6 * Use, modification and distribution are subject to the
7 * Boost Software License, Version 1.0. (See accompanying file
8 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
13 * LOCATION: see http://www.boost.org for most recent version.
14 * FILE test_regex_replace.hpp
15 * VERSION see <boost/version.hpp>
16 * DESCRIPTION: Declares tests for regex search and replace.
19 #ifndef BOOST_REGEX_REGRESS_REGEX_REPLACE_HPP
20 #define BOOST_REGEX_REGRESS_REGEX_REPLACE_HPP
23 template<class charT, class traits>
24 void test_regex_replace(boost::basic_regex<charT, traits>& r)
26 typedef std::basic_string<charT> string_type;
27 const string_type& search_text = test_info<charT>::search_text();
28 boost::regex_constants::match_flag_type opts = test_info<charT>::match_options();
29 const string_type& format_string = test_info<charT>::format_string();
30 const string_type& result_string = test_info<charT>::result_string();
32 string_type result = boost::regex_replace(search_text, r, format_string, opts);
33 if(result != result_string)
35 BOOST_REGEX_TEST_ERROR("regex_replace generated an incorrect string result", charT);
40 struct test_regex_replace_tag{};
42 template<class charT, class traits>
43 void test(boost::basic_regex<charT, traits>& r, const test_regex_replace_tag&)
45 const std::basic_string<charT>& expression = test_info<charT>::expression();
46 boost::regex_constants::syntax_option_type syntax_options = test_info<charT>::syntax_options();
47 #ifndef BOOST_NO_EXCEPTIONS
51 r.assign(expression, syntax_options);
54 BOOST_REGEX_TEST_ERROR("Expression did not compile when it should have done, error code = " << r.status(), charT);
56 test_regex_replace(r);
58 #ifndef BOOST_NO_EXCEPTIONS
59 catch(const boost::bad_expression& e)
61 BOOST_REGEX_TEST_ERROR("Expression did not compile when it should have done: " << e.what(), charT);
63 catch(const std::runtime_error& e)
65 BOOST_REGEX_TEST_ERROR("Received an unexpected std::runtime_error: " << e.what(), charT);
67 catch(const std::exception& e)
69 BOOST_REGEX_TEST_ERROR("Received an unexpected std::exception: " << e.what(), charT);
73 BOOST_REGEX_TEST_ERROR("Received an unexpected exception of unknown type", charT);