forked from p-ranav/argparse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
p-ranav#277 Added in-built support for string_type choices
- Loading branch information
Showing
13 changed files
with
204 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#ifdef WITH_MODULE | ||
import argparse; | ||
#else | ||
#include <argparse/argparse.hpp> | ||
#endif | ||
|
||
#include <doctest.hpp> | ||
|
||
using doctest::test_suite; | ||
|
||
TEST_CASE("Parse argument that is provided zero choices" * | ||
test_suite("choices")) { | ||
argparse::ArgumentParser program("test"); | ||
REQUIRE_THROWS_WITH_AS(program.add_argument("color").choices(), | ||
"Zero choices provided", std::runtime_error); | ||
} | ||
|
||
TEST_CASE("Parse argument that is in the fixed number of allowed choices" * | ||
test_suite("choices")) { | ||
argparse::ArgumentParser program("test"); | ||
program.add_argument("color").choices("red", "green", "blue"); | ||
|
||
program.parse_args({"test", "red"}); | ||
} | ||
|
||
TEST_CASE("Parse argument that is in the fixed number of allowed choices, with " | ||
"invalid default" * | ||
test_suite("choices")) { | ||
argparse::ArgumentParser program("test"); | ||
program.add_argument("color").default_value("yellow").choices("red", "green", | ||
"blue"); | ||
|
||
REQUIRE_THROWS_WITH_AS( | ||
program.parse_args({"test"}), | ||
"Invalid default value \"yellow\" - allowed options: {red, green, blue}", | ||
std::runtime_error); | ||
} | ||
|
||
TEST_CASE("Parse invalid argument that is not in the fixed number of allowed " | ||
"choices" * | ||
test_suite("choices")) { | ||
argparse::ArgumentParser program("test"); | ||
program.add_argument("color").choices("red", "green", "blue"); | ||
|
||
REQUIRE_THROWS_WITH_AS( | ||
program.parse_args({"test", "red2"}), | ||
"Invalid argument \"red2\" - allowed options: {red, green, blue}", | ||
std::runtime_error); | ||
} | ||
|
||
TEST_CASE( | ||
"Parse multiple arguments that are in the fixed number of allowed choices" * | ||
test_suite("choices")) { | ||
argparse::ArgumentParser program("test"); | ||
program.add_argument("color").nargs(2).choices("red", "green", "blue"); | ||
|
||
program.parse_args({"test", "red", "green"}); | ||
} | ||
|
||
TEST_CASE("Parse multiple arguments one of which is not in the fixed number of " | ||
"allowed choices" * | ||
test_suite("choices")) { | ||
argparse::ArgumentParser program("test"); | ||
program.add_argument("color").nargs(2).choices("red", "green", "blue"); | ||
|
||
REQUIRE_THROWS_WITH_AS( | ||
program.parse_args({"test", "red", "green2"}), | ||
"Invalid argument \"green2\" - allowed options: {red, green, blue}", | ||
std::runtime_error); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.