diff options
author | Taylor C. Richberger <Taywee@gmx.com> | 2016-06-02 16:28:41 -0600 |
---|---|---|
committer | Taylor C. Richberger <Taywee@gmx.com> | 2016-06-02 16:28:41 -0600 |
commit | 60ba26118dd8886749229235fc92aec01b7d7ca1 (patch) | |
tree | c40aa934877f5b5634e438df25248e2745bd9a5a /test.cxx | |
parent | empty group helps don't show up in help menu generation or influence indent (diff) | |
download | args.hxx-60ba26118dd8886749229235fc92aec01b7d7ca1.tar.xz |
improve readability by culling explicit matcher construction
Diffstat (limited to 'test.cxx')
-rw-r--r-- | test.cxx | 118 |
1 files changed, 59 insertions, 59 deletions
@@ -21,7 +21,7 @@ std::istream& operator>>(std::istream& is, std::tuple<int, int>& ints) TEST_CASE("Help flag throws Help exception", "[args]") { args::ArgumentParser parser("This is a test program.", "This goes after the options."); - args::HelpFlag help(parser, "help", "Display this help menu", args::Matcher{'h', "help"}); + args::HelpFlag help(parser, "help", "Display this help menu", {'h', "help"}); REQUIRE_NOTHROW(parser.ParseArgs(std::vector<std::string>{})); REQUIRE_THROWS_AS(parser.ParseArgs(std::vector<std::string>{"--help"}), args::Help); } @@ -29,7 +29,7 @@ TEST_CASE("Help flag throws Help exception", "[args]") TEST_CASE("Unknown flags throw exceptions", "[args]") { args::ArgumentParser parser("This is a test program.", "This goes after the options."); - args::HelpFlag help(parser, "help", "Display this help menu", args::Matcher{'h', "help"}); + args::HelpFlag help(parser, "help", "Display this help menu", {'h', "help"}); REQUIRE_NOTHROW(parser.ParseArgs(std::vector<std::string>{})); REQUIRE_THROWS_AS(parser.ParseArgs(std::vector<std::string>{"--Help"}), args::ParseError); REQUIRE_THROWS_AS(parser.ParseArgs(std::vector<std::string>{"-H"}), args::ParseError); @@ -38,10 +38,10 @@ TEST_CASE("Unknown flags throw exceptions", "[args]") TEST_CASE("Boolean flags work as expected, with clustering", "[args]") { args::ArgumentParser parser("This is a test program.", "This goes after the options."); - args::Flag foo(parser, "FOO", "test flag", args::Matcher{'f', "foo"}); - args::Flag bar(parser, "BAR", "test flag", args::Matcher{'b', "bar"}); - args::Flag baz(parser, "BAZ", "test flag", args::Matcher{'a', "baz"}); - args::Flag bix(parser, "BAZ", "test flag", args::Matcher{'x', "bix"}); + args::Flag foo(parser, "FOO", "test flag", {'f', "foo"}); + args::Flag bar(parser, "BAR", "test flag", {'b', "bar"}); + args::Flag baz(parser, "BAZ", "test flag", {'a', "baz"}); + args::Flag bix(parser, "BAZ", "test flag", {'x', "bix"}); parser.ParseArgs(std::vector<std::string>{"--baz", "-fb"}); REQUIRE(foo); REQUIRE(bar); @@ -52,9 +52,9 @@ TEST_CASE("Boolean flags work as expected, with clustering", "[args]") TEST_CASE("Count flag works as expected", "[args]") { args::ArgumentParser parser("This is a test program.", "This goes after the options."); - args::CounterFlag foo(parser, "FOO", "test flag", args::Matcher{'f', "foo"}); - args::CounterFlag bar(parser, "BAR", "test flag", args::Matcher{'b', "bar"}, 7); - args::CounterFlag baz(parser, "BAZ", "test flag", args::Matcher{'z', "baz"}, 7); + args::CounterFlag foo(parser, "FOO", "test flag", {'f', "foo"}); + args::CounterFlag bar(parser, "BAR", "test flag", {'b', "bar"}, 7); + args::CounterFlag baz(parser, "BAZ", "test flag", {'z', "baz"}, 7); parser.ParseArgs(std::vector<std::string>{"--foo", "-fb", "--bar", "-b", "-f", "--foo"}); REQUIRE(foo); REQUIRE(bar); @@ -67,11 +67,11 @@ TEST_CASE("Count flag works as expected", "[args]") TEST_CASE("Argument flags work as expected, with clustering", "[args]") { args::ArgumentParser parser("This is a test program.", "This goes after the options."); - args::ValueFlag<std::string> foo(parser, "FOO", "test flag", args::Matcher{'f', "foo"}); - args::Flag bar(parser, "BAR", "test flag", args::Matcher{'b', "bar"}); - args::ValueFlag<double> baz(parser, "BAZ", "test flag", args::Matcher{'a', "baz"}); - args::ValueFlag<char> bim(parser, "BAZ", "test flag", args::Matcher{'B', "bim"}); - args::Flag bix(parser, "BAZ", "test flag", args::Matcher{'x', "bix"}); + args::ValueFlag<std::string> foo(parser, "FOO", "test flag", {'f', "foo"}); + args::Flag bar(parser, "BAR", "test flag", {'b', "bar"}); + args::ValueFlag<double> baz(parser, "BAZ", "test flag", {'a', "baz"}); + args::ValueFlag<char> bim(parser, "BAZ", "test flag", {'B', "bim"}); + args::Flag bix(parser, "BAZ", "test flag", {'x', "bix"}); parser.ParseArgs(std::vector<std::string>{"-bftest", "--baz=7.555e2", "--bim", "c"}); REQUIRE(foo); REQUIRE(args::get(foo) == "test"); @@ -86,18 +86,18 @@ TEST_CASE("Argument flags work as expected, with clustering", "[args]") 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"}); + args::Flag bar(parser, "BAR", "test flag", {'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."); - args::ValueFlag<std::string> foo(parser, "FOO", "test flag", args::Matcher{'f', "foo"}); - args::Flag bar(parser, "BAR", "test flag", args::Matcher{"bar", 'b'}); - args::ValueFlag<double> baz(parser, "BAZ", "test flag", args::Matcher{'a', "baz"}); - args::ValueFlag<char> bim(parser, "BAZ", "test flag", args::Matcher{'B', "bim"}); - args::Flag bix(parser, "BAZ", "test flag", args::Matcher{"bix"}); + args::ValueFlag<std::string> foo(parser, "FOO", "test flag", {'f', "foo"}); + args::Flag bar(parser, "BAR", "test flag", {"bar", 'b'}); + args::ValueFlag<double> baz(parser, "BAZ", "test flag", {'a', "baz"}); + args::ValueFlag<char> bim(parser, "BAZ", "test flag", {'B', "bim"}); + args::Flag bix(parser, "BAZ", "test flag", {"bix"}); parser.ParseArgs(std::vector<std::string>{"-bftest", "--baz=7.555e2", "--bim", "c"}); REQUIRE(foo); REQUIRE(args::get(foo) == "test"); @@ -112,7 +112,7 @@ TEST_CASE("Unified argument lists for match work", "[args]") TEST_CASE("Get can be assigned to for non-reference types", "[args]") { args::ArgumentParser parser("This is a test program.", "This goes after the options."); - args::ValueFlag<std::string> foo(parser, "FOO", "test flag", args::Matcher{'f', "foo"}); + args::ValueFlag<std::string> foo(parser, "FOO", "test flag", {'f', "foo"}); parser.ParseArgs(std::vector<std::string>{"--foo=test"}); REQUIRE(foo); REQUIRE(args::get(foo) == "test"); @@ -123,7 +123,7 @@ TEST_CASE("Get can be assigned to for non-reference types", "[args]") TEST_CASE("Invalid argument parsing throws parsing exceptions", "[args]") { args::ArgumentParser parser("This is a test program.", "This goes after the options."); - args::ValueFlag<int> foo(parser, "FOO", "test flag", args::Matcher{'f', "foo"}); + args::ValueFlag<int> foo(parser, "FOO", "test flag", {'f', "foo"}); REQUIRE_THROWS_AS(parser.ParseArgs(std::vector<std::string>{"--foo=7.5"}), args::ParseError); REQUIRE_THROWS_AS(parser.ParseArgs(std::vector<std::string>{"--foo", "7a"}), args::ParseError); REQUIRE_THROWS_AS(parser.ParseArgs(std::vector<std::string>{"--foo", "7e4"}), args::ParseError); @@ -132,7 +132,7 @@ TEST_CASE("Invalid argument parsing throws parsing exceptions", "[args]") TEST_CASE("Argument flag lists work as expected", "[args]") { args::ArgumentParser parser("This is a test program.", "This goes after the options."); - args::ValueFlagList<int> foo(parser, "FOO", "test flag", args::Matcher{'f', "foo"}); + args::ValueFlagList<int> foo(parser, "FOO", "test flag", {'f', "foo"}); parser.ParseArgs(std::vector<std::string>{"--foo=7", "-f2", "-f", "9", "--foo", "42"}); REQUIRE((args::get(foo) == std::vector<int>{7, 2, 9, 42})); } @@ -177,16 +177,16 @@ TEST_CASE("Argument groups should throw when validation fails", "[args]") { args::ArgumentParser parser("This is a test program.", "This goes after the options."); args::Group xorgroup(parser, "this group provides xor validation", args::Group::Validators::Xor); - args::Flag a(xorgroup, "a", "test flag", args::Matcher({'a'})); - args::Flag b(xorgroup, "b", "test flag", args::Matcher({'b'})); - args::Flag c(xorgroup, "c", "test flag", args::Matcher({'c'})); + args::Flag a(xorgroup, "a", "test flag", {'a'}); + args::Flag b(xorgroup, "b", "test flag", {'b'}); + args::Flag c(xorgroup, "c", "test flag", {'c'}); args::Group nxor(parser, "this group provides all-or-none (nxor) validation", args::Group::Validators::AllOrNone); - args::Flag d(nxor, "d", "test flag", args::Matcher({'d'})); - args::Flag e(nxor, "e", "test flag", args::Matcher({'e'})); - args::Flag f(nxor, "f", "test flag", args::Matcher({'f'})); + args::Flag d(nxor, "d", "test flag", {'d'}); + args::Flag e(nxor, "e", "test flag", {'e'}); + args::Flag f(nxor, "f", "test flag", {'f'}); args::Group atleastone(parser, "this group provides at-least-one validation", args::Group::Validators::AtLeastOne); - args::Flag g(atleastone, "g", "test flag", args::Matcher({'g'})); - args::Flag h(atleastone, "h", "test flag", args::Matcher({'h'})); + args::Flag g(atleastone, "g", "test flag", {'g'}); + args::Flag h(atleastone, "h", "test flag", {'h'}); // Needs g or h REQUIRE_THROWS_AS(parser.ParseArgs(std::vector<std::string>{"-a"}), args::ValidationError); REQUIRE_NOTHROW(parser.ParseArgs(std::vector<std::string>{"-g", "-a"})); @@ -210,16 +210,16 @@ TEST_CASE("Argument groups should nest", "[args]") { args::ArgumentParser parser("This is a test program.", "This goes after the options."); args::Group xorgroup(parser, "this group provides xor validation", args::Group::Validators::Xor); - args::Flag a(xorgroup, "a", "test flag", args::Matcher({'a'})); - args::Flag b(xorgroup, "b", "test flag", args::Matcher({'b'})); - args::Flag c(xorgroup, "c", "test flag", args::Matcher({'c'})); + args::Flag a(xorgroup, "a", "test flag", {'a'}); + args::Flag b(xorgroup, "b", "test flag", {'b'}); + args::Flag c(xorgroup, "c", "test flag", {'c'}); args::Group nxor(xorgroup, "this group provides all-or-none (nxor) validation", args::Group::Validators::AllOrNone); - args::Flag d(nxor, "d", "test flag", args::Matcher({'d'})); - args::Flag e(nxor, "e", "test flag", args::Matcher({'e'})); - args::Flag f(nxor, "f", "test flag", args::Matcher({'f'})); + args::Flag d(nxor, "d", "test flag", {'d'}); + args::Flag e(nxor, "e", "test flag", {'e'}); + args::Flag f(nxor, "f", "test flag", {'f'}); args::Group atleastone(xorgroup, "this group provides at-least-one validation", args::Group::Validators::AtLeastOne); - args::Flag g(atleastone, "g", "test flag", args::Matcher({'g'})); - args::Flag h(atleastone, "h", "test flag", args::Matcher({'h'})); + args::Flag g(atleastone, "g", "test flag", {'g'}); + args::Flag h(atleastone, "h", "test flag", {'h'}); // Nothing actually matches, because nxor validates properly when it's empty, REQUIRE_NOTHROW(parser.ParseArgs(std::vector<std::string>{})); REQUIRE_NOTHROW(parser.ParseArgs(std::vector<std::string>{"-a", "-d"})); @@ -262,11 +262,11 @@ TEST_CASE("Custom parser prefixes (dd-style)", "[args]") args::ArgumentParser parser("This command likes to break your disks"); parser.LongPrefix(""); parser.LongSeparator("="); - args::HelpFlag help(parser, "HELP", "Show this help menu.", args::Matcher({"help"})); - args::ValueFlag<long> bs(parser, "BYTES", "Block size", args::Matcher({"bs"}), 512); - args::ValueFlag<long> skip(parser, "BYTES", "Bytes to skip", args::Matcher({"skip"}), 0); - args::ValueFlag<std::string> input(parser, "BLOCK SIZE", "Block size", args::Matcher({"if"})); - args::ValueFlag<std::string> output(parser, "BLOCK SIZE", "Block size", args::Matcher({"of"})); + args::HelpFlag help(parser, "HELP", "Show this help menu.", {"help"}); + args::ValueFlag<long> bs(parser, "BYTES", "Block size", {"bs"}, 512); + args::ValueFlag<long> skip(parser, "BYTES", "Bytes to skip", {"skip"}, 0); + args::ValueFlag<std::string> input(parser, "BLOCK SIZE", "Block size", {"if"}); + args::ValueFlag<std::string> output(parser, "BLOCK SIZE", "Block size", {"of"}); parser.ParseArgs(std::vector<std::string>{"skip=8", "if=/dev/null"}); REQUIRE_FALSE(bs); REQUIRE(args::get(bs) == 512); @@ -282,11 +282,11 @@ TEST_CASE("Custom parser prefixes (Some Windows styles)", "[args]") args::ArgumentParser parser("This command likes to break your disks"); parser.LongPrefix("/"); parser.LongSeparator(":"); - args::HelpFlag help(parser, "HELP", "Show this help menu.", args::Matcher({"help"})); - args::ValueFlag<long> bs(parser, "BYTES", "Block size", args::Matcher({"bs"}), 512); - args::ValueFlag<long> skip(parser, "BYTES", "Bytes to skip", args::Matcher({"skip"}), 0); - args::ValueFlag<std::string> input(parser, "BLOCK SIZE", "Block size", args::Matcher({"if"})); - args::ValueFlag<std::string> output(parser, "BLOCK SIZE", "Block size", args::Matcher({"of"})); + args::HelpFlag help(parser, "HELP", "Show this help menu.", {"help"}); + args::ValueFlag<long> bs(parser, "BYTES", "Block size", {"bs"}, 512); + args::ValueFlag<long> skip(parser, "BYTES", "Bytes to skip", {"skip"}, 0); + args::ValueFlag<std::string> input(parser, "BLOCK SIZE", "Block size", {"if"}); + args::ValueFlag<std::string> output(parser, "BLOCK SIZE", "Block size", {"of"}); parser.ParseArgs(std::vector<std::string>{"/skip:8", "/if:/dev/null"}); REQUIRE_FALSE(bs); REQUIRE(args::get(bs) == 512); @@ -301,11 +301,11 @@ TEST_CASE("Help menu can be grabbed as a string, passed into a stream, or by usi { std::ostream null(nullptr); args::ArgumentParser parser("This command likes to break your disks"); - args::HelpFlag help(parser, "HELP", "Show this help menu.", args::Matcher({"help"})); - args::ValueFlag<long> bs(parser, "BYTES", "Block size", args::Matcher({"bs"}), 512); - args::ValueFlag<long> skip(parser, "BYTES", "Bytes to skip", args::Matcher({"skip"}), 0); - args::ValueFlag<std::string> input(parser, "BLOCK SIZE", "Block size", args::Matcher({"if"})); - args::ValueFlag<std::string> output(parser, "BLOCK SIZE", "Block size", args::Matcher({"of"})); + args::HelpFlag help(parser, "HELP", "Show this help menu.", {"help"}); + args::ValueFlag<long> bs(parser, "BYTES", "Block size", {"bs"}, 512); + args::ValueFlag<long> skip(parser, "BYTES", "Bytes to skip", {"skip"}, 0); + args::ValueFlag<std::string> input(parser, "BLOCK SIZE", "Block size", {"if"}); + args::ValueFlag<std::string> output(parser, "BLOCK SIZE", "Block size", {"of"}); parser.ParseArgs(std::vector<std::string>{"--skip=8", "--if=/dev/null"}); null << parser.Help(); parser.Help(null); @@ -315,7 +315,7 @@ TEST_CASE("Help menu can be grabbed as a string, passed into a stream, or by usi 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::ValueFlag<std::string> bar(parser, "BAR", "test flag", args::Matcher{'b', "bar"}); + args::ValueFlag<std::string> bar(parser, "BAR", "test flag", {'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"})); @@ -372,10 +372,10 @@ TEST_CASE("Mapping types work as needed", "[args]") {"yellow", MappingEnum::yellow}, {"green", MappingEnum::green}}; args::ArgumentParser parser("This is a test program.", "This goes after the options."); - args::MapFlag<std::string, MappingEnum> dmf(parser, "DMF", "Maps string to an enum", args::Matcher{"dmf"}, map); - args::MapFlag<std::string, MappingEnum> mf(parser, "MF", "Maps string to an enum", args::Matcher{"mf"}, map); - args::MapFlag<std::string, MappingEnum, ToLowerReader> cimf(parser, "CIMF", "Maps string to an enum case-insensitively", args::Matcher{"cimf"}, map); - args::MapFlagList<std::string, MappingEnum> mfl(parser, "MFL", "Maps string to an enum list", args::Matcher{"mfl"}, map); + args::MapFlag<std::string, MappingEnum> dmf(parser, "DMF", "Maps string to an enum", {"dmf"}, map); + args::MapFlag<std::string, MappingEnum> mf(parser, "MF", "Maps string to an enum", {"mf"}, map); + args::MapFlag<std::string, MappingEnum, ToLowerReader> cimf(parser, "CIMF", "Maps string to an enum case-insensitively", {"cimf"}, map); + args::MapFlagList<std::string, MappingEnum> mfl(parser, "MFL", "Maps string to an enum list", {"mfl"}, map); args::MapPositional<std::string, MappingEnum> mp(parser, "MP", "Maps string to an enum", map); args::MapPositionalList<std::string, MappingEnum> mpl(parser, "MPL", "Maps string to an enum list", map); parser.ParseArgs(std::vector<std::string>{"--mf=red", "--cimf=YeLLoW", "--mfl=bar", "foo", "--mfl=green", "red", "--mfl", "bar", "default"}); |