From da501db8a06b31bf771767302ddad065524d5e67 Mon Sep 17 00:00:00 2001 From: Pavel Belikov Date: Sun, 12 Nov 2017 16:34:21 +0300 Subject: add HelpParams::proglineShowFlags --- test.cxx | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'test.cxx') diff --git a/test.cxx b/test.cxx index ba4d5f8..3376059 100644 --- a/test.cxx +++ b/test.cxx @@ -909,6 +909,55 @@ TEST_CASE("Global options work as expected", "[args]") REQUIRE_NOTHROW(p.ParseArgs(std::vector{"b", "-f"})); } +TEST_CASE("GetProgramLine works as expected", "[args]") +{ + args::ArgumentParser p("parser"); + args::Flag g(p, "g", "g", {'g'}, args::Options::Global); + args::Flag hidden(p, "hidden", "hidden flag", {'h'}, args::Options::Hidden); + args::Command a(p, "a", "command a", [](args::Subparser &s) + { + args::ValueFlag f(s, "STRING", "my f flag", {'f', "f-long"}, args::Options::Required); + args::Positional pos(s, "positional", "positional", args::Options::Required); + s.Parse(); + }); + + args::Command b(p, "b", "command b"); + args::ValueFlag f(b, "STRING", "my f flag", {'f'}, args::Options::Required); + args::Positional pos(b, "positional", "positional"); + + auto line = [&](args::Command &element) + { + p.Reset(); + auto strings = element.GetCommandProgramLine(p.helpParams); + std::string res; + for (const std::string &s: strings) + { + if (!res.empty()) + { + res += ' '; + } + + res += s; + } + + return res; + }; + + REQUIRE(line(p) == "COMMAND {OPTIONS}"); + REQUIRE(line(a) == "a positional {OPTIONS}"); + REQUIRE(line(b) == "b [positional] {OPTIONS}"); + + p.helpParams.proglineShowFlags = true; + REQUIRE(line(p) == "COMMAND [-g]"); + REQUIRE(line(a) == "a --f-long positional"); + REQUIRE(line(b) == "b -f [positional]"); + + p.helpParams.proglinePreferShortFlags = true; + REQUIRE(line(p) == "COMMAND [-g]"); + REQUIRE(line(a) == "a -f positional"); + REQUIRE(line(b) == "b -f [positional]"); +} + #undef ARGS_HXX #define ARGS_TESTNAMESPACE #define ARGS_NOEXCEPT -- cgit v1.2.1