aboutsummaryrefslogtreecommitdiff
path: root/test.cxx
diff options
context:
space:
mode:
authorTaylor C. Richberger <taywee@gmx.com>2017-11-19 14:47:12 -0700
committerGitHub <noreply@github.com>2017-11-19 14:47:12 -0700
commitcd260c9694c212a2c95f173f69a0c7b1b3cda89a (patch)
treebf1f9025ee294a11c79f5395a62a2a1ab3714162 /test.cxx
parentMerge pull request #46 from pavel-belikov/additional-flag-description (diff)
parentFix broken test (diff)
downloadargs.hxx-cd260c9694c212a2c95f173f69a0c7b1b3cda89a.tar.xz
Merge pull request #44 from pavel-belikov/better-value-parsing
Fix ValueReader for types assignable to std::string
Diffstat (limited to 'test.cxx')
-rw-r--r--test.cxx33
1 files changed, 33 insertions, 0 deletions
diff --git a/test.cxx b/test.cxx
index a8d1676..897dcf3 100644
--- a/test.cxx
+++ b/test.cxx
@@ -1066,6 +1066,39 @@ TEST_CASE("HelpParams work as expected", "[args]")
}
+struct StringAssignable
+{
+public:
+ StringAssignable() = default;
+ StringAssignable(const std::string &p) : path(p) {}
+ std::string path;
+
+ friend std::istream &operator >> (std::istream &s, StringAssignable &a)
+ { return s >> a.path; }
+};
+
+TEST_CASE("ValueParser works as expected", "[args]")
+{
+ static_assert(std::is_assignable<StringAssignable, std::string>::value, "StringAssignable must be assignable to std::string");
+
+ args::ArgumentParser p("parser");
+ args::ValueFlag<std::string> f(p, "name", "description", {'f'});
+ args::ValueFlag<StringAssignable> b(p, "name", "description", {'b'});
+ args::ValueFlag<int> i(p, "name", "description", {'i'});
+
+ REQUIRE_NOTHROW(p.ParseArgs(std::vector<std::string>{"-f", "a b"}));
+ REQUIRE(args::get(f) == "a b");
+
+ REQUIRE_NOTHROW(p.ParseArgs(std::vector<std::string>{"-b", "a b"}));
+ REQUIRE(args::get(b).path == "a b");
+
+ REQUIRE_NOTHROW(p.ParseArgs(std::vector<std::string>{"-i", "42 "}));
+ REQUIRE(args::get(i) == 42);
+
+ 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");