mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-03 22:54:39 +00:00
.present returns std::nullopt if the optional argument is not given by the user -- as long as a .default_value is not defined. With a .default_value, .present cannot be used to determine if a value is user-provided or the default. .is_used fills that role and only returns true if the argument was passed by the user. Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
23 lines
717 B
C++
23 lines
717 B
C++
#include <doctest.hpp>
|
|
#include <argparse/argparse.hpp>
|
|
|
|
using doctest::test_suite;
|
|
|
|
TEST_CASE("User-supplied argument" * test_suite("is_used")) {
|
|
argparse::ArgumentParser program("test");
|
|
program.add_argument("--dir")
|
|
.default_value(std::string("/"));
|
|
program.parse_args({ "test", "--dir", "/home/user" });
|
|
REQUIRE(program.get("--dir") == "/home/user");
|
|
REQUIRE(program.is_used("--dir") == true);
|
|
}
|
|
|
|
TEST_CASE("Not user-supplied argument" * test_suite("is_used")) {
|
|
argparse::ArgumentParser program("test");
|
|
program.add_argument("--dir")
|
|
.default_value(std::string("/"));
|
|
program.parse_args({ "test" });
|
|
REQUIRE(program.get("--dir") == "/");
|
|
REQUIRE(program.is_used("--dir") == false);
|
|
}
|