aboutsummaryrefslogtreecommitdiff
path: root/test.cxx
diff options
context:
space:
mode:
authorPavel Belikov <pavel.fuchs.belikov@gmail.com>2017-11-18 10:53:22 +0300
committerPavel Belikov <pavel.fuchs.belikov@gmail.com>2017-11-18 10:53:22 +0300
commitcfe810e78efb8a570602606157d28d108f5f4b4b (patch)
tree36dde274b84cf07b44bcc85388651c82d55e7bff /test.cxx
parentMerge pull request #43 from pavel-belikov/better-help (diff)
downloadargs.hxx-cfe810e78efb8a570602606157d28d108f5f4b4b.tar.xz
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 1189f97..c73c692 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);
+}
+
#undef ARGS_HXX
#define ARGS_TESTNAMESPACE
#define ARGS_NOEXCEPT