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_not_regex.hpp
15 * VERSION see <boost/version.hpp>
16 * DESCRIPTION: Declares tests for invalid regexes.
20 #ifndef BOOST_REGEX_REGRESS_TEST_NOT_REGEX_HPP
21 #define BOOST_REGEX_REGRESS_TEST_NOT_REGEX_HPP
24 // this file implements a test for a regular expression that should not compile:
26 struct test_invalid_regex_tag{};
28 template<class charT, class traits>
29 void test_empty(boost::basic_regex<charT, traits>& r)
33 BOOST_REGEX_TEST_ERROR("Invalid value returned from basic_regex<>::empty().", charT);
37 BOOST_REGEX_TEST_ERROR("Invalid value returned from basic_regex<>::size().", charT);
41 BOOST_REGEX_TEST_ERROR("Invalid value returned from basic_regex<>::str().", charT);
43 if(r.begin() != r.end())
45 BOOST_REGEX_TEST_ERROR("Invalid value returned from basic_regex<>::begin().", charT);
49 BOOST_REGEX_TEST_ERROR("Invalid value returned from basic_regex<>::status().", charT);
51 if(r.begin() != r.end())
53 BOOST_REGEX_TEST_ERROR("Invalid value returned from basic_regex<>::begin().", charT);
57 template<class charT, class traits>
58 void test(boost::basic_regex<charT, traits>& r, const test_invalid_regex_tag&)
60 const std::basic_string<charT>& expression = test_info<charT>::expression();
61 boost::regex_constants::syntax_option_type syntax_options = test_info<charT>::syntax_options();
63 // try it with exceptions disabled first:
65 #ifndef BOOST_NO_EXCEPTIONS
69 if(0 == r.assign(expression, syntax_options | boost::regex_constants::no_except).status())
71 BOOST_REGEX_TEST_ERROR("Expression compiled when it should not have done so.", charT);
75 #ifndef BOOST_NO_EXCEPTIONS
78 BOOST_REGEX_TEST_ERROR("Unexpected exception thrown.", charT);
82 // now try again with exceptions:
84 bool have_catch = false;
85 #ifndef BOOST_NO_EXCEPTIONS
89 r.assign(expression, syntax_options);
90 #ifdef BOOST_NO_EXCEPTIONS
95 #ifndef BOOST_NO_EXCEPTIONS
96 catch(const boost::bad_expression&)
101 catch(const std::runtime_error& e)
104 BOOST_REGEX_TEST_ERROR("Expected a bad_expression exception, but a std::runtime_error instead: " << e.what(), charT);
106 catch(const std::exception& e)
109 BOOST_REGEX_TEST_ERROR("Expected a bad_expression exception, but a std::exception instead: " << e.what(), charT);
114 BOOST_REGEX_TEST_ERROR("Expected a bad_expression exception, but got an exception of unknown type instead", charT);
119 // oops expected exception was not thrown:
120 BOOST_REGEX_TEST_ERROR("Expected an exception, but didn't find one.", charT);