From 4b02649e9fee72a66f17a1b96e90ef4f4e053aeb Mon Sep 17 00:00:00 2001 From: Pavel Belikov Date: Sat, 18 Nov 2017 15:27:23 +0300 Subject: add choices and default strings to argument description --- test.cxx | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'test.cxx') diff --git a/test.cxx b/test.cxx index 44cde49..a8d1676 100644 --- a/test.cxx +++ b/test.cxx @@ -1088,6 +1088,68 @@ TEST_CASE("ActionFlag works as expected", "[args]") REQUIRE_THROWS_AS(p.ParseArgs(std::vector{"-v"}), std::runtime_error); } +TEST_CASE("Default values work as expected", "[args]") +{ + args::ArgumentParser p("parser"); + args::ValueFlag f(p, "name", "description", {'f', "foo"}, "abc"); + args::MapFlag 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 -- cgit v1.2.1