diff options
author | Taylor C. Richberger <taywee@gmx.com> | 2017-11-19 13:44:41 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-19 13:44:41 -0700 |
commit | 14202ddf76649027a7f3cf9399d455b97d96a215 (patch) | |
tree | 18dc18d21fe469007b7abe10ace094a8c6aac625 /test.cxx | |
parent | Merge pull request #45 from pavel-belikov/readme (diff) | |
parent | add /bigobj for msvc debug build (diff) | |
download | args.hxx-14202ddf76649027a7f3cf9399d455b97d96a215.tar.xz |
Merge pull request #46 from pavel-belikov/additional-flag-description
Add default values and choices to help output
Diffstat (limited to 'test.cxx')
-rw-r--r-- | test.cxx | 62 |
1 files changed, 62 insertions, 0 deletions
@@ -1088,6 +1088,68 @@ TEST_CASE("ActionFlag works as expected", "[args]") REQUIRE_THROWS_AS(p.ParseArgs(std::vector<std::string>{"-v"}), std::runtime_error); } +TEST_CASE("Default values work as expected", "[args]") +{ + args::ArgumentParser p("parser"); + args::ValueFlag<std::string> f(p, "name", "description", {'f', "foo"}, "abc"); + args::MapFlag<std::string, int> b(p, "name", "description", {'b', "bar"}, {{"a", 1}, {"b", 2}, {"c", 3}}); + p.Prog("prog"); + REQUIRE(p.Help() == R"( prog {OPTIONS} + + parser + + OPTIONS: + + -f[name], --foo=[name] description + -b[name], --bar=[name] description + +)"); + + p.helpParams.addDefault = true; + p.helpParams.addChoices = true; + + REQUIRE(p.Help() == R"( prog {OPTIONS} + + parser + + OPTIONS: + + -f[name], --foo=[name] description + Default: abc + -b[name], --bar=[name] description + One of: a, b, c + +)"); + + f.HelpDefault("123"); + b.HelpChoices("1, 2, 3"); + REQUIRE(p.Help() == R"( prog {OPTIONS} + + parser + + OPTIONS: + + -f[name], --foo=[name] description + Default: 123 + -b[name], --bar=[name] description + One of: 1, 2, 3 + +)"); + + f.HelpDefault({}); + b.HelpChoices({}); + REQUIRE(p.Help() == R"( prog {OPTIONS} + + parser + + OPTIONS: + + -f[name], --foo=[name] description + -b[name], --bar=[name] description + +)"); +} + #undef ARGS_HXX #define ARGS_TESTNAMESPACE #define ARGS_NOEXCEPT |