From debaca70bc9ac882a210c4efd3761edf3935f10d Mon Sep 17 00:00:00 2001 From: Pavel Belikov Date: Sat, 23 Dec 2017 11:27:03 +0300 Subject: change GetChoicesString() signature --- test.cxx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'test.cxx') diff --git a/test.cxx b/test.cxx index 01decbe..5be6ff7 100644 --- a/test.cxx +++ b/test.cxx @@ -1203,7 +1203,7 @@ TEST_CASE("Default values work as expected", "[args]") )"); f.HelpDefault("123"); - b.HelpChoices("1, 2, 3"); + b.HelpChoices({"1", "2", "3"}); REQUIRE(p.Help() == R"( prog {OPTIONS} parser @@ -1239,10 +1239,10 @@ TEST_CASE("Choices description works as expected", "[args]") args::MapPositional mappos(p, "mappos", "mappos", {{"1",1}, {"2", 2}}); args::MapPositionalList mapposlist(p, "mapposlist", "mapposlist", {{'1',1}, {'2', 2}}); - REQUIRE(map.HelpChoices(p.helpParams) == "1, 2"); - REQUIRE(maplist.HelpChoices(p.helpParams) == "1, 2"); - REQUIRE(mappos.HelpChoices(p.helpParams) == "1, 2"); - REQUIRE(mapposlist.HelpChoices(p.helpParams) == "1, 2"); + REQUIRE(map.HelpChoices(p.helpParams) == std::vector{"1", "2"}); + REQUIRE(maplist.HelpChoices(p.helpParams) == std::vector{"1", "2"}); + REQUIRE(mappos.HelpChoices(p.helpParams) == std::vector{"1", "2"}); + REQUIRE(mapposlist.HelpChoices(p.helpParams) == std::vector{"1", "2"}); } #undef ARGS_HXX -- cgit v1.2.1 From a8b96a749d28465af2a45ccfe2b46c6fd96018b2 Mon Sep 17 00:00:00 2001 From: Pavel Belikov Date: Sat, 23 Dec 2017 15:55:28 +0300 Subject: add auto completion for flags --- test.cxx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test.cxx') diff --git a/test.cxx b/test.cxx index 5be6ff7..2d3b625 100644 --- a/test.cxx +++ b/test.cxx @@ -1245,6 +1245,20 @@ TEST_CASE("Choices description works as expected", "[args]") REQUIRE(mapposlist.HelpChoices(p.helpParams) == std::vector{"1", "2"}); } +TEST_CASE("Completion works as expected", "[args]") +{ + using namespace Catch::Matchers; + + args::ArgumentParser p("parser"); + args::CompletionFlag c(p, {"completion"}); + args::ValueFlag f(p, "name", "description", {'f', "foo"}, "abc"); + args::ValueFlag b(p, "name", "description", {'b', "bar"}, "abc"); + + REQUIRE_THROWS_WITH(p.ParseArgs(std::vector{"--completion", "bash", "1", "test", "-"}), Equals("-f\n-b")); + REQUIRE_THROWS_WITH(p.ParseArgs(std::vector{"--completion", "bash", "1", "test", "-f"}), Equals("-f")); + REQUIRE_THROWS_WITH(p.ParseArgs(std::vector{"--completion", "bash", "1", "test", "--"}), Equals("--foo\n--bar")); +} + #undef ARGS_HXX #define ARGS_TESTNAMESPACE #define ARGS_NOEXCEPT -- cgit v1.2.1 From f0ae519bdf43a67cfb6b238e28bdcc75917d94de Mon Sep 17 00:00:00 2001 From: Pavel Belikov Date: Sat, 23 Dec 2017 16:30:37 +0300 Subject: add completion for flag values --- test.cxx | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test.cxx') diff --git a/test.cxx b/test.cxx index 2d3b625..4768cde 100644 --- a/test.cxx +++ b/test.cxx @@ -1257,6 +1257,11 @@ TEST_CASE("Completion works as expected", "[args]") REQUIRE_THROWS_WITH(p.ParseArgs(std::vector{"--completion", "bash", "1", "test", "-"}), Equals("-f\n-b")); REQUIRE_THROWS_WITH(p.ParseArgs(std::vector{"--completion", "bash", "1", "test", "-f"}), Equals("-f")); REQUIRE_THROWS_WITH(p.ParseArgs(std::vector{"--completion", "bash", "1", "test", "--"}), Equals("--foo\n--bar")); + + args::MapFlag m(p, "mappos", "mappos", {'m', "map"}, {{"1",1}, {"2", 2}}); + REQUIRE_THROWS_WITH(p.ParseArgs(std::vector{"--completion", "bash", "2", "test", "-m", ""}), Equals("1\n2")); + REQUIRE_THROWS_WITH(p.ParseArgs(std::vector{"--completion", "bash", "1", "test", "--map="}), Equals("--map=1\n--map=2")); + REQUIRE_THROWS_WITH(p.ParseArgs(std::vector{"--completion", "bash", "1", "test", "-m1"}), Equals("-m1")); } #undef ARGS_HXX -- cgit v1.2.1 From 39fb642c4148cc12eefffcef056a4cbfbbfab314 Mon Sep 17 00:00:00 2001 From: Pavel Belikov Date: Sat, 23 Dec 2017 20:47:59 +0300 Subject: fix bash equal sign tokenization --- test.cxx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'test.cxx') diff --git a/test.cxx b/test.cxx index 4768cde..94defee 100644 --- a/test.cxx +++ b/test.cxx @@ -1260,8 +1260,14 @@ TEST_CASE("Completion works as expected", "[args]") args::MapFlag m(p, "mappos", "mappos", {'m', "map"}, {{"1",1}, {"2", 2}}); REQUIRE_THROWS_WITH(p.ParseArgs(std::vector{"--completion", "bash", "2", "test", "-m", ""}), Equals("1\n2")); - REQUIRE_THROWS_WITH(p.ParseArgs(std::vector{"--completion", "bash", "1", "test", "--map="}), Equals("--map=1\n--map=2")); + REQUIRE_THROWS_WITH(p.ParseArgs(std::vector{"--completion", "bash", "1", "test", "--map="}), Equals("1\n2")); + REQUIRE_THROWS_WITH(p.ParseArgs(std::vector{"--completion", "bash", "2", "test", "--map", "="}), Equals("1\n2")); REQUIRE_THROWS_WITH(p.ParseArgs(std::vector{"--completion", "bash", "1", "test", "-m1"}), Equals("-m1")); + + args::Positional pos(p, "name", "desc"); + REQUIRE_THROWS_WITH(p.ParseArgs(std::vector{"--completion", "bash", "1", "test", ""}), Equals("")); + REQUIRE_THROWS_WITH(p.ParseArgs(std::vector{"--completion", "bash", "1", "test", "-"}), Equals("-f\n-b\n-m")); + REQUIRE_THROWS_WITH(p.ParseArgs(std::vector{"--completion", "bash", "1", "test", "--"}), Equals("--foo\n--bar\n--map")); } #undef ARGS_HXX -- cgit v1.2.1 From 016304b1043e104d19b3a48e6ed2d8d398c63229 Mon Sep 17 00:00:00 2001 From: Pavel Belikov Date: Sat, 23 Dec 2017 22:21:56 +0300 Subject: fix subparsers completion --- test.cxx | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'test.cxx') diff --git a/test.cxx b/test.cxx index 94defee..ffb475b 100644 --- a/test.cxx +++ b/test.cxx @@ -1251,8 +1251,9 @@ TEST_CASE("Completion works as expected", "[args]") args::ArgumentParser p("parser"); args::CompletionFlag c(p, {"completion"}); - args::ValueFlag f(p, "name", "description", {'f', "foo"}, "abc"); - args::ValueFlag b(p, "name", "description", {'b', "bar"}, "abc"); + args::Group g(p); + args::ValueFlag f(g, "name", "description", {'f', "foo"}, "abc"); + args::ValueFlag b(g, "name", "description", {'b', "bar"}, "abc"); REQUIRE_THROWS_WITH(p.ParseArgs(std::vector{"--completion", "bash", "1", "test", "-"}), Equals("-f\n-b")); REQUIRE_THROWS_WITH(p.ParseArgs(std::vector{"--completion", "bash", "1", "test", "-f"}), Equals("-f")); @@ -1268,6 +1269,26 @@ TEST_CASE("Completion works as expected", "[args]") REQUIRE_THROWS_WITH(p.ParseArgs(std::vector{"--completion", "bash", "1", "test", ""}), Equals("")); REQUIRE_THROWS_WITH(p.ParseArgs(std::vector{"--completion", "bash", "1", "test", "-"}), Equals("-f\n-b\n-m")); REQUIRE_THROWS_WITH(p.ParseArgs(std::vector{"--completion", "bash", "1", "test", "--"}), Equals("--foo\n--bar\n--map")); + + args::ArgumentParser p2("parser"); + args::CompletionFlag complete2(p2, {"completion"}); + + args::Command c1(p2, "command1", "desc", [](args::Subparser &sp) + { + args::ValueFlag f1(sp, "name", "description", {'f', "foo"}, "abc"); + sp.Parse(); + }); + + args::Command c2(p2, "command2", "desc", [](args::Subparser &sp) + { + args::ValueFlag f1(sp, "name", "description", {'b', "bar"}, "abc"); + sp.Parse(); + }); + + REQUIRE_THROWS_WITH(p2.ParseArgs(std::vector{"--completion", "bash", "1", "test", "-"}), Equals("")); + REQUIRE_THROWS_WITH(p2.ParseArgs(std::vector{"--completion", "bash", "1", "test", ""}), Equals("command1\ncommand2")); + REQUIRE_THROWS_WITH(p2.ParseArgs(std::vector{"--completion", "bash", "2", "test", "command1", ""}), Equals("-f")); + REQUIRE_THROWS_WITH(p2.ParseArgs(std::vector{"--completion", "bash", "2", "test", "command2", ""}), Equals("-b")); } #undef ARGS_HXX @@ -1415,3 +1436,17 @@ TEST_CASE("Matcher validation works as expected in noexcept mode", "[args]") REQUIRE(parser.GetError() == argstest::Error::Usage); } +TEST_CASE("Completion works as expected in noexcept mode", "[args]") +{ + using namespace Catch::Matchers; + + argstest::ArgumentParser p("parser"); + argstest::CompletionFlag c(p, {"completion"}); + argstest::Group g(p); + argstest::ValueFlag f(g, "name", "description", {'f', "foo"}, "abc"); + argstest::ValueFlag b(g, "name", "description", {'b', "bar"}, "abc"); + + p.ParseArgs(std::vector{"--completion", "bash", "1", "test", "-"}); + REQUIRE(p.GetError() == argstest::Error::Completion); + REQUIRE(argstest::get(c) == "-f\n-b"); +} -- cgit v1.2.1 From b8fc68ac37103a3b35d013ff10d0b623a3d6a75d Mon Sep 17 00:00:00 2001 From: Pavel Belikov Date: Sat, 23 Dec 2017 23:16:30 +0300 Subject: add more test cases --- test.cxx | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test.cxx') diff --git a/test.cxx b/test.cxx index ffb475b..13cd4d0 100644 --- a/test.cxx +++ b/test.cxx @@ -1276,6 +1276,7 @@ TEST_CASE("Completion works as expected", "[args]") args::Command c1(p2, "command1", "desc", [](args::Subparser &sp) { args::ValueFlag f1(sp, "name", "description", {'f', "foo"}, "abc"); + f1.KickOut(); sp.Parse(); }); @@ -1289,6 +1290,8 @@ TEST_CASE("Completion works as expected", "[args]") REQUIRE_THROWS_WITH(p2.ParseArgs(std::vector{"--completion", "bash", "1", "test", ""}), Equals("command1\ncommand2")); REQUIRE_THROWS_WITH(p2.ParseArgs(std::vector{"--completion", "bash", "2", "test", "command1", ""}), Equals("-f")); REQUIRE_THROWS_WITH(p2.ParseArgs(std::vector{"--completion", "bash", "2", "test", "command2", ""}), Equals("-b")); + REQUIRE_THROWS_WITH(p2.ParseArgs(std::vector{"--completion", "bash", "2", "test", "command3", ""}), Equals("")); + REQUIRE_THROWS_WITH(p2.ParseArgs(std::vector{"--completion", "bash", "3", "test", "command1", "-f", "-"}), Equals("")); } #undef ARGS_HXX -- cgit v1.2.1