|
Boost-Commit : |
From: eric_at_[hidden]
Date: 2008-03-16 19:06:27
Author: eric_niebler
Date: 2008-03-16 19:06:26 EDT (Sun, 16 Mar 2008)
New Revision: 43661
URL: http://svn.boost.org/trac/boost/changeset/43661
Log:
more tests for new regex_replace functionality
Text files modified:
trunk/libs/xpressive/test/misc2.cpp | 18 ++++++++++++++++++
trunk/libs/xpressive/test/test_non_char.cpp | 6 ++++++
2 files changed, 24 insertions(+), 0 deletions(-)
Modified: trunk/libs/xpressive/test/misc2.cpp
==============================================================================
--- trunk/libs/xpressive/test/misc2.cpp (original)
+++ trunk/libs/xpressive/test/misc2.cpp 2008-03-16 19:06:26 EDT (Sun, 16 Mar 2008)
@@ -5,6 +5,7 @@
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#include <map>
#include <string>
#include <boost/xpressive/xpressive.hpp>
#include <boost/xpressive/regex_actions.hpp>
@@ -56,6 +57,22 @@
BOOST_CHECK_EQUAL(result, "foo");
}
+///////////////////////////////////////////////////////////////////////////////
+//
+void test_replace_with_lambda()
+{
+ std::map<std::string, std::string> replacements;
+ replacements["X"] = "this";
+ replacements["Y"] = "that";
+
+ std::string input("\"$(X)\" has the value \"$(Y)\""), output;
+ std::string expected("\"this\" has the value \"that\"");
+ sregex rx = "$(" >> (s1= +~as_xpr(')')) >> ')';
+
+ output = regex_replace(input, rx, ref(replacements)[s1]);
+ BOOST_CHECK_EQUAL(output, expected);
+}
+
using namespace boost::unit_test;
///////////////////////////////////////////////////////////////////////////////
// init_unit_test_suite
@@ -67,6 +84,7 @@
test->add(BOOST_TEST_CASE(&test_complement));
test->add(BOOST_TEST_CASE(&test_static_actions_in_dynamic_keep));
test->add(BOOST_TEST_CASE(&test_static_actions_in_static_keep));
+ test->add(BOOST_TEST_CASE(&test_replace_with_lambda));
return test;
}
Modified: trunk/libs/xpressive/test/test_non_char.cpp
==============================================================================
--- trunk/libs/xpressive/test/test_non_char.cpp (original)
+++ trunk/libs/xpressive/test/test_non_char.cpp 2008-03-16 19:06:26 EDT (Sun, 16 Mar 2008)
@@ -80,6 +80,12 @@
BOOST_CHECK_EQUAL(3, what.position());
BOOST_CHECK_EQUAL(3, what.length());
}
+
+ // test for range-based regex_replace
+ std::vector<UChar> output = regex_replace(str, urx, pattern_);
+ std::string output_(output.begin(), output.end());
+ std::string expected("foob.*rboo");
+ BOOST_CHECK_EQUAL(output_, expected);
}
///////////////////////////////////////////////////////////////////////////////
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk