]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/regex/test/regress/test_regex_replace.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / regex / test / regress / test_regex_replace.hpp
1 /*
2 *
3 * Copyright (c) 2004
4 * John Maddock
5 *
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)
9 *
10 */
11
12 /*
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.
17 */
18
19 #ifndef BOOST_REGEX_REGRESS_REGEX_REPLACE_HPP
20 #define BOOST_REGEX_REGRESS_REGEX_REPLACE_HPP
21 #include "info.hpp"
22
23 template<class charT, class traits>
24 void test_regex_replace(boost::basic_regex<charT, traits>& r)
25 {
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();
31
32 string_type result = boost::regex_replace(search_text, r, format_string, opts);
33 if(result != result_string)
34 {
35 BOOST_REGEX_TEST_ERROR("regex_replace generated an incorrect string result", charT);
36 }
37 }
38
39
40 struct test_regex_replace_tag{};
41
42 template<class charT, class traits>
43 void test(boost::basic_regex<charT, traits>& r, const test_regex_replace_tag&)
44 {
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
48 try
49 #endif
50 {
51 r.assign(expression, syntax_options);
52 if(r.status())
53 {
54 BOOST_REGEX_TEST_ERROR("Expression did not compile when it should have done, error code = " << r.status(), charT);
55 }
56 test_regex_replace(r);
57 }
58 #ifndef BOOST_NO_EXCEPTIONS
59 catch(const boost::bad_expression& e)
60 {
61 BOOST_REGEX_TEST_ERROR("Expression did not compile when it should have done: " << e.what(), charT);
62 }
63 catch(const std::runtime_error& e)
64 {
65 BOOST_REGEX_TEST_ERROR("Received an unexpected std::runtime_error: " << e.what(), charT);
66 }
67 catch(const std::exception& e)
68 {
69 BOOST_REGEX_TEST_ERROR("Received an unexpected std::exception: " << e.what(), charT);
70 }
71 catch(...)
72 {
73 BOOST_REGEX_TEST_ERROR("Received an unexpected exception of unknown type", charT);
74 }
75 #endif
76
77 }
78
79 #endif
80