From f4fd39821ac05baabfe13590e9b71e3088a77bc4 Mon Sep 17 00:00:00 2001 From: "Taylor C. Richberger" Date: Thu, 30 Jun 2016 12:15:20 -0600 Subject: add noexcept functionality --- test.cxx | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 2 deletions(-) (limited to 'test.cxx') diff --git a/test.cxx b/test.cxx index 8113943..b4cc9fc 100644 --- a/test.cxx +++ b/test.cxx @@ -251,11 +251,12 @@ TEST_CASE("Argument groups should nest", "[args]") REQUIRE_THROWS_AS(parser.ParseArgs(std::vector{"-a", "-dg"}), args::ValidationError); } -void DoublesReader(const std::string &name, const std::string &value, std::tuple &destination) +bool DoublesReader(const std::string &name, const std::string &value, std::tuple &destination) { size_t commapos = 0; std::get<0>(destination) = std::stod(value, &commapos); std::get<1>(destination) = std::stod(std::string(value, commapos + 1)); + return true; } TEST_CASE("Custom types work", "[args]") @@ -375,10 +376,11 @@ enum class MappingEnum #include #include -void ToLowerReader(const std::string &name, const std::string &value, std::string &destination) +bool ToLowerReader(const std::string &name, const std::string &value, std::string &destination) { destination = value; std::transform(destination.begin(), destination.end(), destination.begin(), ::tolower); + return true; } TEST_CASE("Mapping types work as needed", "[args]") @@ -522,3 +524,66 @@ TEST_CASE("Kick-out should work via all flags and value flags", "[args]") REQUIRE_FALSE(c3); REQUIRE(d3); } + +#define ARGS_TESTNAMESPACE +#define ARGS_NOEXCEPT +#include + +TEST_CASE("Noexcept mode works as expected", "[args]") +{ + std::unordered_map map{ + {"default", MappingEnum::def}, + {"foo", MappingEnum::foo}, + {"bar", MappingEnum::bar}, + {"red", MappingEnum::red}, + {"yellow", MappingEnum::yellow}, + {"green", MappingEnum::green}}; + + argstest::ArgumentParser parser("This is a test program.", "This goes after the options."); + argstest::HelpFlag help(parser, "help", "Display this help menu", {'h', "help"}); + argstest::Flag bar(parser, "BAR", "test flag", {'b', "bar"}, true); + argstest::ValueFlag foo(parser, "FOO", "test flag", {'f', "foo"}); + argstest::Group nandgroup(parser, "this group provides nand validation", argstest::Group::Validators::AtMostOne); + argstest::Flag x(nandgroup, "x", "test flag", {'x'}); + argstest::Flag y(nandgroup, "y", "test flag", {'y'}); + argstest::Flag z(nandgroup, "z", "test flag", {'z'}); + argstest::MapFlag mf(parser, "MF", "Maps string to an enum", {"mf"}, map); + parser.ParseArgs(std::vector{"-h"}); + REQUIRE(parser.GetError() == argstest::Error::Help); + parser.ParseArgs(std::vector{"--Help"}); + REQUIRE(parser.GetError() == argstest::Error::Parse); + parser.ParseArgs(std::vector{"--bar=test"}); + REQUIRE(parser.GetError() == argstest::Error::Parse); + parser.ParseArgs(std::vector{"--bar"}); + REQUIRE(parser.GetError() == argstest::Error::None); + parser.ParseArgs(std::vector{"--bar", "-b"}); + REQUIRE(parser.GetError() == argstest::Error::Extra); + + parser.ParseArgs(std::vector{"--foo=7.5"}); + REQUIRE(parser.GetError() == argstest::Error::Parse); + parser.ParseArgs(std::vector{"--foo", "7a"}); + REQUIRE(parser.GetError() == argstest::Error::Parse); + parser.ParseArgs(std::vector{"--foo", "7e4"}); + REQUIRE(parser.GetError() == argstest::Error::Parse); + parser.ParseArgs(std::vector{"--foo"}); + REQUIRE(parser.GetError() == argstest::Error::Parse); + + parser.ParseArgs(std::vector{"--foo=85"}); + REQUIRE(parser.GetError() == argstest::Error::None); + + parser.ParseArgs(std::vector{"this is a test flag again", "1", "this has no positional available"}); + REQUIRE(parser.GetError() == argstest::Error::Parse); + + parser.ParseArgs(std::vector{"-x"}); + REQUIRE(parser.GetError() == argstest::Error::None); + parser.ParseArgs(std::vector{"-xz"}); + REQUIRE(parser.GetError() == argstest::Error::Validation); + parser.ParseArgs(std::vector{"-y"}); + REQUIRE(parser.GetError() == argstest::Error::None); + parser.ParseArgs(std::vector{"-y", "-xz"}); + REQUIRE(parser.GetError() == argstest::Error::Validation); + parser.ParseArgs(std::vector{"--mf", "YeLLoW"}); + REQUIRE(parser.GetError() == argstest::Error::Map); + parser.ParseArgs(std::vector{"--mf", "yellow"}); + REQUIRE(parser.GetError() == argstest::Error::None); +} -- cgit v1.2.1