aboutsummaryrefslogtreecommitdiff
path: root/test.cxx
diff options
context:
space:
mode:
authorTaylor C. Richberger <taywee@gmx.com>2019-01-11 11:35:07 -0700
committerTaylor C. Richberger <taywee@gmx.com>2019-01-11 11:35:07 -0700
commitf68b7e186cd2a020cbddfe3194c1d8ddfeeb1013 (patch)
tree57641aba0a32a1ef43ada31ff81ef36f55401a92 /test.cxx
parentfix default args for extra types (diff)
downloadargs.hxx-f68b7e186cd2a020cbddfe3194c1d8ddfeeb1013.tar.xz
Fix default list processing6.2.2
The previous release had set up default arguments to add to the existing default list. Now making a match will clear the list and replace it.
Diffstat (limited to 'test.cxx')
-rw-r--r--test.cxx40
1 files changed, 40 insertions, 0 deletions
diff --git a/test.cxx b/test.cxx
index 13cd4d0..b46007d 100644
--- a/test.cxx
+++ b/test.cxx
@@ -137,6 +137,46 @@ TEST_CASE("Argument flag lists work as expected", "[args]")
REQUIRE((args::get(foo) == std::vector<int>{7, 2, 9, 42}));
}
+TEST_CASE("Argument flag lists use default values", "[args]")
+{
+ args::ArgumentParser parser("This is a test program.", "This goes after the options.");
+ args::ValueFlagList<int> foo(parser, "FOO", "test flag", {'f', "foo"}, {9, 7, 5});
+ parser.ParseArgs(std::vector<std::string>());
+ REQUIRE((args::get(foo) == std::vector<int>{9, 7, 5}));
+}
+
+TEST_CASE("Argument flag lists replace default values", "[args]")
+{
+ args::ArgumentParser parser("This is a test program.", "This goes after the options.");
+ args::ValueFlagList<int> foo(parser, "FOO", "test flag", {'f', "foo"}, {9, 7, 5});
+ parser.ParseArgs(std::vector<std::string>{"--foo=7", "-f2", "-f", "9", "--foo", "42"});
+ REQUIRE((args::get(foo) == std::vector<int>{7, 2, 9, 42}));
+}
+
+TEST_CASE("Positional lists work as expected", "[args]")
+{
+ args::ArgumentParser parser("This is a test program.", "This goes after the options.");
+ args::PositionalList<int> foo(parser, "FOO", "test flag");
+ parser.ParseArgs(std::vector<std::string>{"7", "2", "9", "42"});
+ REQUIRE((args::get(foo) == std::vector<int>{7, 2, 9, 42}));
+}
+
+TEST_CASE("Positional lists use default values", "[args]")
+{
+ args::ArgumentParser parser("This is a test program.", "This goes after the options.");
+ args::PositionalList<int> foo(parser, "FOO", "test flag", {9, 7, 5});
+ parser.ParseArgs(std::vector<std::string>());
+ REQUIRE((args::get(foo) == std::vector<int>{9, 7, 5}));
+}
+
+TEST_CASE("Positional lists replace default values", "[args]")
+{
+ args::ArgumentParser parser("This is a test program.", "This goes after the options.");
+ args::PositionalList<int> foo(parser, "FOO", "test flag", {9, 7, 5});
+ parser.ParseArgs(std::vector<std::string>{"7", "2", "9", "42"});
+ REQUIRE((args::get(foo) == std::vector<int>{7, 2, 9, 42}));
+}
+
#include <unordered_set>
TEST_CASE("Argument flag lists work with sets", "[args]")