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
12
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
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>
130
: std::unary_function<xpr_test_case<BidiIter>, void>
132
void operator ()(xpr_test_case<BidiIter> const &test) const
138
///////////////////////////////////////////////////////////////////////////////
139
// helpful debug routines
140
///////////////////////////////////////////////////////////////////////////////
142
///////////////////////////////////////////////////////////////////////////////
143
// remove all occurances of sz from str
144
inline void string_remove(std::string &str, char const *sz)
146
std::string::size_type i = 0, n = std::strlen(sz);
147
while(std::string::npos != (i=str.find(sz,i)))
153
///////////////////////////////////////////////////////////////////////////////
155
// for type T, write typeid::name after performing some substitutions
157
inline void display_type2()
159
std::string str = typeid(T).name();
161
string_remove(str, "struct ");
162
string_remove(str, "boost::");
163
string_remove(str, "xpressive::");
164
string_remove(str, "detail::");
165
string_remove(str, "fusion::");
167
//std::printf("%s\n\n", str.c_str());
168
std::printf("%s\nwdith=%d\nuse_simple_repeat=%s\n\n", str.c_str()
169
, detail::width_of<T, char>::value
170
, detail::use_simple_repeat<T, char>::value ? "true" : "false");
173
///////////////////////////////////////////////////////////////////////////////
175
// display the type of the deduced template argument
177
inline void display_type(T const &)