Skip to content

Commit

Permalink
add Matcher validation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Belikov committed Nov 12, 2017
1 parent da501db commit a86c29b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions args.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ namespace args
*/
template <typename Short, typename Long>
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
Expand All @@ -360,7 +360,7 @@ namespace args
* args::Matcher{"foo", 'f', 'F', "FoO"}
*/
Matcher(std::initializer_list<EitherFlag> 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))
{}
Expand Down
17 changes: 17 additions & 0 deletions test.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,12 @@ TEST_CASE("GetProgramLine works as expected", "[args]")
REQUIRE(line(b) == "b -f <STRING> [positional]");
}

TEST_CASE("Matcher validation works as expected", "[args]")
{
args::ArgumentParser parser("Test command");
REQUIRE_THROWS_AS(args::ValueFlag<int>(parser, "", "", {}), args::UsageError);
}

#undef ARGS_HXX
#define ARGS_TESTNAMESPACE
#define ARGS_NOEXCEPT
Expand Down Expand Up @@ -1088,6 +1094,17 @@ TEST_CASE("Nargs work as expected in noexcept mode", "[args]")
argstest::ArgumentParser parser("Test command");
argstest::NargsValueFlag<int> a(parser, "", "", {'a'}, {3, 2});

REQUIRE(parser.GetError() == argstest::Error::Usage);
parser.ParseArgs(std::vector<std::string>{"-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<int> a(parser, "", "", {});

REQUIRE(parser.GetError() == argstest::Error::Usage);
parser.ParseArgs(std::vector<std::string>{"-a", "1", "2"});
REQUIRE(parser.GetError() == argstest::Error::Usage);
}
Expand Down

0 comments on commit a86c29b

Please sign in to comment.