From a86c29be5bb206420aa7520633782c7fc6c1b4db Mon Sep 17 00:00:00 2001 From: Pavel Belikov Date: Sun, 12 Nov 2017 16:45:02 +0300 Subject: add Matcher validation tests --- args.hxx | 4 ++-- test.cxx | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/args.hxx b/args.hxx index 817835d..c595ab7 100644 --- a/args.hxx +++ b/args.hxx @@ -344,7 +344,7 @@ namespace args */ template Matcher(Short &&shortIn, Long &&longIn) : - shortFlags(std::begin(shortIn), std::end(shortIn)), longFlags(std::begin(longIn), std::end(longIn)) + Matcher(std::begin(shortIn), std::end(shortIn), std::begin(longIn), std::end(longIn)) {} /** Specify a mixed single initializer-list of both short and long flags @@ -360,7 +360,7 @@ namespace args * args::Matcher{"foo", 'f', 'F', "FoO"} */ Matcher(std::initializer_list in) : - shortFlags(EitherFlag::GetShort(in)), longFlags(EitherFlag::GetLong(in)) {} + Matcher(EitherFlag::GetShort(in), EitherFlag::GetLong(in)) {} Matcher(Matcher &&other) : shortFlags(std::move(other.shortFlags)), longFlags(std::move(other.longFlags)) {} diff --git a/test.cxx b/test.cxx index 3376059..71f1fb7 100644 --- a/test.cxx +++ b/test.cxx @@ -958,6 +958,12 @@ TEST_CASE("GetProgramLine works as expected", "[args]") REQUIRE(line(b) == "b -f [positional]"); } +TEST_CASE("Matcher validation works as expected", "[args]") +{ + args::ArgumentParser parser("Test command"); + REQUIRE_THROWS_AS(args::ValueFlag(parser, "", "", {}), args::UsageError); +} + #undef ARGS_HXX #define ARGS_TESTNAMESPACE #define ARGS_NOEXCEPT @@ -1088,6 +1094,17 @@ TEST_CASE("Nargs work as expected in noexcept mode", "[args]") argstest::ArgumentParser parser("Test command"); argstest::NargsValueFlag a(parser, "", "", {'a'}, {3, 2}); + REQUIRE(parser.GetError() == argstest::Error::Usage); + parser.ParseArgs(std::vector{"-a", "1", "2"}); + REQUIRE(parser.GetError() == argstest::Error::Usage); +} + +TEST_CASE("Matcher validation works as expected in noexcept mode", "[args]") +{ + argstest::ArgumentParser parser("Test command"); + argstest::ValueFlag a(parser, "", "", {}); + + REQUIRE(parser.GetError() == argstest::Error::Usage); parser.ParseArgs(std::vector{"-a", "1", "2"}); REQUIRE(parser.GetError() == argstest::Error::Usage); } -- cgit v1.2.1