Added nargs test for multiple values to a choices() argument

This commit is contained in:
Pranav Srinivas Kumar 2023-11-13 14:19:55 -08:00
parent f5287e2f20
commit d8aa2ba1db

View File

@ -38,6 +38,24 @@ TEST_CASE("Parse argument that is in the fixed number of allowed choices, with "
REQUIRE(program.get<int>("--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<std::vector<std::string>>("--input") ==
std::vector<std::string>{"foo", "bar"}));
REQUIRE(program.get<int>("--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<int>("--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<std::vector<std::string>>("--input") ==
std::vector<std::string>{"foo", "bar"}));
REQUIRE(program.get<int>("--value") == 1);
}
TEST_CASE("Parse argument that is in the fixed number of allowed choices, with "
"invalid default" *
test_suite("choices")) {