From bbb2ea53147b4065722ba7e861c2292b41bdd2d3 Mon Sep 17 00:00:00 2001 From: Pranav Srinivas Kumar Date: Sat, 4 Nov 2023 09:51:25 -0500 Subject: [PATCH] Added unit test for #239 --- test/test_optional_arguments.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/test_optional_arguments.cpp b/test/test_optional_arguments.cpp index 74a4c25a..39ad7a3e 100644 --- a/test/test_optional_arguments.cpp +++ b/test/test_optional_arguments.cpp @@ -202,3 +202,30 @@ TEST_CASE("Parse arguments of different types" * REQUIRE(program["-string-view"] == true); REQUIRE(program["-builtin"s] == true); } + +TEST_CASE("Parse quoted negative numbers as values to optional arguments" * + test_suite("optional_arguments")) { + using namespace std::literals; + + argparse::ArgumentParser program("test"); + + program.add_argument( "--user-origin") + .default_value( std::string() ) + .help( "User-specified output origin ex. 1x1in, 1x1inch, 25.4x25.4mm (default mm)" ); + + SUBCASE("Double quotes, positive number") { + REQUIRE_NOTHROW(program.parse_args({"test", "--user-origin=\"56.100000x27.000000mm\""})); + } + + SUBCASE("Single quotes, positive number") { + REQUIRE_NOTHROW(program.parse_args({"test", "--user-origin='56.100000x27.000000mm'"})); + } + + SUBCASE("Double quotes, negative number") { + REQUIRE_NOTHROW(program.parse_args({"test", "--user-origin=\"-56.100000x27.000000mm\""})); + } + + SUBCASE("Single quotes, negative number") { + REQUIRE_NOTHROW(program.parse_args({"test", "--user-origin='-56.100000x27.000000mm'"})); + } +} \ No newline at end of file