From 5408a17020ba7d7467288ce59f820a07ae890142 Mon Sep 17 00:00:00 2001 From: Ben10do Date: Wed, 1 Aug 2018 22:42:18 +0100 Subject: [PATCH] Add tests with lvalue inputs If the compiler supports forwarding references, we now test if lvalues can be used as input strings for split(), find_all(), and ifind_all(). Note that MSVC (without its recent /permissive- flag) may pass these tests without the forwarding references changes that I made, due to its non-standard binding of lvalues to rvalues. --- string/test/split_test.cpp | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/string/test/split_test.cpp b/string/test/split_test.cpp index 582472b..d7e9186 100644 --- a/string/test/split_test.cpp +++ b/string/test/split_test.cpp @@ -7,6 +7,8 @@ // See http://www.boost.org for updates, documentation, and revision history. +#include + #include #include // equals predicate is used for result comparison @@ -82,6 +84,28 @@ void iterator_test() string("xx") ); deep_compare( tokens, vtokens ); +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + // If using a compiler that supports forwarding references, we should be able to use lvalues, too + find_all( + tokens, + string("xx-abc--xx-abb"), + "xx" ); + + BOOST_REQUIRE( tokens.size()==2 ); + BOOST_CHECK( tokens[0]==string("xx") ); + BOOST_CHECK( tokens[1]==string("xx") ); + + ifind_all( + tokens, + string("Xx-abc--xX-abb-xx"), + "xx" ); + + BOOST_REQUIRE( tokens.size()==3 ); + BOOST_CHECK( tokens[0]==string("Xx") ); + BOOST_CHECK( tokens[1]==string("xX") ); + BOOST_CHECK( tokens[2]==string("xx") ); +#endif + // split tests split( tokens, @@ -144,6 +168,21 @@ void iterator_test() BOOST_REQUIRE( tokens.size()==1 ); BOOST_CHECK( tokens[0]==string("") ); +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + // If using a compiler that supports forwarding references, we should be able to use lvalues, too + split( + tokens, + string("Xx-abc--xX-abb-xx"), + is_any_of("xX"), + token_compress_on ); + + BOOST_REQUIRE( tokens.size()==4 ); + BOOST_CHECK( tokens[0]==string("") ); + BOOST_CHECK( tokens[1]==string("-abc--") ); + BOOST_CHECK( tokens[2]==string("-abb-") ); + BOOST_CHECK( tokens[3]==string("") ); +#endif + find_iterator fiter=make_find_iterator(str1, first_finder("xx")); find_iterator fiter2;