From f68b7e186cd2a020cbddfe3194c1d8ddfeeb1013 Mon Sep 17 00:00:00 2001 From: "Taylor C. Richberger" Date: Fri, 11 Jan 2019 11:35:07 -0700 Subject: Fix default list processing 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. --- test.cxx | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'test.cxx') 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{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 foo(parser, "FOO", "test flag", {'f', "foo"}, {9, 7, 5}); + parser.ParseArgs(std::vector()); + REQUIRE((args::get(foo) == std::vector{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 foo(parser, "FOO", "test flag", {'f', "foo"}, {9, 7, 5}); + parser.ParseArgs(std::vector{"--foo=7", "-f2", "-f", "9", "--foo", "42"}); + REQUIRE((args::get(foo) == std::vector{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 foo(parser, "FOO", "test flag"); + parser.ParseArgs(std::vector{"7", "2", "9", "42"}); + REQUIRE((args::get(foo) == std::vector{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 foo(parser, "FOO", "test flag", {9, 7, 5}); + parser.ParseArgs(std::vector()); + REQUIRE((args::get(foo) == std::vector{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 foo(parser, "FOO", "test flag", {9, 7, 5}); + parser.ParseArgs(std::vector{"7", "2", "9", "42"}); + REQUIRE((args::get(foo) == std::vector{7, 2, 9, 42})); +} + #include TEST_CASE("Argument flag lists work with sets", "[args]") -- cgit v1.2.1