mirror of
https://github.com/CLIUtils/CLI11.git
synced 2026-01-19 04:52:08 +00:00
prefix_command tests and improvements (#1266)
adding a PrefixCommandMode option to the prefix_command to allow specification of a separator and catch other errors Addresses #1264 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -2427,6 +2427,57 @@ TEST_CASE_METHOD(TApp, "AllowExtrasCascade", "[app]") {
|
||||
CHECK(45 == v1);
|
||||
CHECK(27 == v2);
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(TApp, "PrefixCommand", "[app]") {
|
||||
int v1{0};
|
||||
int v2{0};
|
||||
app.add_option("-f", v1);
|
||||
app.add_option("-x", v2);
|
||||
app.prefix_command();
|
||||
args = {"-x", "45", "-f", "27"};
|
||||
run();
|
||||
auto rem = app.remaining();
|
||||
CHECK(rem.empty());
|
||||
|
||||
args = {"-x", "45", "-f", "27", "--test", "23"};
|
||||
|
||||
run();
|
||||
rem = app.remaining();
|
||||
CHECK(rem.size() == 2U);
|
||||
|
||||
args = {"-x", "45", "-f", "27", "--", "--test", "23"};
|
||||
|
||||
run();
|
||||
rem = app.remaining();
|
||||
CHECK(rem.size() == 3U);
|
||||
|
||||
args = {"-x", "45", "--test4", "-f", "27", "--test", "23"};
|
||||
|
||||
run();
|
||||
rem = app.remaining();
|
||||
CHECK(rem.size() == 5U);
|
||||
|
||||
app.prefix_command(CLI::PrefixCommandMode::SeparatorOnly);
|
||||
CHECK_THROWS_AS(run(), CLI::ExtrasError);
|
||||
|
||||
args = {"-x", "45", "positional", "-f", "27", "--test", "23"};
|
||||
CHECK_THROWS_AS(run(), CLI::ExtrasError);
|
||||
|
||||
args = {"-x", "45", "-f", "27", "--", "--test", "23"};
|
||||
|
||||
run();
|
||||
rem = app.remaining();
|
||||
CHECK(rem.size() == 3U);
|
||||
|
||||
args = {"-x", "45", "--test4", "-f", "27", "--", "--test", "23"};
|
||||
|
||||
CHECK_THROWS_AS(run(), CLI::ExtrasError);
|
||||
app.allow_extras(true);
|
||||
run();
|
||||
rem = app.remaining();
|
||||
CHECK(rem.size() == 4U);
|
||||
}
|
||||
|
||||
// makes sure the error throws on the rValue version of the parse
|
||||
TEST_CASE_METHOD(TApp, "ExtrasErrorRvalueParse", "[app]") {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user