mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-04 07:04:39 +00:00
These test the API shown in README.md, rather than the Argument::get function that does most of the work. Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
30 lines
1.0 KiB
C++
30 lines
1.0 KiB
C++
#include <doctest.hpp>
|
|
#include <argparse/argparse.hpp>
|
|
|
|
using doctest::test_suite;
|
|
|
|
TEST_CASE("Getting a simple argument" * test_suite("ArgumentParser::get")) {
|
|
argparse::ArgumentParser program("test");
|
|
program.add_argument("-s", "--stuff");
|
|
REQUIRE_NOTHROW(program.parse_args({ "test", "-s", "./src" }));
|
|
REQUIRE(program.get("--stuff") == "./src");
|
|
}
|
|
|
|
TEST_CASE("Missing argument" * test_suite("ArgumentParser::get")) {
|
|
argparse::ArgumentParser program("test");
|
|
program.add_argument("-s", "--stuff");
|
|
REQUIRE_NOTHROW(program.parse_args({ "test" }));
|
|
REQUIRE_THROWS_WITH_AS(program.get("--stuff"),
|
|
"No value provided",
|
|
std::logic_error);
|
|
}
|
|
|
|
TEST_CASE("Implicit argument" * test_suite("ArgumentParser::get")) {
|
|
argparse::ArgumentParser program("test");
|
|
program.add_argument("-s", "--stuff").nargs(1);
|
|
REQUIRE_NOTHROW(program.parse_args({ "test" }));
|
|
REQUIRE_THROWS_WITH_AS(program.get("--stuff"),
|
|
"No value provided",
|
|
std::logic_error);
|
|
}
|