mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-03 22:54:39 +00:00
Added nargs test for multiple values to a choices() argument
This commit is contained in:
parent
f5287e2f20
commit
d8aa2ba1db
@ -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")) {
|
||||
|
Loading…
Reference in New Issue
Block a user