aboutsummaryrefslogtreecommitdiff
path: root/test.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'test.cxx')
-rw-r--r--test.cxx35
1 files changed, 27 insertions, 8 deletions
diff --git a/test.cxx b/test.cxx
index 3ad5533..84cd6ce 100644
--- a/test.cxx
+++ b/test.cxx
@@ -4,6 +4,14 @@
#include <iostream>
+std::istream& operator>>(std::istream& is, std::tuple<int, int>& ints)
+{
+ is >> std::get<0>(ints);
+ is.get();
+ is >> std::get<1>(ints);
+ return is;
+}
+
#include <args.hxx>
#define CATCH_CONFIG_MAIN
@@ -59,6 +67,25 @@ TEST_CASE("Argument flags work as expected, with clustering", "[args]")
REQUIRE_FALSE(bix);
}
+TEST_CASE("Unified argument lists for match work", "[args]")
+{
+ args::ArgumentParser parser("This is a test program.", "This goes after the options.");
+ args::ArgFlag<std::string> foo(parser, "FOO", "test flag", args::Matcher{'f', "foo"});
+ args::Flag bar(parser, "BAR", "test flag", args::Matcher{"bar", 'b'});
+ args::ArgFlag<double> baz(parser, "BAZ", "test flag", args::Matcher{'a', "baz"});
+ args::ArgFlag<char> bim(parser, "BAZ", "test flag", args::Matcher{'B', "bim"});
+ args::Flag bix(parser, "BAZ", "test flag", args::Matcher{"bix"});
+ parser.ParseArgs(std::vector<std::string>{"-bftest", "--baz=7.555e2", "--bim", "c"});
+ REQUIRE(foo);
+ REQUIRE(foo.value == "test");
+ REQUIRE(bar);
+ REQUIRE(baz);
+ REQUIRE((baz.value > 755.49 && baz.value < 755.51));
+ REQUIRE(bim);
+ REQUIRE(bim.value == 'c');
+ REQUIRE_FALSE(bix);
+}
+
TEST_CASE("Invalid argument parsing throws parsing exceptions", "[args]")
{
args::ArgumentParser parser("This is a test program.", "This goes after the options.");
@@ -173,14 +200,6 @@ TEST_CASE("Argument groups should nest", "[args]")
#include <tuple>
-std::istream& operator>>(std::istream& is, std::tuple<int, int>& ints)
-{
- is >> std::get<0>(ints);
- is.get();
- is >> std::get<1>(ints);
- return is;
-}
-
void DoublesReader(const std::string &name, const std::string &value, std::tuple<double, double> &destination)
{
size_t commapos = 0;