parent
17b2c91049
commit
5f258387a7
@ -754,7 +754,7 @@ std::basic_regex<char> falsy_pattern
|
|||||||
("(f|F)(alse)?|0");
|
("(f|F)(alse)?|0");
|
||||||
|
|
||||||
std::basic_regex<char> option_matcher
|
std::basic_regex<char> option_matcher
|
||||||
("--([[:alnum:]][-_[:alnum:]]+)(=(.*))?|-([[:alnum:]]+)");
|
("--([[:alnum:]][-_[:alnum:]]+)(=(.*))?|-([[:alnum:]].*)");
|
||||||
std::basic_regex<char> option_specifier
|
std::basic_regex<char> option_specifier
|
||||||
("([[:alnum:]][-_[:alnum:]]*)(,[ ]*[[:alnum:]][-_[:alnum:]]*)*");
|
("([[:alnum:]][-_[:alnum:]]*)(,[ ]*[[:alnum:]][-_[:alnum:]]*)*");
|
||||||
std::basic_regex<char> option_specifier_separator(", *");
|
std::basic_regex<char> option_specifier_separator(", *");
|
||||||
|
|||||||
@ -118,9 +118,11 @@ TEST_CASE("Short options", "[options]")
|
|||||||
cxxopts::Options options("test_short", " - test short options");
|
cxxopts::Options options("test_short", " - test short options");
|
||||||
|
|
||||||
options.add_options()
|
options.add_options()
|
||||||
("a", "a short option", cxxopts::value<std::string>());
|
("a", "a short option", cxxopts::value<std::string>())
|
||||||
|
("b", "b option")
|
||||||
|
("c", "c option", cxxopts::value<std::string>());
|
||||||
|
|
||||||
Argv argv({"test_short", "-a", "value"});
|
Argv argv({"test_short", "-a", "value", "-bcfoo=something"});
|
||||||
|
|
||||||
auto actual_argv = argv.argv();
|
auto actual_argv = argv.argv();
|
||||||
auto argc = argv.argc();
|
auto argc = argv.argc();
|
||||||
@ -131,10 +133,15 @@ TEST_CASE("Short options", "[options]")
|
|||||||
CHECK(result["a"].as<std::string>() == "value");
|
CHECK(result["a"].as<std::string>() == "value");
|
||||||
|
|
||||||
auto& arguments = result.arguments();
|
auto& arguments = result.arguments();
|
||||||
REQUIRE(arguments.size() == 1);
|
REQUIRE(arguments.size() == 3);
|
||||||
CHECK(arguments[0].key() == "a");
|
CHECK(arguments[0].key() == "a");
|
||||||
CHECK(arguments[0].value() == "value");
|
CHECK(arguments[0].value() == "value");
|
||||||
|
|
||||||
|
CHECK(result.count("b") == 1);
|
||||||
|
CHECK(result.count("c") == 1);
|
||||||
|
|
||||||
|
CHECK(result["c"].as<std::string>() == "foo=something");
|
||||||
|
|
||||||
REQUIRE_THROWS_AS(options.add_options()("", "nothing option"),
|
REQUIRE_THROWS_AS(options.add_options()("", "nothing option"),
|
||||||
cxxopts::exceptions::invalid_option_format&);
|
cxxopts::exceptions::invalid_option_format&);
|
||||||
}
|
}
|
||||||
@ -703,8 +710,8 @@ TEST_CASE("Allow bad short syntax", "[options]") {
|
|||||||
("s,short", "a short option");
|
("s,short", "a short option");
|
||||||
|
|
||||||
Argv av({
|
Argv av({
|
||||||
"unknown_options",
|
"--ab?",
|
||||||
"-some_bad_short",
|
"-?b?#@"
|
||||||
});
|
});
|
||||||
|
|
||||||
auto** argv = av.argv();
|
auto** argv = av.argv();
|
||||||
@ -718,7 +725,7 @@ TEST_CASE("Allow bad short syntax", "[options]") {
|
|||||||
options.allow_unrecognised_options();
|
options.allow_unrecognised_options();
|
||||||
CHECK_NOTHROW(options.parse(argc, argv));
|
CHECK_NOTHROW(options.parse(argc, argv));
|
||||||
REQUIRE(argc == 2);
|
REQUIRE(argc == 2);
|
||||||
CHECK_THAT(argv[1], Catch::Equals("-some_bad_short"));
|
CHECK_THAT(argv[1], Catch::Equals("-?b?#@"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user