diff options
author | Taylor C. Richberger <Taywee@gmx.com> | 2016-05-09 17:08:23 -0600 |
---|---|---|
committer | Taylor C. Richberger <Taywee@gmx.com> | 2016-05-09 17:08:23 -0600 |
commit | a8ab419fcee610891602eac72ffe051db656e943 (patch) | |
tree | 181b6fd258a74091d248178262112ddd37312179 /test.cxx | |
parent | some small const improvements (diff) | |
download | args.hxx-a8ab419fcee610891602eac72ffe051db656e943.tar.xz |
resolve this, and improve help generation
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"})); +} |