diff options
author | Taylor C. Richberger <taywee@gmx.com> | 2016-05-09 19:14:16 -0400 |
---|---|---|
committer | Taylor C. Richberger <taywee@gmx.com> | 2016-05-09 19:14:16 -0400 |
commit | dd1ed9fe73a0c45f2612e32627e0d4b6bcba8690 (patch) | |
tree | 8ed28eb5db2cba62dab55ba3c4de7995b6a07ce4 /test.cxx | |
parent | some small const improvements (diff) | |
parent | make changes, bump version number (diff) | |
download | args.hxx-2.1.0.tar.xz |
Merge branch '12-allow-user-to-specify-argument-separation-on-argumentparser' into 'master'
2.1.0
12 allow user to specify argument separation on argumentparser
Closes #12
See merge request !8
Diffstat (limited to 'test.cxx')
-rw-r--r-- | test.cxx | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -68,6 +68,13 @@ TEST_CASE("Argument flags work as expected, with clustering", "[args]") REQUIRE_FALSE(bix); } +TEST_CASE("Passing an argument to a non-argument flag throws an error", "[args]") +{ + args::ArgumentParser parser("This is a test program.", "This goes after the options."); + args::Flag bar(parser, "BAR", "test flag", args::Matcher{'b', "bar"}); + REQUIRE_THROWS_AS(parser.ParseArgs(std::vector<std::string>{"--bar=test"}), args::ParseError); +} + TEST_CASE("Unified argument lists for match work", "[args]") { args::ArgumentParser parser("This is a test program.", "This goes after the options."); @@ -278,3 +285,33 @@ TEST_CASE("Help menu can be grabbed as a string, passed into a stream, or by usi parser.Help(null); null << parser; } + +TEST_CASE("Required argument separation being violated throws an error", "[args]") +{ + args::ArgumentParser parser("This is a test program.", "This goes after the options."); + args::ArgFlag<std::string> bar(parser, "BAR", "test flag", args::Matcher{'b', "bar"}); + REQUIRE_NOTHROW(parser.ParseArgs(std::vector<std::string>{"-btest"})); + REQUIRE_NOTHROW(parser.ParseArgs(std::vector<std::string>{"--bar=test"})); + REQUIRE_NOTHROW(parser.ParseArgs(std::vector<std::string>{"-b", "test"})); + REQUIRE_NOTHROW(parser.ParseArgs(std::vector<std::string>{"--bar", "test"})); + parser.SetArgumentSeparations(true, false, false, false); + REQUIRE_NOTHROW(parser.ParseArgs(std::vector<std::string>{"-btest"})); + REQUIRE_THROWS_AS(parser.ParseArgs(std::vector<std::string>{"--bar=test"}), args::ParseError); + REQUIRE_THROWS_AS(parser.ParseArgs(std::vector<std::string>{"-b", "test"}), args::ParseError); + REQUIRE_THROWS_AS(parser.ParseArgs(std::vector<std::string>{"--bar", "test"}), args::ParseError); + parser.SetArgumentSeparations(false, true, false, false); + REQUIRE_THROWS_AS(parser.ParseArgs(std::vector<std::string>{"-btest"}), args::ParseError); + REQUIRE_NOTHROW(parser.ParseArgs(std::vector<std::string>{"--bar=test"})); + REQUIRE_THROWS_AS(parser.ParseArgs(std::vector<std::string>{"-b", "test"}), args::ParseError); + REQUIRE_THROWS_AS(parser.ParseArgs(std::vector<std::string>{"--bar", "test"}), args::ParseError); + parser.SetArgumentSeparations(false, false, true, false); + REQUIRE_THROWS_AS(parser.ParseArgs(std::vector<std::string>{"-btest"}), args::ParseError); + REQUIRE_THROWS_AS(parser.ParseArgs(std::vector<std::string>{"--bar=test"}), args::ParseError); + REQUIRE_NOTHROW(parser.ParseArgs(std::vector<std::string>{"-b", "test"})); + REQUIRE_THROWS_AS(parser.ParseArgs(std::vector<std::string>{"--bar", "test"}), args::ParseError); + parser.SetArgumentSeparations(false, false, false, true); + REQUIRE_THROWS_AS(parser.ParseArgs(std::vector<std::string>{"-btest"}), args::ParseError); + REQUIRE_THROWS_AS(parser.ParseArgs(std::vector<std::string>{"--bar=test"}), args::ParseError); + REQUIRE_THROWS_AS(parser.ParseArgs(std::vector<std::string>{"-b", "test"}), args::ParseError); + REQUIRE_NOTHROW(parser.ParseArgs(std::vector<std::string>{"--bar", "test"})); +} |