forked from boostorg/regex
55 lines
1.7 KiB
C++
55 lines
1.7 KiB
C++
|
|
#ifndef BOOST_REGEX_REGRESS_REGEX_REPLACE_HPP
|
|
#define BOOST_REGEX_REGRESS_REGEX_REPLACE_HPP
|
|
#include "info.hpp"
|
|
|
|
template<class charT, class traits>
|
|
void test_regex_replace(boost::basic_regex<charT, traits>& r)
|
|
{
|
|
typedef std::basic_string<charT> string_type;
|
|
const string_type& search_text = test_info<charT>::search_text();
|
|
boost::regex_constants::match_flag_type opts = test_info<charT>::match_options();
|
|
const string_type& format_string = test_info<charT>::format_string();
|
|
const string_type& result_string = test_info<charT>::result_string();
|
|
|
|
string_type result = boost::regex_replace(search_text, r, format_string, opts);
|
|
if(result != result_string)
|
|
{
|
|
BOOST_REGEX_TEST_ERROR("regex_replace generated an incorrect string result", charT);
|
|
}
|
|
}
|
|
|
|
|
|
struct test_regex_replace_tag{};
|
|
|
|
template<class charT, class traits>
|
|
void test(boost::basic_regex<charT, traits>& r, const test_regex_replace_tag&)
|
|
{
|
|
const std::basic_string<charT>& expression = test_info<charT>::expression();
|
|
boost::regex_constants::syntax_option_type syntax_options = test_info<charT>::syntax_options();
|
|
try{
|
|
r.assign(expression, syntax_options);
|
|
test_regex_replace(r);
|
|
}
|
|
catch(const boost::bad_expression& e)
|
|
{
|
|
BOOST_REGEX_TEST_ERROR("Expression did not compile when it should have done: " << e.what(), charT);
|
|
}
|
|
catch(const std::runtime_error& r)
|
|
{
|
|
BOOST_REGEX_TEST_ERROR("Received an unexpected std::runtime_error: " << r.what(), charT);
|
|
}
|
|
catch(const std::exception& r)
|
|
{
|
|
BOOST_REGEX_TEST_ERROR("Received an unexpected std::exception: " << r.what(), charT);
|
|
}
|
|
catch(...)
|
|
{
|
|
BOOST_REGEX_TEST_ERROR("Received an unexpected exception of unknown type", charT);
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|