aboutsummaryrefslogtreecommitdiff
path: root/test.cxx
diff options
context:
space:
mode:
authorTaylor C. Richberger <taywee@gmx.com>2017-11-19 09:49:53 -0700
committerGitHub <noreply@github.com>2017-11-19 09:49:53 -0700
commit431997da39a678b1aad0b85a5aacabd70120d513 (patch)
tree452b897a311e5d6f190ad33979ecdb00092fba55 /test.cxx
parentfix ValueReader for types assignable to std::string (diff)
parentMerge pull request #45 from pavel-belikov/readme (diff)
downloadargs.hxx-431997da39a678b1aad0b85a5aacabd70120d513.tar.xz
Merge branch 'master' into better-value-parsing
Diffstat (limited to 'test.cxx')
-rw-r--r--test.cxx21
1 files changed, 21 insertions, 0 deletions
diff --git a/test.cxx b/test.cxx
index c73c692..46a7b4c 100644
--- a/test.cxx
+++ b/test.cxx
@@ -1097,6 +1097,27 @@ TEST_CASE("ValueParser works as expected", "[args]")
REQUIRE_NOTHROW(p.ParseArgs(std::vector<std::string>{"-i", " 12"}));
REQUIRE(args::get(i) == 12);
+
+TEST_CASE("ActionFlag works as expected", "[args]")
+{
+ args::ArgumentParser p("parser");
+ std::string s;
+
+ args::ActionFlag action0(p, "name", "description", {'x'}, [&]() { s = "flag"; });
+ args::ActionFlag action1(p, "name", "description", {'y'}, [&](const std::string &arg) { s = arg; });
+ args::ActionFlag actionN(p, "name", "description", {'z'}, 2, [&](const std::vector<std::string> &arg) { s = arg[0] + arg[1]; });
+ args::ActionFlag actionThrow(p, "name", "description", {'v'}, [&]() { throw std::runtime_error(""); });
+
+ p.ParseArgs(std::vector<std::string>{"-x"});
+ REQUIRE(s == "flag");
+
+ p.ParseArgs(std::vector<std::string>{"-y", "a"});
+ REQUIRE(s == "a");
+
+ p.ParseArgs(std::vector<std::string>{"-z", "a", "b"});
+ REQUIRE(s == "ab");
+
+ REQUIRE_THROWS_AS(p.ParseArgs(std::vector<std::string>{"-v"}), std::runtime_error);
}
#undef ARGS_HXX