From 2cb1ea69204781f73a58b9c86288079a7c787230 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Thu, 4 Feb 2016 23:05:41 +0100 Subject: [PATCH] devise a pipeline based variant of stringify() --- tests/library/format-helper-test.cpp | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/library/format-helper-test.cpp b/tests/library/format-helper-test.cpp index 13ec1fbb3..1b4075d8d 100644 --- a/tests/library/format-helper-test.cpp +++ b/tests/library/format-helper-test.cpp @@ -33,6 +33,7 @@ using lib::transformIterator; using lib::iter_stl::eachElm; +using lib::eachNum; using util::_Fmt; using std::vector; @@ -41,6 +42,14 @@ using std::to_string; namespace util { + template + inline lib::TransformIter + stringify (IT const& src) + { + using Val = typename IT::value_type; + + return transformIterator(src, util::toString); + } namespace test { namespace { // test fixture... @@ -95,6 +104,7 @@ namespace test { run (Arg) { check2String(); + checkStringify(); checkStringJoin(); checkPrefixSuffix(); } @@ -124,6 +134,28 @@ namespace test { } + /** @test inline to-string converter function + * - can be used as transforming iterator + * - alternatively accept arbitrary arguments + */ + void + checkStringify() + { + auto ss = stringify (eachNum (1.11, 10.2)); + + CHECK (ss); + CHECK ("1.11" == *ss); + ++ss; + CHECK ("2.11" == *ss); + + string res{".."}; + for (auto s : ss) + res += s; + + CHECK (res == "..2.113.114.115.116.117.118.119.1110.11"); + } + + /** @test verify delimiter separated joining of arbitrary collections. * - the first test uses a STL container, which means we need to wrap * into a lib::RangeIter. Moreover, lexical_cast is used to convert