aboutsummaryrefslogtreecommitdiff
path: root/test.cxx
diff options
context:
space:
mode:
authorPavel Belikov <pavel.fuchs.belikov@gmail.com>2017-11-18 15:27:23 +0300
committerPavel Belikov <pavel.fuchs.belikov@gmail.com>2017-11-19 21:10:30 +0300
commit4b02649e9fee72a66f17a1b96e90ef4f4e053aeb (patch)
tree90b8fb405f29b7773e9fdf15802d0472feefc902 /test.cxx
parentadd more HelpParams for different strings used in usage/options sections (diff)
downloadargs.hxx-4b02649e9fee72a66f17a1b96e90ef4f4e053aeb.tar.xz
add choices and default strings to argument description
Diffstat (limited to 'test.cxx')
-rw-r--r--test.cxx62
1 files changed, 62 insertions, 0 deletions
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<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