diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c981f89..b1e00be 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -28,6 +28,7 @@ file(GLOB ARGPARSE_TEST_SOURCES test_append.cpp test_compound_arguments.cpp test_container_arguments.cpp + test_const_correct.cpp test_help.cpp test_invalid_arguments.cpp test_is_used.cpp diff --git a/test/test_const_correct.cpp b/test/test_const_correct.cpp new file mode 100644 index 0000000..1acfdd4 --- /dev/null +++ b/test/test_const_correct.cpp @@ -0,0 +1,27 @@ +#include +#include + +using doctest::test_suite; + +TEST_CASE("ArgumentParser is const-correct after construction and parsing" * + test_suite("value_semantics")) { + GIVEN("a parser") { + argparse::ArgumentParser parser("test"); + parser.add_argument("--foo", "-f").help("I am foo"); + parser.add_description("A description"); + parser.add_epilog("An epilog"); + + WHEN("becomes const-qualified") { + parser.parse_args({"./main", "--foo", "baz"}); + const auto const_parser = std::move(parser); + + THEN("only const methods are accessible") { + REQUIRE(const_parser.help().str().size() > 0); + REQUIRE(const_parser.present("--foo")); + REQUIRE(const_parser.is_used("-f")); + REQUIRE(const_parser.get("-f") == "baz"); + REQUIRE(const_parser["-f"] == std::string("baz")); + } + } + } +} diff --git a/test/test_value_semantics.cpp b/test/test_value_semantics.cpp index 72958cc..2cc0f88 100644 --- a/test/test_value_semantics.cpp +++ b/test/test_value_semantics.cpp @@ -93,27 +93,4 @@ TEST_CASE("ArgumentParser is CopyConstructible and CopyAssignable" * } } } - - TEST_CASE("ArgumentParser is const-correct after construction and parsing" * - test_suite("value_semantics")) { - GIVEN("a parser") { - argparse::ArgumentParser parser("test"); - parser.add_argument("--foo", "-f").help("I am foo"); - parser.add_description("A description"); - parser.add_epilog("An epilog"); - - WHEN("becomes const-qualified") { - parser.parse_args({"./main", "--foo", "baz"}); - const auto const_parser = std::move(parser); - - THEN("only const methods are accessible") { - REQUIRE(const_parser.help().str().size() > 0); - REQUIRE(const_parser.present("--foo")); - REQUIRE(const_parser.is_used("-f")); - REQUIRE(const_parser.get("-f") == "baz"); - REQUIRE(const_parser["-f"] == std::string("baz")); - } - } - } - } }