Commit e792760ab91b30028f49df4edd72687d4f0e684c
1 parent
76717cb3
Changes default values so that they aren't counted
Fixes #96. Default values of options not specified on the command line had a `count` of 1. It would be better if they had a count of 0 because they were not actually specified, so that count is only for options given by the user.
Showing
2 changed files
with
4 additions
and
5 deletions
include/cxxopts.hpp
test/options.cpp
| ... | ... | @@ -243,7 +243,7 @@ TEST_CASE("Default values", "[default]") |
| 243 | 243 | auto argc = av.argc(); |
| 244 | 244 | |
| 245 | 245 | auto result = options.parse(argc, argv); |
| 246 | - CHECK(result.count("default") == 1); | |
| 246 | + CHECK(result.count("default") == 0); | |
| 247 | 247 | CHECK(result["default"].as<int>() == 42); |
| 248 | 248 | } |
| 249 | 249 | |
| ... | ... | @@ -441,9 +441,9 @@ TEST_CASE("Booleans", "[boolean]") { |
| 441 | 441 | REQUIRE(result.count("bool") == 1); |
| 442 | 442 | REQUIRE(result.count("debug") == 1); |
| 443 | 443 | REQUIRE(result.count("timing") == 1); |
| 444 | - REQUIRE(result.count("noExplicitDefault") == 1); | |
| 445 | - REQUIRE(result.count("defaultTrue") == 1); | |
| 446 | - REQUIRE(result.count("defaultFalse") == 1); | |
| 444 | + REQUIRE(result.count("noExplicitDefault") == 0); | |
| 445 | + REQUIRE(result.count("defaultTrue") == 0); | |
| 446 | + REQUIRE(result.count("defaultFalse") == 0); | |
| 447 | 447 | |
| 448 | 448 | CHECK(result["bool"].as<bool>() == false); |
| 449 | 449 | CHECK(result["debug"].as<bool>() == true); | ... | ... |