Commit 288c790f545104c2c940340819dc6b4c0298006c
1 parent
5bcfb24a
Handling negitive numbers
Showing
2 changed files
with
24 additions
and
7 deletions
include/CLI.hpp
| ... | ... | @@ -178,8 +178,8 @@ struct EmptyError : public Error { |
| 178 | 178 | EmptyError(std::string name) : Error("EmptyError", name, 9) {} |
| 179 | 179 | }; |
| 180 | 180 | |
| 181 | -const std::regex reg_split{R"regex((?:([a-zA-Z0-9]?)(?:,|$)|^)([a-zA-Z0-9][a-zA-Z0-9_\-]*)?)regex"}; | |
| 182 | -const std::regex reg_short{R"regex(-([^-])(.*))regex"}; | |
| 181 | +const std::regex reg_split{R"regex((?:([a-zA-Z_]?)(?:,|$)|^)([a-zA-Z0-9_][a-zA-Z0-9_\-]*)?)regex"}; | |
| 182 | +const std::regex reg_short{R"regex(-([a-zA-Z_])(.*))regex"}; | |
| 183 | 183 | const std::regex reg_long{R"regex(--([^-^=][^=]*)=?(.*))regex"}; |
| 184 | 184 | |
| 185 | 185 | ... | ... |
tests/CLITest.cpp
| ... | ... | @@ -433,13 +433,30 @@ TEST_F(TAppValue, Vector) { |
| 433 | 433 | EXPECT_EQ(3, app.count("first")); |
| 434 | 434 | EXPECT_EQ(2, app.count("second")); |
| 435 | 435 | |
| 436 | - EXPECT_EQ(*value, std::vector<int>({12,3,9})); | |
| 437 | - EXPECT_EQ(*value2, std::vector<std::string>({"thing", "try"})); | |
| 436 | + EXPECT_EQ(std::vector<int>({12,3,9}), *value); | |
| 437 | + EXPECT_EQ(std::vector<std::string>({"thing", "try"}), *value2); | |
| 438 | 438 | |
| 439 | 439 | } |
| 440 | 440 | |
| 441 | +TEST_F(TAppValue, DoubleVector) { | |
| 442 | + auto value = app.make_option<std::vector<double>>("simple", "", CLI::ARGS); | |
| 443 | + std::vector<double> d; | |
| 444 | + | |
| 445 | + args = {"--simple", "1.2", "3.4", "-1"}; | |
| 446 | + | |
| 447 | + EXPECT_THROW(d = *value, CLI::EmptyError); | |
| 448 | + | |
| 449 | + EXPECT_NO_THROW(run()); | |
| 450 | + | |
| 451 | + EXPECT_NO_THROW(d = *value); | |
| 452 | + | |
| 453 | + EXPECT_EQ(3, app.count("simple")); | |
| 454 | + EXPECT_EQ(std::vector<double>({1.2, 3.4, -1}), *value); | |
| 455 | +} | |
| 456 | + | |
| 441 | 457 | // TODO: Maybe add function to call on subcommand parse? Stashed. |
| 442 | -// TODO: Check help output | |
| 458 | +// TODO: Check help output, better formatting | |
| 443 | 459 | // TODO: Add default/type info to help |
| 444 | -// TODO: Add set checking | |
| 445 | -// TODO: Try all of the options together | |
| 460 | +// TODO: Add regex replacement function (GCC 4.8 support) | |
| 461 | +// TODO: Add README | |
| 462 | +// TODO: Change format of option specifications? | ... | ... |