From 288c790f545104c2c940340819dc6b4c0298006c Mon Sep 17 00:00:00 2001 From: Henry Fredrick Schreiner Date: Tue, 31 Jan 2017 11:55:51 -0500 Subject: [PATCH] Handling negitive numbers --- include/CLI.hpp | 4 ++-- tests/CLITest.cpp | 27 ++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/include/CLI.hpp b/include/CLI.hpp index 3344246..21ec9ac 100644 --- a/include/CLI.hpp +++ b/include/CLI.hpp @@ -178,8 +178,8 @@ struct EmptyError : public Error { EmptyError(std::string name) : Error("EmptyError", name, 9) {} }; -const std::regex reg_split{R"regex((?:([a-zA-Z0-9]?)(?:,|$)|^)([a-zA-Z0-9][a-zA-Z0-9_\-]*)?)regex"}; -const std::regex reg_short{R"regex(-([^-])(.*))regex"}; +const std::regex reg_split{R"regex((?:([a-zA-Z_]?)(?:,|$)|^)([a-zA-Z0-9_][a-zA-Z0-9_\-]*)?)regex"}; +const std::regex reg_short{R"regex(-([a-zA-Z_])(.*))regex"}; const std::regex reg_long{R"regex(--([^-^=][^=]*)=?(.*))regex"}; diff --git a/tests/CLITest.cpp b/tests/CLITest.cpp index 4af13f1..ec2396a 100644 --- a/tests/CLITest.cpp +++ b/tests/CLITest.cpp @@ -433,13 +433,30 @@ TEST_F(TAppValue, Vector) { EXPECT_EQ(3, app.count("first")); EXPECT_EQ(2, app.count("second")); - EXPECT_EQ(*value, std::vector({12,3,9})); - EXPECT_EQ(*value2, std::vector({"thing", "try"})); + EXPECT_EQ(std::vector({12,3,9}), *value); + EXPECT_EQ(std::vector({"thing", "try"}), *value2); } +TEST_F(TAppValue, DoubleVector) { + auto value = app.make_option>("simple", "", CLI::ARGS); + std::vector d; + + args = {"--simple", "1.2", "3.4", "-1"}; + + EXPECT_THROW(d = *value, CLI::EmptyError); + + EXPECT_NO_THROW(run()); + + EXPECT_NO_THROW(d = *value); + + EXPECT_EQ(3, app.count("simple")); + EXPECT_EQ(std::vector({1.2, 3.4, -1}), *value); +} + // TODO: Maybe add function to call on subcommand parse? Stashed. -// TODO: Check help output +// TODO: Check help output, better formatting // TODO: Add default/type info to help -// TODO: Add set checking -// TODO: Try all of the options together +// TODO: Add regex replacement function (GCC 4.8 support) +// TODO: Add README +// TODO: Change format of option specifications? -- libgit2 0.21.4