From d8aa2ba1db9320e05d0542bf8c6259d2f11fc7c7 Mon Sep 17 00:00:00 2001 From: Pranav Srinivas Kumar Date: Mon, 13 Nov 2023 14:19:55 -0800 Subject: [PATCH] Added nargs test for multiple values to a choices() argument --- test/test_choices.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/test_choices.cpp b/test/test_choices.cpp index 206ec89d..4fc4383a 100644 --- a/test/test_choices.cpp +++ b/test/test_choices.cpp @@ -38,6 +38,24 @@ TEST_CASE("Parse argument that is in the fixed number of allowed choices, with " REQUIRE(program.get("--value") == 1); } +TEST_CASE( + "Parse nargs argument that is in the fixed number of allowed choices, with " + "other positional argument" * + test_suite("choices")) { + argparse::ArgumentParser program("test"); + program.add_argument("--input") + .default_value(std::string{"baz"}) + .choices("foo", "bar", "baz") + .nargs(2); + program.add_argument("--value").scan<'i', int>().default_value(0); + + REQUIRE_NOTHROW( + program.parse_args({"test", "--input", "foo", "bar", "--value", "1"})); + REQUIRE((program.get>("--input") == + std::vector{"foo", "bar"})); + REQUIRE(program.get("--value") == 1); +} + TEST_CASE("Parse argument that is in the fixed number of allowed choices, with " "other positional argument (reversed)" * test_suite("choices")) { @@ -53,6 +71,24 @@ TEST_CASE("Parse argument that is in the fixed number of allowed choices, with " REQUIRE(program.get("--value") == 1); } +TEST_CASE( + "Parse nargs argument that is in the fixed number of allowed choices, with " + "other positional argument (reversed)" * + test_suite("choices")) { + argparse::ArgumentParser program("test"); + program.add_argument("--input") + .default_value(std::string{"baz"}) + .choices("foo", "bar", "baz") + .nargs(2); + program.add_argument("--value").scan<'i', int>().default_value(0); + + REQUIRE_NOTHROW( + program.parse_args({"test", "--value", "1", "--input", "foo", "bar"})); + REQUIRE((program.get>("--input") == + std::vector{"foo", "bar"})); + REQUIRE(program.get("--value") == 1); +} + TEST_CASE("Parse argument that is in the fixed number of allowed choices, with " "invalid default" * test_suite("choices")) {