From 9bc4c477e39725d6031a601f5341363bcbf54646 Mon Sep 17 00:00:00 2001 From: "Taylor C. Richberger" Date: Sat, 16 Jul 2016 03:44:22 -0600 Subject: fix many bugs, add tests for terminator --- test.cxx | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'test.cxx') diff --git a/test.cxx b/test.cxx index 8d77bf4..ad3bfd8 100644 --- a/test.cxx +++ b/test.cxx @@ -162,6 +162,47 @@ TEST_CASE("Positional arguments and positional argument lists work as expected", REQUIRE((args::get(baz) == std::vector{'a', 'b', 'c', 'x', 'y', 'z'})); } +TEST_CASE("The option terminator works as expected", "[args]") +{ + args::ArgumentParser parser("This is a test program.", "This goes after the options."); + args::Positional foo(parser, "FOO", "test flag"); + args::Positional bar(parser, "BAR", "test flag"); + args::PositionalList baz(parser, "BAZ", "test flag"); + args::Flag ofoo(parser, "FOO", "test flag", {'f', "foo"}); + args::Flag obar(parser, "BAR", "test flag", {"bar", 'b'}); + args::ValueFlag obaz(parser, "BAZ", "test flag", {'a', "baz"}); + parser.ParseArgs(std::vector{"--foo", "this is a test flag", "0", "a", "b", "--baz", "7.0", "c", "x", "y", "z"}); + REQUIRE(foo); + REQUIRE((args::get(foo) == "this is a test flag")); + REQUIRE(bar); + REQUIRE(!args::get(bar)); + REQUIRE(baz); + REQUIRE((args::get(baz) == std::vector{"a", "b", "c", "x", "y", "z"})); + REQUIRE(ofoo); + REQUIRE(!obar); + REQUIRE(obaz); + parser.ParseArgs(std::vector{"--foo", "this is a test flag", "0", "a", "--", "b", "--baz", "7.0", "c", "x", "y", "z"}); + REQUIRE(foo); + REQUIRE((args::get(foo) == "this is a test flag")); + REQUIRE(bar); + REQUIRE(!args::get(bar)); + REQUIRE(baz); + REQUIRE((args::get(baz) == std::vector{"a", "b", "--baz", "7.0", "c", "x", "y", "z"})); + REQUIRE(ofoo); + REQUIRE(!obar); + REQUIRE(!obaz); + parser.ParseArgs(std::vector{"--foo", "--", "this is a test flag", "0", "a", "b", "--baz", "7.0", "c", "x", "y", "z"}); + REQUIRE(foo); + REQUIRE((args::get(foo) == "this is a test flag")); + REQUIRE(bar); + REQUIRE(!args::get(bar)); + REQUIRE(baz); + REQUIRE((args::get(baz) == std::vector{"a", "b", "--baz", "7.0", "c", "x", "y", "z"})); + REQUIRE(ofoo); + REQUIRE(!obar); + REQUIRE(!obaz); +} + TEST_CASE("Positional lists work with sets", "[args]") { args::ArgumentParser parser("This is a test program.", "This goes after the options."); -- cgit v1.2.1