From cfe810e78efb8a570602606157d28d108f5f4b4b Mon Sep 17 00:00:00 2001 From: Pavel Belikov Date: Sat, 18 Nov 2017 10:53:22 +0300 Subject: fix ValueReader for types assignable to std::string --- test.cxx | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'test.cxx') 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::value, "StringAssignable must be assignable to std::string"); + + args::ArgumentParser p("parser"); + args::ValueFlag f(p, "name", "description", {'f'}); + args::ValueFlag b(p, "name", "description", {'b'}); + args::ValueFlag i(p, "name", "description", {'i'}); + + REQUIRE_NOTHROW(p.ParseArgs(std::vector{"-f", "a b"})); + REQUIRE(args::get(f) == "a b"); + + REQUIRE_NOTHROW(p.ParseArgs(std::vector{"-b", "a b"})); + REQUIRE(args::get(b).path == "a b"); + + REQUIRE_NOTHROW(p.ParseArgs(std::vector{"-i", "42 "})); + REQUIRE(args::get(i) == 42); + + REQUIRE_NOTHROW(p.ParseArgs(std::vector{"-i", " 12"})); + REQUIRE(args::get(i) == 12); +} + #undef ARGS_HXX #define ARGS_TESTNAMESPACE #define ARGS_NOEXCEPT -- cgit v1.2.1 From 184a6beb581448a84720ed6f74c6a04558e2aaa2 Mon Sep 17 00:00:00 2001 From: "Taylor C. Richberger" Date: Sun, 19 Nov 2017 14:09:05 -0700 Subject: Fix broken test I dropped a closing brace by mistake when merging --- test.cxx | 1 + 1 file changed, 1 insertion(+) (limited to 'test.cxx') diff --git a/test.cxx b/test.cxx index 46a7b4c..97d2c37 100644 --- a/test.cxx +++ b/test.cxx @@ -1097,6 +1097,7 @@ TEST_CASE("ValueParser works as expected", "[args]") REQUIRE_NOTHROW(p.ParseArgs(std::vector{"-i", " 12"})); REQUIRE(args::get(i) == 12); +} TEST_CASE("ActionFlag works as expected", "[args]") { -- cgit v1.2.1