aboutsummaryrefslogtreecommitdiff
path: root/test.cxx
diff options
context:
space:
mode:
authorTaylor C. Richberger <Taywee@gmx.com>2016-06-14 19:35:48 -0600
committerTaylor C. Richberger <Taywee@gmx.com>2016-06-14 19:35:48 -0600
commit8c1154cbcddf5dfcb278e3a821cb1d0a3a6c984e (patch)
tree36ece64bf25c6cf76012da7c7a5bd7be1a75cf2e /test.cxx
parentfixed problem hopefully (diff)
downloadargs.hxx-8c1154cbcddf5dfcb278e3a821cb1d0a3a6c984e.tar.xz
add new feature
Diffstat (limited to 'test.cxx')
-rw-r--r--test.cxx30
1 files changed, 30 insertions, 0 deletions
diff --git a/test.cxx b/test.cxx
index b4c451b..c368bf9 100644
--- a/test.cxx
+++ b/test.cxx
@@ -412,3 +412,33 @@ TEST_CASE("Mapping types work as needed", "[args]")
REQUIRE((args::get(mpl) == std::vector<MappingEnum>{MappingEnum::red, MappingEnum::def}));
REQUIRE_THROWS_AS(parser.ParseArgs(std::vector<std::string>{"--mf=YeLLoW"}), args::MapError);
}
+
+TEST_CASE("An exception should be thrown when a single-argument flag is matched multiple times and the constructor option is specified", "[args]")
+{
+ std::unordered_map<std::string, MappingEnum> map{
+ {"default", MappingEnum::def},
+ {"foo", MappingEnum::foo},
+ {"bar", MappingEnum::bar},
+ {"red", MappingEnum::red},
+ {"yellow", MappingEnum::yellow},
+ {"green", MappingEnum::green}};
+
+ std::ostream null(nullptr);
+ args::ArgumentParser parser("Test command");
+ args::Flag foo(parser, "Foo", "Foo", {'f', "foo"}, true);
+ args::ValueFlag<std::string> bar(parser, "Bar", "Bar", {'b', "bar"}, "", true);
+ args::Flag bix(parser, "Bix", "Bix", {'x', "bix"});
+ args::MapFlag<std::string, MappingEnum> baz(parser, "Baz", "Baz", {'B', "baz"}, map, MappingEnum::def, true);
+ REQUIRE_THROWS_AS(parser.ParseArgs(std::vector<std::string>{"--foo", "-f", "-bblah"}), args::ExtraError);
+ REQUIRE_NOTHROW(parser.ParseArgs(std::vector<std::string>{"--foo", "-xxx", "--bix", "-bblah", "--bix"}));
+ REQUIRE_THROWS_AS(parser.ParseArgs(std::vector<std::string>{"--foo", "-bblah", "-blah"}), args::ExtraError);
+ REQUIRE_THROWS_AS(parser.ParseArgs(std::vector<std::string>{"--foo", "-bblah", "--bar", "blah"}), args::ExtraError);
+ REQUIRE_THROWS_AS(parser.ParseArgs(std::vector<std::string>{"--baz=red", "-B", "yellow"}), args::ExtraError);
+ REQUIRE_THROWS_AS(parser.ParseArgs(std::vector<std::string>{"--baz", "red", "-Byellow"}), args::ExtraError);
+ REQUIRE_NOTHROW(parser.ParseArgs(std::vector<std::string>{"--foo", "-Bgreen"}));
+ REQUIRE(foo);
+ REQUIRE_FALSE(bar);
+ REQUIRE_FALSE(bix);
+ REQUIRE(baz);
+ REQUIRE(args::get(baz) == MappingEnum::green);
+}