From 60ba26118dd8886749229235fc92aec01b7d7ca1 Mon Sep 17 00:00:00 2001 From: "Taylor C. Richberger" Date: Thu, 2 Jun 2016 16:28:41 -0600 Subject: improve readability by culling explicit matcher construction --- test.cxx | 118 +++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 59 insertions(+), 59 deletions(-) (limited to 'test.cxx') diff --git a/test.cxx b/test.cxx index b28a378..7822821 100644 --- a/test.cxx +++ b/test.cxx @@ -21,7 +21,7 @@ std::istream& operator>>(std::istream& is, std::tuple& 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{})); REQUIRE_THROWS_AS(parser.ParseArgs(std::vector{"--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{})); REQUIRE_THROWS_AS(parser.ParseArgs(std::vector{"--Help"}), args::ParseError); REQUIRE_THROWS_AS(parser.ParseArgs(std::vector{"-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{"--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{"--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 foo(parser, "FOO", "test flag", args::Matcher{'f', "foo"}); - args::Flag bar(parser, "BAR", "test flag", args::Matcher{'b', "bar"}); - args::ValueFlag baz(parser, "BAZ", "test flag", args::Matcher{'a', "baz"}); - args::ValueFlag bim(parser, "BAZ", "test flag", args::Matcher{'B', "bim"}); - args::Flag bix(parser, "BAZ", "test flag", args::Matcher{'x', "bix"}); + args::ValueFlag foo(parser, "FOO", "test flag", {'f', "foo"}); + args::Flag bar(parser, "BAR", "test flag", {'b', "bar"}); + args::ValueFlag baz(parser, "BAZ", "test flag", {'a', "baz"}); + args::ValueFlag bim(parser, "BAZ", "test flag", {'B', "bim"}); + args::Flag bix(parser, "BAZ", "test flag", {'x', "bix"}); parser.ParseArgs(std::vector{"-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{"--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 foo(parser, "FOO", "test flag", args::Matcher{'f', "foo"}); - args::Flag bar(parser, "BAR", "test flag", args::Matcher{"bar", 'b'}); - args::ValueFlag baz(parser, "BAZ", "test flag", args::Matcher{'a', "baz"}); - args::ValueFlag bim(parser, "BAZ", "test flag", args::Matcher{'B', "bim"}); - args::Flag bix(parser, "BAZ", "test flag", args::Matcher{"bix"}); + args::ValueFlag foo(parser, "FOO", "test flag", {'f', "foo"}); + args::Flag bar(parser, "BAR", "test flag", {"bar", 'b'}); + args::ValueFlag baz(parser, "BAZ", "test flag", {'a', "baz"}); + args::ValueFlag bim(parser, "BAZ", "test flag", {'B', "bim"}); + args::Flag bix(parser, "BAZ", "test flag", {"bix"}); parser.ParseArgs(std::vector{"-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 foo(parser, "FOO", "test flag", args::Matcher{'f', "foo"}); + args::ValueFlag foo(parser, "FOO", "test flag", {'f', "foo"}); parser.ParseArgs(std::vector{"--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 foo(parser, "FOO", "test flag", args::Matcher{'f', "foo"}); + args::ValueFlag foo(parser, "FOO", "test flag", {'f', "foo"}); REQUIRE_THROWS_AS(parser.ParseArgs(std::vector{"--foo=7.5"}), args::ParseError); REQUIRE_THROWS_AS(parser.ParseArgs(std::vector{"--foo", "7a"}), args::ParseError); REQUIRE_THROWS_AS(parser.ParseArgs(std::vector{"--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 foo(parser, "FOO", "test flag", args::Matcher{'f', "foo"}); + args::ValueFlagList foo(parser, "FOO", "test flag", {'f', "foo"}); parser.ParseArgs(std::vector{"--foo=7", "-f2", "-f", "9", "--foo", "42"}); REQUIRE((args::get(foo) == std::vector{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{"-a"}), args::ValidationError); REQUIRE_NOTHROW(parser.ParseArgs(std::vector{"-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{})); REQUIRE_NOTHROW(parser.ParseArgs(std::vector{"-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 bs(parser, "BYTES", "Block size", args::Matcher({"bs"}), 512); - args::ValueFlag skip(parser, "BYTES", "Bytes to skip", args::Matcher({"skip"}), 0); - args::ValueFlag input(parser, "BLOCK SIZE", "Block size", args::Matcher({"if"})); - args::ValueFlag output(parser, "BLOCK SIZE", "Block size", args::Matcher({"of"})); + args::HelpFlag help(parser, "HELP", "Show this help menu.", {"help"}); + args::ValueFlag bs(parser, "BYTES", "Block size", {"bs"}, 512); + args::ValueFlag skip(parser, "BYTES", "Bytes to skip", {"skip"}, 0); + args::ValueFlag input(parser, "BLOCK SIZE", "Block size", {"if"}); + args::ValueFlag output(parser, "BLOCK SIZE", "Block size", {"of"}); parser.ParseArgs(std::vector{"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 bs(parser, "BYTES", "Block size", args::Matcher({"bs"}), 512); - args::ValueFlag skip(parser, "BYTES", "Bytes to skip", args::Matcher({"skip"}), 0); - args::ValueFlag input(parser, "BLOCK SIZE", "Block size", args::Matcher({"if"})); - args::ValueFlag output(parser, "BLOCK SIZE", "Block size", args::Matcher({"of"})); + args::HelpFlag help(parser, "HELP", "Show this help menu.", {"help"}); + args::ValueFlag bs(parser, "BYTES", "Block size", {"bs"}, 512); + args::ValueFlag skip(parser, "BYTES", "Bytes to skip", {"skip"}, 0); + args::ValueFlag input(parser, "BLOCK SIZE", "Block size", {"if"}); + args::ValueFlag output(parser, "BLOCK SIZE", "Block size", {"of"}); parser.ParseArgs(std::vector{"/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 bs(parser, "BYTES", "Block size", args::Matcher({"bs"}), 512); - args::ValueFlag skip(parser, "BYTES", "Bytes to skip", args::Matcher({"skip"}), 0); - args::ValueFlag input(parser, "BLOCK SIZE", "Block size", args::Matcher({"if"})); - args::ValueFlag output(parser, "BLOCK SIZE", "Block size", args::Matcher({"of"})); + args::HelpFlag help(parser, "HELP", "Show this help menu.", {"help"}); + args::ValueFlag bs(parser, "BYTES", "Block size", {"bs"}, 512); + args::ValueFlag skip(parser, "BYTES", "Bytes to skip", {"skip"}, 0); + args::ValueFlag input(parser, "BLOCK SIZE", "Block size", {"if"}); + args::ValueFlag output(parser, "BLOCK SIZE", "Block size", {"of"}); parser.ParseArgs(std::vector{"--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 bar(parser, "BAR", "test flag", args::Matcher{'b', "bar"}); + args::ValueFlag bar(parser, "BAR", "test flag", {'b', "bar"}); REQUIRE_NOTHROW(parser.ParseArgs(std::vector{"-btest"})); REQUIRE_NOTHROW(parser.ParseArgs(std::vector{"--bar=test"})); REQUIRE_NOTHROW(parser.ParseArgs(std::vector{"-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 dmf(parser, "DMF", "Maps string to an enum", args::Matcher{"dmf"}, map); - args::MapFlag mf(parser, "MF", "Maps string to an enum", args::Matcher{"mf"}, map); - args::MapFlag cimf(parser, "CIMF", "Maps string to an enum case-insensitively", args::Matcher{"cimf"}, map); - args::MapFlagList mfl(parser, "MFL", "Maps string to an enum list", args::Matcher{"mfl"}, map); + args::MapFlag dmf(parser, "DMF", "Maps string to an enum", {"dmf"}, map); + args::MapFlag mf(parser, "MF", "Maps string to an enum", {"mf"}, map); + args::MapFlag cimf(parser, "CIMF", "Maps string to an enum case-insensitively", {"cimf"}, map); + args::MapFlagList mfl(parser, "MFL", "Maps string to an enum list", {"mfl"}, map); args::MapPositional mp(parser, "MP", "Maps string to an enum", map); args::MapPositionalList mpl(parser, "MPL", "Maps string to an enum list", map); parser.ParseArgs(std::vector{"--mf=red", "--cimf=YeLLoW", "--mfl=bar", "foo", "--mfl=green", "red", "--mfl", "bar", "default"}); -- cgit v1.2.1