1 ///////////////////////////////////////////////////////////////////////////////
4 // Copyright 2008 Eric Niebler. Distributed under the Boost
5 // Software License, Version 1.0. (See accompanying file
6 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 #ifndef BOOST_XPRESSIVE_TEST_TEST_HPP_EAN_10_04_2005
9 #define BOOST_XPRESSIVE_TEST_TEST_HPP_EAN_10_04_2005
11 // MS compatible compilers support #pragma once
21 #include <boost/range/iterator_range.hpp>
22 #include <boost/xpressive/xpressive_static.hpp>
23 #include <boost/test/unit_test.hpp>
25 using namespace boost::unit_test;
26 using namespace boost::xpressive;
28 #define L(x) BOOST_XPR_CSTR_(char_type, x)
30 #define BOOST_XPR_CHECK(pred) \
31 if( pred ) {} else { BOOST_ERROR( this->section_ << " : " << #pred ); }
33 using namespace boost::xpressive;
35 ///////////////////////////////////////////////////////////////////////////////
38 #if defined(__cplusplus_cli)
39 #pragma managed(push, off)
41 template<typename Char>
42 inline std::vector<std::basic_string<Char> > backrefs(Char const *br0, ...)
45 std::vector<std::basic_string<Char> > backrefs;
48 backrefs.push_back(br0);
52 while(0 != (brN = va_arg(va, Char const *)))
54 backrefs.push_back(brN);
60 #if defined(__cplusplus_cli)
64 ///////////////////////////////////////////////////////////////////////////////
67 no_match_t const no_match = {};
69 ///////////////////////////////////////////////////////////////////////////////
72 template<typename BidiIter>
75 typedef BidiIter iterator_type;
76 typedef typename boost::iterator_value<iterator_type>::type char_type;
77 typedef basic_regex<iterator_type> regex_type;
78 typedef std::basic_string<char_type> string_type;
79 typedef std::vector<string_type> backrefs_type;
81 xpr_test_case(std::string section, string_type str, regex_type rex, backrefs_type brs)
89 xpr_test_case(std::string section, string_type str, regex_type rex, no_match_t)
99 char_type const empty[] = {0};
100 match_results<BidiIter> what;
101 if(regex_search(this->str_, what, this->rex_))
103 // match succeeded: was it expected to succeed?
104 BOOST_XPR_CHECK(what.size() == this->brs_.size());
106 for(std::size_t i = 0; i < what.size() && i < this->brs_.size(); ++i)
108 BOOST_XPR_CHECK((!what[i].matched && this->brs_[i] == empty) || this->brs_[i] == what[i].str());
113 // match failed: was it expected to fail?
114 BOOST_XPR_CHECK(0 == this->brs_.size());
120 std::string section_;
123 std::vector<string_type> brs_;
126 ///////////////////////////////////////////////////////////////////////////////
128 template<typename BidiIter>
131 typedef xpr_test_case<BidiIter> argument_type;
132 typedef void result_type;
134 void operator ()(xpr_test_case<BidiIter> const &test) const
140 ///////////////////////////////////////////////////////////////////////////////
141 // helpful debug routines
142 ///////////////////////////////////////////////////////////////////////////////
144 ///////////////////////////////////////////////////////////////////////////////
145 // remove all occurances of sz from str
146 inline void string_remove(std::string &str, char const *sz)
148 std::string::size_type i = 0, n = std::strlen(sz);
149 while(std::string::npos != (i=str.find(sz,i)))
155 ///////////////////////////////////////////////////////////////////////////////
157 // for type T, write typeid::name after performing some substitutions
159 inline void display_type2()
161 std::string str = typeid(T).name();
163 string_remove(str, "struct ");
164 string_remove(str, "boost::");
165 string_remove(str, "xpressive::");
166 string_remove(str, "detail::");
167 string_remove(str, "fusion::");
169 //std::printf("%s\n\n", str.c_str());
170 std::printf("%s\nwdith=%d\nuse_simple_repeat=%s\n\n", str.c_str()
171 , detail::width_of<T, char>::value
172 , detail::use_simple_repeat<T, char>::value ? "true" : "false");
175 ///////////////////////////////////////////////////////////////////////////////
177 // display the type of the deduced template argument
179 inline void display_type(T const &)