Skip to content

Commit

Permalink
Added nargs test for multiple values to a choices() argument
Browse files Browse the repository at this point in the history
  • Loading branch information
p-ranav committed Nov 13, 2023
1 parent f5287e2 commit d8aa2ba
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/test_choices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand All @@ -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")) {
Expand Down

0 comments on commit d8aa2ba

Please sign in to comment.