diff options
Diffstat (limited to 'src/boost/libs/xpressive/test')
70 files changed, 9044 insertions, 0 deletions
diff --git a/src/boost/libs/xpressive/test/Jamfile.v2 b/src/boost/libs/xpressive/test/Jamfile.v2 new file mode 100644 index 00000000..c3652e1b --- /dev/null +++ b/src/boost/libs/xpressive/test/Jamfile.v2 @@ -0,0 +1,84 @@ +# (C) Copyright 2004: Eric Niebler +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +# bring in rules for testing +import testing ; + +project + : requirements + <toolset>intel:<debug-symbols>off + # Turn off debug symbols on MSVC to bring down the size of object files + <toolset>msvc:<debug-symbols>off + <toolset>msvc-8.0:<define>_SCL_SECURE_NO_DEPRECATE + <toolset>msvc-8.0:<define>_CRT_SECURE_NO_DEPRECATE + <toolset>msvc-9.0:<define>_SCL_SECURE_NO_DEPRECATE + <toolset>msvc-10.0:<define>_SCL_SECURE_NO_WARNINGS + <toolset>msvc-11.0:<define>_SCL_SECURE_NO_DEPRECATE + <toolset>msvc-11.0:<define>_SCL_SECURE_NO_WARNINGS + <toolset>gcc:<cxxflags>-ftemplate-depth-1024 + <toolset>darwin:<cxxflags>-ftemplate-depth-1024 +# <toolset>gcc:<cxxflags>-W +# <toolset>gcc:<cxxflags>-Wall +# <toolset>msvc:<cxxflags>-W4 + <toolset>msvc,<stdlib>stlport:<define>_STLP_EXPOSE_GLOBALS_IMPLEMENTATION + <library>/boost/test//boost_unit_test_framework + <link>static + ; + +test-suite "xpressive" + : [ run regress.cpp : : regress.txt : <toolset>msvc:<cxxflags>/bigobj ] + [ run regress_u.cpp : : regress.txt : <toolset>msvc:<cxxflags>/bigobj ] + [ run c_traits.cpp : : regress.txt : <toolset>msvc:<cxxflags>/bigobj ] + [ run c_traits_u.cpp : : regress.txt : <toolset>msvc:<cxxflags>/bigobj ] + [ run test1.cpp ] + [ run test2.cpp ] + [ run test3.cpp ] + [ run test4.cpp ] + [ run test5.cpp ] + [ run test6.cpp ] + [ run test7.cpp ] + [ run test8.cpp ] + [ run test9.cpp ] + [ run test10.cpp ] + [ run test11.cpp ] + [ run test1u.cpp ] + [ run test2u.cpp ] + [ run test3u.cpp ] + [ run test4u.cpp ] + [ run test5u.cpp ] + [ run test6u.cpp ] + [ run test7u.cpp ] + [ run test8u.cpp ] + [ run test9u.cpp ] + [ run test10u.cpp ] + [ run test11u.cpp ] + [ run misc1.cpp ] + [ run misc2.cpp ] + [ run test_format.cpp ] + [ run test_cycles.cpp ] + [ run test_non_char.cpp ] + [ run test_static.cpp ] + [ run test_actions.cpp ] + [ run test_assert.cpp ] + [ run test_assert_with_placeholder.cpp ] + [ run test_symbols.cpp ] + [ run test_dynamic.cpp ] + [ run test_dynamic_grammar.cpp ] + [ run test_skip.cpp ] + [ link multiple_defs1.cpp multiple_defs2.cpp : : multiple_defs ] + [ compile test_basic_regex.cpp ] + [ compile test_match_results.cpp ] + [ compile test_regex_algorithms.cpp ] + [ compile test_regex_compiler.cpp ] + [ compile test_regex_constants.cpp ] + [ compile test_regex_error.cpp ] + [ compile test_regex_iterator.cpp ] + [ compile test_regex_primitives.cpp ] + [ compile test_regex_token_iterator.cpp ] + [ compile test_regex_traits.cpp ] + [ compile test_sub_match.cpp ] +# [ compile test_typeof.cpp ] +# [ compile test_typeof2.cpp ] + ; + diff --git a/src/boost/libs/xpressive/test/c_traits.cpp b/src/boost/libs/xpressive/test/c_traits.cpp new file mode 100644 index 00000000..6e8ad48c --- /dev/null +++ b/src/boost/libs/xpressive/test/c_traits.cpp @@ -0,0 +1,16 @@ +////////////////////////////////////////////////////////////////////////////// +// c_traits.cpp +// +// (C) Copyright Eric Niebler 2004. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +/* + Revision history: + 6 January 2006 : Initial version. +*/ + +#define BOOST_XPRESSIVE_USE_C_TRAITS +#include "./regress.ipp" + diff --git a/src/boost/libs/xpressive/test/c_traits_u.cpp b/src/boost/libs/xpressive/test/c_traits_u.cpp new file mode 100644 index 00000000..77c9d9f3 --- /dev/null +++ b/src/boost/libs/xpressive/test/c_traits_u.cpp @@ -0,0 +1,17 @@ +////////////////////////////////////////////////////////////////////////////// +// c_traits.cpp +// +// (C) Copyright Eric Niebler 2004. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +/* + Revision history: + 6 January 2006 : Initial version. +*/ + +#define BOOST_XPRESSIVE_USE_C_TRAITS +#define BOOST_XPRESSIVE_TEST_WREGEX +#include "./regress.ipp" + diff --git a/src/boost/libs/xpressive/test/misc1.cpp b/src/boost/libs/xpressive/test/misc1.cpp new file mode 100644 index 00000000..9bcd63b1 --- /dev/null +++ b/src/boost/libs/xpressive/test/misc1.cpp @@ -0,0 +1,252 @@ +/////////////////////////////////////////////////////////////////////////////// +// misc1.hpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <iostream> +#include <boost/xpressive/xpressive.hpp> +#include <boost/xpressive/traits/cpp_regex_traits.hpp> +#include <boost/test/unit_test.hpp> + +using namespace boost::unit_test; +using namespace boost::xpressive; + +void test1() +{ + // make sure the following compiles: + sregex a = _; + sregex b = _; + sregex c = a >> b; + c = 'a' >> b; + c = a >> 'b'; + c = a | b; + c = 'a' | b; + c = a | 'b'; + c = !a; + c = *a; + c = +a; +} + +/////////////////////////////////////////////////////////////////////////////// +// test for basic_regex in a keep +// +void test2() +{ + std::locale loc; + std::string str("Its a mad Mad mAd maD world"); + sregex word = +_w; + sregex sentence = imbue(loc)(*(keep(word) >> +_s) >> word); + smatch what; + + BOOST_REQUIRE(regex_match(str, what, sentence)); + BOOST_REQUIRE(7 == what.nested_results().size()); + smatch::nested_results_type::const_iterator pword = what.nested_results().begin(); + BOOST_CHECK((*pword++)[0] == "Its"); + BOOST_CHECK((*pword++)[0] == "a"); + BOOST_CHECK((*pword++)[0] == "mad"); + BOOST_CHECK((*pword++)[0] == "Mad"); + BOOST_CHECK((*pword++)[0] == "mAd"); + BOOST_CHECK((*pword++)[0] == "maD"); + BOOST_CHECK((*pword++)[0] == "world"); + BOOST_CHECK(pword == what.nested_results().end()); +} + +/////////////////////////////////////////////////////////////////////////////// +// test for a simple non-recursive grammar +// +void test3() +{ + // test for a simple regex grammar + std::string buffer = + "FROGGIE\r\n" + "Volume = 1\r\n" + "Other1= 2\r\n" + "Channel=3\r\n" + "Other =4\r\n" + "\r\n" + "FROGGIE\r\n" + "Volume = 5\r\n" + "Other1= 6\r\n" + "Channel=7\r\n" + "Other =8\r\n" + "\r\n" + "FROGGIE\r\n" + "Volume = 9\r\n" + "Other1= 0\r\n" + "Channel=10\r\n" + "\r\n"; + + mark_tag name(1), value(2); + + sregex name_value_pair_ = + (name= +alnum) >> *_s >> "=" >> *_s >> + (value= +_d) >> *_s >> _ln; + + sregex message_ = + *_s >> "FROGGIE" >> _ln >> +name_value_pair_ >> _ln; + + sregex re_ = +message_; + + smatch::nested_results_type::const_iterator msg, nvp; + smatch tmpwhat; + + BOOST_REQUIRE(regex_search(buffer, tmpwhat, re_)); + // for giggles, make a deep-copy of the tree of results + smatch what = tmpwhat; + BOOST_REQUIRE(3 == what.nested_results().size()); + + msg = what.nested_results().begin(); + BOOST_REQUIRE(4 == msg->nested_results().size()); + + nvp = msg->nested_results().begin(); + BOOST_REQUIRE(3 == nvp->size()); + BOOST_CHECK("Volume" == (*nvp)[name]); + BOOST_CHECK("1" == (*nvp)[value]); + ++nvp; + BOOST_REQUIRE(3 == nvp->size()); + BOOST_CHECK("Other1" == (*nvp)[name]); + BOOST_CHECK("2" == (*nvp)[value]); + ++nvp; + BOOST_REQUIRE(3 == nvp->size()); + BOOST_CHECK("Channel" == (*nvp)[name]); + BOOST_CHECK("3" == (*nvp)[value]); + ++nvp; + BOOST_REQUIRE(3 == nvp->size()); + BOOST_CHECK("Other" == (*nvp)[name]); + BOOST_CHECK("4" == (*nvp)[value]); + + ++msg; + BOOST_REQUIRE(4 == msg->nested_results().size()); + + nvp = msg->nested_results().begin(); + BOOST_REQUIRE(3 == nvp->size()); + BOOST_CHECK("Volume" == (*nvp)[name]); + BOOST_CHECK("5" == (*nvp)[value]); + ++nvp; + BOOST_REQUIRE(3 == nvp->size()); + BOOST_CHECK("Other1" == (*nvp)[name]); + BOOST_CHECK("6" == (*nvp)[value]); + ++nvp; + BOOST_REQUIRE(3 == nvp->size()); + BOOST_CHECK("Channel" == (*nvp)[name]); + BOOST_CHECK("7" == (*nvp)[value]); + ++nvp; + BOOST_REQUIRE(3 == nvp->size()); + BOOST_CHECK("Other" == (*nvp)[name]); + BOOST_CHECK("8" == (*nvp)[value]); + + ++msg; + BOOST_REQUIRE(3 == msg->nested_results().size()); + + nvp = msg->nested_results().begin(); + BOOST_REQUIRE(3 == nvp->size()); + BOOST_CHECK("Volume" == (*nvp)[name]); + BOOST_CHECK("9" == (*nvp)[value]); + ++nvp; + BOOST_REQUIRE(3 == nvp->size()); + BOOST_CHECK("Other1" == (*nvp)[name]); + BOOST_CHECK("0" == (*nvp)[value]); + ++nvp; + BOOST_REQUIRE(3 == nvp->size()); + BOOST_CHECK("Channel" == (*nvp)[name]); + BOOST_CHECK("10" == (*nvp)[value]); +} + +/////////////////////////////////////////////////////////////////////////////// +// test for a self-recursive regex +// +void test4() +{ + sregex parentheses; + parentheses // A balanced set of parentheses ... + = '(' // is an opening parenthesis ... + >> // followed by ... + *( // zero or more ... + keep( +~(set='(',')') ) // of a bunch of things that are not parentheses ... + | // or ... + by_ref(parentheses) // a balanced set of parentheses + ) // (ooh, recursion!) ... + >> // followed by ... + ')' // a closing parenthesis + ; + + smatch what; + smatch::nested_results_type::const_iterator pwhat, pwhat2; + std::string str( "blah blah( a(b)c (c(e)f (g)h )i (j)6 )blah" ); + + BOOST_REQUIRE(regex_search(str, what, parentheses)); + BOOST_REQUIRE(1 == what.size()); + BOOST_CHECK("( a(b)c (c(e)f (g)h )i (j)6 )" == what[0]); + + BOOST_REQUIRE(3 == what.nested_results().size()); + pwhat = what.nested_results().begin(); + BOOST_REQUIRE(1 == pwhat->size()); + BOOST_CHECK("(b)" == (*pwhat)[0]); + + ++pwhat; + BOOST_REQUIRE(1 == pwhat->size()); + BOOST_CHECK("(c(e)f (g)h )" == (*pwhat)[0]); + + BOOST_REQUIRE(2 == pwhat->nested_results().size()); + pwhat2 = pwhat->nested_results().begin(); + BOOST_REQUIRE(1 == pwhat2->size()); + BOOST_CHECK("(e)" == (*pwhat2)[0]); + + ++pwhat2; + BOOST_REQUIRE(1 == pwhat2->size()); + BOOST_CHECK("(g)" == (*pwhat2)[0]); + + ++pwhat; + BOOST_REQUIRE(1 == pwhat->size()); + BOOST_CHECK("(j)" == (*pwhat)[0]); +} + +/////////////////////////////////////////////////////////////////////////////// +// test for a sub-match scoping +// +void test5() +{ + sregex inner = sregex::compile( "(.)\\1" ); + sregex outer = (s1= _) >> inner >> s1; + std::string abba("ABBA"); + + BOOST_CHECK(regex_match(abba, outer)); +} + +/////////////////////////////////////////////////////////////////////////////// +// Ye olde calculator. Test recursive grammar. +// +void test6() +{ + sregex group, factor, term, expression; + + group = '(' >> by_ref(expression) >> ')'; + factor = +_d | group; + term = factor >> *(('*' >> factor) | ('/' >> factor)); + expression = term >> *(('+' >> term) | ('-' >> term)); + + smatch what; + std::string str("foo 9*(10+3) bar"); + + BOOST_REQUIRE(regex_search(str, what, expression)); + BOOST_CHECK("9*(10+3)" == what[0]); +} + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("miscelaneous tests and examples from the docs"); + + test->add(BOOST_TEST_CASE(&test1)); + test->add(BOOST_TEST_CASE(&test2)); + test->add(BOOST_TEST_CASE(&test3)); + test->add(BOOST_TEST_CASE(&test4)); + test->add(BOOST_TEST_CASE(&test5)); + test->add(BOOST_TEST_CASE(&test6)); + + return test; +} diff --git a/src/boost/libs/xpressive/test/misc2.cpp b/src/boost/libs/xpressive/test/misc2.cpp new file mode 100644 index 00000000..2c78e594 --- /dev/null +++ b/src/boost/libs/xpressive/test/misc2.cpp @@ -0,0 +1,91 @@ +/////////////////////////////////////////////////////////////////////////////// +// misc2.hpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <map> +#include <string> +#include <boost/xpressive/xpressive.hpp> +#include <boost/xpressive/regex_actions.hpp> +#include <boost/test/unit_test.hpp> + +namespace xpr = boost::xpressive; +using namespace xpr; + +/////////////////////////////////////////////////////////////////////////////// +// +void test_complement() +{ + sregex rx1 = ~_n >> ~(set='a') >> ~(set='a','b') >> ~set['a'] >> ~_ln + >> ~before('a') >> ~after('a') >> ~alpha >> ~range('a','b') >> ~_b >> ~as_xpr('a'); + +#ifndef BOOST_XPRESSIVE_NO_WREGEX + wsregex rx2 = ~_n >> ~(set=L'a') >> ~(set=L'a',L'b') >> ~set[L'a'] >> ~_ln + >> ~before(L'a') >> ~after(L'a') >> ~alpha >> ~range(L'a',L'b') >> ~_b >> ~as_xpr(L'a'); +#endif +} + +/////////////////////////////////////////////////////////////////////////////// +// +void test_static_actions_in_dynamic_keep() +{ + std::string result; + std::string str("foo"); + + sregex_compiler compiler; + compiler["rx0"] = (s1="foo")[ xpr::ref(result) = s1 ]; + sregex rx = compiler.compile("(?>(?$rx0))"); + + bool ok = regex_match(str, rx); + BOOST_CHECK(ok); + BOOST_CHECK_EQUAL(result, "foo"); +} + +/////////////////////////////////////////////////////////////////////////////// +// +void test_static_actions_in_static_keep() +{ + std::string result; + std::string str("foo"); + + sregex rx0 = (s1="foo")[ xpr::ref(result) = s1 ]; + sregex rx = keep(rx0); + + bool ok = regex_match(str, rx); + BOOST_CHECK(ok); + BOOST_CHECK_EQUAL(result, "foo"); +} + +/////////////////////////////////////////////////////////////////////////////// +// +void test_replace_with_lambda() +{ + std::map<std::string, std::string> replacements; + replacements["X"] = "this"; + replacements["Y"] = "that"; + + std::string input("\"$(X)\" has the value \"$(Y)\""), output; + std::string expected("\"this\" has the value \"that\""); + sregex rx = "$(" >> (s1= +~as_xpr(')')) >> ')'; + + output = regex_replace(input, rx, xpr::ref(replacements)[s1]); + BOOST_CHECK_EQUAL(output, expected); +} + +using namespace boost::unit_test; +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("miscelaneous tests"); + + test->add(BOOST_TEST_CASE(&test_complement)); + test->add(BOOST_TEST_CASE(&test_static_actions_in_dynamic_keep)); + test->add(BOOST_TEST_CASE(&test_static_actions_in_static_keep)); + test->add(BOOST_TEST_CASE(&test_replace_with_lambda)); + + return test; +} diff --git a/src/boost/libs/xpressive/test/multiple_defs1.cpp b/src/boost/libs/xpressive/test/multiple_defs1.cpp new file mode 100644 index 00000000..8067294d --- /dev/null +++ b/src/boost/libs/xpressive/test/multiple_defs1.cpp @@ -0,0 +1,16 @@ +/////////////////////////////////////////////////////////////////////////////// +// multiple_defs1.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/xpressive/xpressive.hpp> +extern int f(); +int main() +{ + using namespace boost::xpressive; + sregex srx = +_; + sregex drx = sregex::compile(".+"); + return f(); +} diff --git a/src/boost/libs/xpressive/test/multiple_defs2.cpp b/src/boost/libs/xpressive/test/multiple_defs2.cpp new file mode 100644 index 00000000..b9305d81 --- /dev/null +++ b/src/boost/libs/xpressive/test/multiple_defs2.cpp @@ -0,0 +1,17 @@ +/////////////////////////////////////////////////////////////////////////////// +// multiple_defs2.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/xpressive/xpressive.hpp> + +int f() +{ + using namespace boost::xpressive; + sregex srx = +_; + sregex drx = sregex::compile(".+"); + + return 0; +} diff --git a/src/boost/libs/xpressive/test/regress.cpp b/src/boost/libs/xpressive/test/regress.cpp new file mode 100644 index 00000000..f968d5e4 --- /dev/null +++ b/src/boost/libs/xpressive/test/regress.cpp @@ -0,0 +1,14 @@ +////////////////////////////////////////////////////////////////////////////// +// regress.cpp +// +// (C) Copyright Eric Niebler 2004. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +/* + Revision history: + 6 January 2006 : Initial version. +*/ + +#include "./regress.ipp" diff --git a/src/boost/libs/xpressive/test/regress.ipp b/src/boost/libs/xpressive/test/regress.ipp new file mode 100644 index 00000000..683c8b1e --- /dev/null +++ b/src/boost/libs/xpressive/test/regress.ipp @@ -0,0 +1,451 @@ +////////////////////////////////////////////////////////////////////////////// +// regress.ipp +// +// (C) Copyright Eric Niebler 2004. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +/* + Revision history: + 7 March 2004 : Initial version. +*/ + +#include <locale> +#include <vector> +#include <string> +#include <fstream> +#include <iostream> +#include <boost/lexical_cast.hpp> +#include <boost/xpressive/xpressive.hpp> +#include <boost/test/unit_test.hpp> + +#if defined(_MSC_VER) && defined(_DEBUG) +# define _CRTDBG_MAP_ALLOC +# include <crtdbg.h> +#endif + +#if defined(BOOST_XPRESSIVE_TEST_WREGEX) && !defined(BOOST_XPRESSIVE_NO_WREGEX) +namespace std +{ + inline std::ostream &operator <<(std::ostream &sout, std::wstring const &wstr) + { + for(std::size_t n = 0; n < wstr.size(); ++n) + sout.put(BOOST_USE_FACET(std::ctype<wchar_t>, std::locale()).narrow(wstr[n], '?')); + return sout; + } +} +#endif + +#define BOOST_XPR_CHECK(pred) \ + if(pred) {} else { BOOST_ERROR(case_ << #pred); } + +using namespace boost::unit_test; +using namespace boost::xpressive; + +////////////////////////////////////////////////////////////////////////////// +// xpr_test_case +template<typename Char> +struct xpr_test_case +{ + typedef std::basic_string<Char> string_type; + std::string section; + string_type str; + string_type pat; + string_type sub; + string_type res; + regex_constants::syntax_option_type syntax_flags; + regex_constants::match_flag_type match_flags; + std::vector<string_type> br; + + xpr_test_case() + { + this->reset(); + } + + void reset() + { + this->section.clear(); + this->str.clear(); + this->pat.clear(); + this->sub.clear(); + this->res.clear(); + this->br.clear(); + this->syntax_flags = regex_constants::ECMAScript; + this->match_flags = regex_constants::match_default | regex_constants::format_first_only; + } +}; + +////////////////////////////////////////////////////////////////////////////// +// globals +std::ifstream in; +unsigned int test_count = 0; + +// The global object that contains the current test case +xpr_test_case<char> test; + +struct test_case_formatter +{ + friend std::ostream &operator <<(std::ostream &sout, test_case_formatter) + { + sout << test.section << " /" << test.pat << "/ : "; + return sout; + } +}; + +test_case_formatter const case_ = {}; + +#if defined(BOOST_XPRESSIVE_TEST_WREGEX) && !defined(BOOST_XPRESSIVE_NO_WREGEX) +/////////////////////////////////////////////////////////////////////////////// +// widen +// make a std::wstring from a std::string by widening according to the +// current ctype<char> facet +inline std::wstring widen(std::string const &str) +{ + std::ctype<char> const &ct = BOOST_USE_FACET(std::ctype<char>, std::locale()); + std::wstring res; + for(size_t i=0; i<str.size(); ++i) + { + res += ct.widen(str[i]); + } + return res; +} + +/////////////////////////////////////////////////////////////////////////////// +// widen +// widens an entire test case +xpr_test_case<wchar_t> widen(xpr_test_case<char> const &test) +{ + xpr_test_case<wchar_t> wtest; + wtest.section = test.section; + wtest.str = ::widen(test.str); + wtest.pat = ::widen(test.pat); + wtest.sub = ::widen(test.sub); + wtest.res = ::widen(test.res); + wtest.syntax_flags = test.syntax_flags; + wtest.match_flags = test.match_flags; + wtest.br.reserve(test.br.size()); + for(std::size_t i = 0; i < test.br.size(); ++i) + { + wtest.br.push_back(::widen(test.br[i])); + } + return wtest; +} +#endif // BOOST_XPRESSIVE_NO_WREGEX + +std::string escape(std::string str) +{ + for(std::string::size_type pos = 0; std::string::npos != (pos = str.find('\\', pos)); ++pos) + { + if(pos + 1 == str.size()) + break; + + switch(str[pos + 1]) + { + case '\\': str.replace(pos, 2, "\\"); break; + case 'n': str.replace(pos, 2, "\n"); break; + case 'r': str.replace(pos, 2, "\r"); break; + } + } + return str; +} + +/////////////////////////////////////////////////////////////////////////////// +// get_test +// read the next section out of the input file, and fill out +// the global variables +bool get_test() +{ + test.reset(); + bool first = true; + std::string line; + smatch what; + + sregex const rx_sec = '[' >> (s1= +_) >> ']'; + sregex const rx_str = "str=" >> (s1= *_); + sregex const rx_pat = "pat=" >> (s1= *_); + sregex const rx_flg = "flg=" >> (s1= *_); + sregex const rx_sub = "sub=" >> (s1= *_); + sregex const rx_res = "res=" >> (s1= *_); + sregex const rx_br = "br" >> (s1= +digit) >> '=' >> (s2= *_); + + while(in.good()) + { + std::getline(in, line); + + if(!line.empty() && '\r' == line[line.size()-1]) + { + line.erase(line.size()-1); + } + + if(regex_match(line, what, rx_sec)) + { + if(!first) + { + if(what[1] != "end") + { + BOOST_FAIL(("invalid input : " + line).c_str()); + } + break; + } + + first = false; + test.section = what[1].str(); + } + else if(regex_match(line, what, rx_str)) + { + test.str = escape(what[1].str()); + } + else if(regex_match(line, what, rx_pat)) + { + test.pat = what[1].str(); + } + else if(regex_match(line, what, rx_sub)) + { + test.sub = what[1].str(); + } + else if(regex_match(line, what, rx_res)) + { + test.res = escape(what[1].str()); + } + else if(regex_match(line, what, rx_flg)) + { + std::string flg = what[1].str(); + + if(std::string::npos != flg.find('i')) + { + test.syntax_flags = test.syntax_flags | regex_constants::icase; + } + if(std::string::npos == flg.find('m')) + { + test.syntax_flags = test.syntax_flags | regex_constants::single_line; + } + if(std::string::npos == flg.find('s')) + { + test.syntax_flags = test.syntax_flags | regex_constants::not_dot_newline; + } + if(std::string::npos != flg.find('x')) + { + test.syntax_flags = test.syntax_flags | regex_constants::ignore_white_space; + } + if(std::string::npos != flg.find('g')) + { + test.match_flags = test.match_flags & ~regex_constants::format_first_only; + } + if(std::string::npos != flg.find('a')) + { + test.match_flags = test.match_flags | regex_constants::format_all; + } + if(std::string::npos != flg.find('p')) + { + test.match_flags = test.match_flags | regex_constants::format_perl; + } + if(std::string::npos != flg.find('d')) + { + test.match_flags = test.match_flags | regex_constants::format_sed; + } + } + else if(regex_match(line, what, rx_br)) + { + std::size_t nbr = boost::lexical_cast<std::size_t>(what[1].str()); + + if(nbr >= test.br.size()) + { + test.br.resize(nbr + 1); + } + + test.br[nbr] = escape(what[2].str()); + } + else if(!line.empty() && ';' != line[0]) + { + BOOST_FAIL((std::string("invalid input : ") + line).c_str()); + } + } + + return !first; +} + +/////////////////////////////////////////////////////////////////////////////// +// run_test_impl +// run the test +template<typename Char> +void run_test_impl(xpr_test_case<Char> const &test) +{ + try + { + Char const empty[] = {0}; + typedef typename std::basic_string<Char>::const_iterator iterator; + basic_regex<iterator> rx = basic_regex<iterator>::compile(test.pat, test.syntax_flags); + + // Build the same regex for use with C strings + basic_regex<Char const *> c_rx = basic_regex<Char const *>::compile(test.pat, test.syntax_flags); + + if(!test.res.empty()) + { + // test regex_replace + std::basic_string<Char> res = regex_replace(test.str, rx, test.sub, test.match_flags); + BOOST_CHECK_MESSAGE(res == test.res, case_ << res << " != " << test.res ); + + // test regex_replace with NTBS format string + std::basic_string<Char> res2 = regex_replace(test.str, rx, test.sub.c_str(), test.match_flags); + BOOST_CHECK_MESSAGE(res2 == test.res, case_ << res2 << " != " << test.res ); + + // test regex_replace with NTBS input string + std::basic_string<Char> res3 = regex_replace(test.str.c_str(), c_rx, test.sub, test.match_flags); + BOOST_CHECK_MESSAGE(res3 == test.res, case_ << res3 << " != " << test.res ); + + // test regex_replace with NTBS input string and NTBS format string + std::basic_string<Char> res4 = regex_replace(test.str.c_str(), c_rx, test.sub.c_str(), test.match_flags); + BOOST_CHECK_MESSAGE(res4 == test.res, case_ << res4 << " != " << test.res ); + } + + if(0 == (test.match_flags & regex_constants::format_first_only)) + { + { + // global search, use regex_iterator + std::vector<sub_match<iterator> > br; + regex_iterator<iterator> begin(test.str.begin(), test.str.end(), rx, test.match_flags), end; + for(; begin != end; ++begin) + { + match_results<iterator> const &what = *begin; + br.insert(br.end(), what.begin(), what.end()); + } + + // match succeeded: was it expected to succeed? + BOOST_XPR_CHECK(br.size() == test.br.size()); + + for(std::size_t i = 0; i < br.size() && i < test.br.size(); ++i) + { + BOOST_XPR_CHECK((!br[i].matched && test.br[i] == empty) || test.br[i] == br[i].str()); + } + } + + { + // global search, use regex_token_iterator + std::vector<typename sub_match<iterator>::string_type> br2; + std::vector<int> subs(rx.mark_count() + 1, 0); + // regex_token_iterator will extract all sub_matches, in order: + for(std::size_t i = 0; i < subs.size(); ++i) + { + subs[i] = static_cast<int>(i); + } + regex_token_iterator<iterator> begin2(test.str.begin(), test.str.end(), rx, subs, test.match_flags), end2; + for(; begin2 != end2; ++begin2) + { + br2.push_back(*begin2); + } + + // match succeeded: was it expected to succeed? + BOOST_XPR_CHECK(br2.size() == test.br.size()); + + for(std::size_t i = 0; i < br2.size() && i < test.br.size(); ++i) + { + BOOST_XPR_CHECK(test.br[i] == br2[i]); + } + } + } + else + { + // test regex_search + match_results<iterator> what; + if(regex_search(test.str, what, rx, test.match_flags)) + { + // match succeeded: was it expected to succeed? + BOOST_XPR_CHECK(what.size() == test.br.size()); + + for(std::size_t i = 0; i < what.size() && i < test.br.size(); ++i) + { + BOOST_XPR_CHECK((!what[i].matched && test.br[i] == empty) || test.br[i] == what[i].str()); + } + } + else + { + // match failed: was it expected to fail? + BOOST_XPR_CHECK(0 == test.br.size()); + } + } + } + catch(regex_error const &e) + { + BOOST_ERROR(case_ << e.what()); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// run_test_impl +// run the current test +void run_test() +{ + #ifdef BOOST_XPRESSIVE_TEST_WREGEX + xpr_test_case<wchar_t> wtest = ::widen(test); + run_test_impl(wtest); + #else + run_test_impl(test); + #endif +} + +static char const * s_argv1; + +/////////////////////////////////////////////////////////////////////////////// +// open_test +bool open_test() +{ + in.open( s_argv1? s_argv1: "regress.txt" ); + return in.good(); +} + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// read the tests from the input file and execute them +void test_main() +{ + #if !defined(BOOST_XPRESSIVE_TEST_WREGEX) || !defined(BOOST_XPRESSIVE_NO_WREGEX) + if(!open_test()) + { + BOOST_ERROR("Error: unable to open input file."); + } + + while(get_test()) + { + run_test(); + ++test_count; + } + #endif + + std::cout << test_count << " tests completed." << std::endl; +} + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + s_argv1 = argv[1]; + + test_suite *test = BOOST_TEST_SUITE("basic regression test"); + test->add(BOOST_TEST_CASE(&test_main)); + return test; +} + +/////////////////////////////////////////////////////////////////////////////// +// debug_init +static const struct debug_init +{ + debug_init() + { + #if defined(_MSC_VER) && defined(_DEBUG) + // Send warnings, errors and asserts to STDERR + _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); + _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); + _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); + _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); + _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); + _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); + + // Check for leaks at program termination + _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF | _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG)); + + //_CrtSetBreakAlloc(221); + #endif + } +} g_debug_init; diff --git a/src/boost/libs/xpressive/test/regress.txt b/src/boost/libs/xpressive/test/regress.txt new file mode 100644 index 00000000..803e9d6a --- /dev/null +++ b/src/boost/libs/xpressive/test/regress.txt @@ -0,0 +1,3756 @@ +; Copyright 2004 Eric Niebler. +; +; Distributed under the Boost Software License, Version 1.0. +; (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +[test1] +str=foobarboo +pat=foo +flg= +br0=foo +[end] + +[test2] +str=foobarboo +pat=bar +flg= +br0=bar +[end] + +[test3] +str=foobarboo +pat=bat +flg= +[end] + +[test4] +str=foobarboo +pat=b.*ar +flg= +br0=bar +[end] + +[test5] +str=foobarboo +pat=b.*r +flg= +br0=bar +[end] + +[test6] +str=foobarboo +pat=b.*b +flg= +br0=barb +[end] + +[test7] +str=foobarboo +pat=b.*o +flg= +br0=barboo +[end] + +[test8] +str=foobarboo +pat=b.*oo +flg= +br0=barboo +[end] + +[test9] +str=foobarboo +pat=b.+ar +flg= +[end] + +[test10] +str=foobarboo +pat=b.+r +flg= +br0=bar +[end] + +[test11] +str=foobarboo +pat=b.+b +flg= +br0=barb +[end] + +[test12] +str=foobarboo +pat=b.+o +flg= +br0=barboo +[end] + +[test13] +str=foobarboo +pat=b.+oo +flg= +br0=barboo +[end] + +[test14] +str=foobarboo +pat=^foo +flg= +br0=foo +[end] + +[test15] +str=foobarboo +pat=^b.*ar +flg= +[end] + +[test16] +str=foobarboo +pat=b.+ar$ +flg= +[end] + +[test17] +str=foobarboo +pat=b.+o$ +flg= +br0=barboo +[end] + +[test18] +str=foobarboo +pat=b.+oo$ +flg= +br0=barboo +[end] + +[test19] +str=+1234.56789F +pat=^([-+]?[0-9]+(\.[0-9]*)?)([CF])$ +flg= +br0=+1234.56789F +br1=+1234.56789 +br2=.56789 +br3=F +[end] + +[test20] +str=+1234.56789 +pat=(\+|-)?([0-9]+\.?[0-9]*|\.[0-9]+)([eE](\+|-)?[0-9]+)? +flg= +br0=+1234.56789 +br1=+ +br2=1234.56789 +br3= +br4= +[end] + +[test21] +str=-1234.56789 +pat=(\+|-)?([0-9]+\.?[0-9]*|\.[0-9]+)([eE](\+|-)?[0-9]+)? +flg= +br0=-1234.56789 +br1=- +br2=1234.56789 +br3= +br4= +[end] + +[test22] +str=-1234.56789e-123123123 +pat=(\+|-)?([0-9]+\.?[0-9]*|\.[0-9]+)([eE](\+|-)?[0-9]+)? +flg= +br0=-1234.56789e-123123123 +br1=- +br2=1234.56789 +br3=e-123123123 +br4=- +[end] + +[test23] +str=-.1234.56789 +pat=^(\+|-)?([0-9]+\.?[0-9]*|\.[0-9]+)([eE](\+|-)?[0-9]+)?$ +flg= +[end] + +[test24] +str=-1234.56789e-12312e123 +pat=^(\+|-)?([0-9]+\.?[0-9]*|\.[0-9]+)([eE](\+|-)?[0-9]+)?$ +flg= +[end] + +[test25] +str=aaaaaaaaac +pat=a*a*a*a*a*b +flg= +[end] + +[test26] +str=ThIs iS a TeSt +pat=[a-zA-Z]* +flg= +br0=ThIs +[end] + +[test27] +str=a^b +pat=a^b +flg= +[end] + +[test28] +str=a^b +pat=a\^b +flg= +br0=a^b +[end] + +[test29] +str=a^b +pat=a[^ ]b +flg= +br0=a^b +[end] + +[test30] +str=a^b +pat=a[^^]b +flg= +[end] + +[test31] +str=a^b +pat=a[^\^]b +flg= +[end] + +[test31.1] +str=a^b +pat=a[\^]b +flg= +br0=a^b +[end] + +[test32] +str=foobazFOObar +pat=foo(?=bar) +flg=i +br0=FOO +[end] + +[test33] +str=foobarFOObaz +pat=foo(?!bar) +flg=i +br0=FOO +[end] + +[test34] +str=foobarFOO +pat=foo(?!bar) +flg=i +br0=FOO +[end] + +[test35] +str=foobarFOObarfoo +pat=((?>(foo))bar)+ +flg=i +br0=foobarFOObar +br1=FOObar +br2=FOO +[end] + +[test36] +str=foobar +pat=bar|(foo) +flg=g +br0=foo +br1=foo +br2=bar +br3= +[end] + +; These results seem odd to me, but +; it comforms with perl + +[test37] +str=foobar +pat=(bar|(foo))+ +flg= +br0=foobar +br1=bar +br2=foo +[end] + +[test38] +str=foobar +pat=((bar)|foo)+ +flg= +br0=foobar +br1=bar +br2=bar +[end] + +[test39] +str=foobar +pat=(foo|(bar))+ +flg= +br0=foobar +br1=bar +br2=bar +[end] + +; These results seem odd to me, but +; it comforms with perl + +[test40] +str=foobar +pat=((foo)|bar)+ +flg= +br0=foobar +br1=bar +br2=foo +[end] + +[test41] +str=foobarFOObarfoo +pat=((?i)FOO)(.*?)\1 +flg= +br0=foobarFOObarfoo +br1=foo +br2=barFOObar +[end] + +[test42] +str=foobarFOObarfoo +pat=((?i)FOO)(.*?)(?i:\1) +flg= +br0=foobarFOO +br1=foo +br2=bar +[end] + +; perl allows this, and it is pretty sick. +; But anything perl can do, I can do, too.[end] + +[test42.1] +str=fooFOOOFOOOOObar +pat=(foo|(?i:\1O))+ +flg= +br0=fooFOOOFOOOO +br1=FOOOO +[end] + +[test43] +str=zoo +pat=^[A-Za-m] +flg= +[end] + +[test44] +str=Here is a URL: http://www.cnn.com. OK? +pat=(https?:/|www\.)[\w\./,?@#%!_=~&-]+\w +flg= +br0=http://www.cnn.com +br1=http:/ +[end] + +[test45] +str=fooooooooo +pat=fo{2,5} +flg= +br0=fooooo +[end] + +[test46] +str=fooooooooo +pat=fo{2,5}? +flg= +br0=foo +[end] + +[test45.1] +str=fooooooooo +pat=fo{2,5}o +flg= +br0=foooooo +[end] + +[test46.1] +str=fooooooooo +pat=fo{2,5}?o +flg= +br0=fooo +[end] + +[test47] +str={match this} +pat=^{.*}$ +flg= +br0={match this} +[end] + +[test48] +str=+-+- +pat=[+-]+ +flg= +br0=+-+- +[end] + +[test49] +str=+-+- +pat=[-+]+ +flg= +br0=+-+- +[end] + +[test50] +str=\\05g-9e +pat=[\d-g]+ +flg= +br0=05g-9 +[end] + +[test51] +str=\\05g-9e +pat=[\d-\g]+ +flg= +br0=05g-9 +[end] + +[test52] +str=\\05g-9e +pat=[g-\d]+ +flg= +br0=05g-9 +[end] + +[test53] +str=\\05g-9e +pat=[\g-\d]+ +flg= +br0=05g-9 +[end] + +[test54] +str=aBcdefg\\ +pat=[a-\g]+ +flg=i +br0=aBcdefg +[end] + +[test55] +str=ab/.-ba +pat=[--/]+ +flg= +br0=/.- +[end] + +[test56] +str=ab+,-ba +pat=[+--]+ +flg= +br0=+,- +[end] + +[test56.1] +str=aaabbbb---- +pat=[b-b]+ +flg= +br0=bbbb +[end] + +[test57] +str=foobarFOO5 +pat=(foo).*\15 +flg=i +[end] + +[test58] +str=Her number is 804-867-5309. +pat=(?:\d{3}-){2}\d{4} +flg= +br0=804-867-5309 +[end] + +[test59] +str=foo +pat=fo+ +flg= +br0=foo +[end] + +; backtrack a group[end] + +[test60] +str=fooFOObar +pat=(foo)+foobar +flg=i +br0=fooFOObar +br1=foo +[end] + +; nested, matched parens [end] + +[test61] +str=this is sublist(now(is(the(time),for(all),good(men))to(come)))ok? +pat=\bsublist\((?>[^()]*)(?>(?:\((?>[^()]*)(?>(?:\((?>[^()]*)(?>(?:\((?>[^()]*)(?>(?:\((?>[^()]*)\)[^()]*)*)\)[^()]*)*)\)[^()]*)*)\)[^()]*)*)\) +flg= +br0=sublist(now(is(the(time),for(all),good(men))to(come))) +[end] + +; nested, matched parens [end] + +[test62] +str=this is sublist(now(is(the(time),for(all),good(men))to(come))ok? +pat=\bsublist\((?>[^()]*)(?>(?:\((?>[^()]*)(?>(?:\((?>[^()]*)(?>(?:\((?>[^()]*)(?>(?:\((?>[^()]*)\)[^()]*)*)\)[^()]*)*)\)[^()]*)*)\)[^()]*)*)\) +flg= +[end] + +[test63] +str=foobar +pat=^baz|bar +flg= +br0=bar +[end] + +[test64] +str=Now <foo>is</foo> the time for all <BOLD>good</bald> men</bold> to come to the aid of their country. +pat=<(.*?)>(.*?)</(\1)> +flg=ig +sub={$1}$2{/$3} +res=Now {foo}is{/foo} the time for all {BOLD}good</bald> men{/bold} to come to the aid of their country. +br0=<foo>is</foo> +br1=foo +br2=is +br3=foo +br4=<BOLD>good</bald> men</bold> +br5=BOLD +br6=good</bald> men +br7=bold +[end] + +[test64.sed] +str=Now <foo>is</foo> the time for all <BOLD>good</bald> men</bold> to come to the aid of their country. +pat=<(.*?)>(.*?)</(\1)> +flg=igd +sub={\1}\2{/\3} +res=Now {foo}is{/foo} the time for all {BOLD}good</bald> men{/bold} to come to the aid of their country. +br0=<foo>is</foo> +br1=foo +br2=is +br3=foo +br4=<BOLD>good</bald> men</bold> +br5=BOLD +br6=good</bald> men +br7=bold +[end] + +[test68] +str=Now is the time for all good men to come to the aid of their country. +pat=o +flg=g +sub=O +res=NOw is the time fOr all gOOd men tO cOme tO the aid Of their cOuntry. +br0=o +br1=o +br2=o +br3=o +br4=o +br5=o +br6=o +br7=o +br8=o +[end] + +[test69] +str=FooBarfoobar +pat=.*foo +flg=i +br0=FooBarfoo +[end] + +[test70] +str=FooBarfoobar +pat=.*boo +flg=i +[end] + +[test71] +str=FooBarfoobar +pat=.*boo|bar +flg=i +br0=Bar +[end] + +[test72] +str=FooBarfoobar +pat=bar +flg=i +sub=($`$&) +res=Foo(FooBar)foobar +br0=Bar +[end] + +[test72.perl] +str=FooBarfoobar +pat=bar +flg=ip +sub=($`$&) +res=Foo(FooBar)foobar +br0=Bar +[end] + +[test73] +str=FooBarfoobar +pat=bar +flg=gi +sub=($`$&) +res=Foo(FooBar)foo(FooBarfoobar) +br0=Bar +br1=bar +[end] + +[test73.perl] +str=FooBarfoobar +pat=bar +flg=gip +sub=($`$&) +res=Foo(FooBar)foo(FooBarfoobar) +br0=Bar +br1=bar +[end] + +[test74] +str=FooBarfoobar +pat=bar +flg=gi +sub=($'$&) +res=Foo(foobarBar)foo(bar) +br0=Bar +br1=bar +[end] + +[test74.perl] +str=FooBarfoobar +pat=bar +flg=gip +sub=($'$&) +res=Foo(foobarBar)foo(bar) +br0=Bar +br1=bar +[end] + +[test75] +str=fooooo +pat=fo{1,} +flg= +br0=fooooo +[end] + +[test76.perl] +str=fOO bAr BaZ +pat=\w+ +flg=gp +sub=\L\u$& +res=Foo Bar Baz +br0=fOO +br1=bAr +br2=BaZ +[end] + +[test76.all] +str=fOO bAr BaZ +pat=\w+ +flg=ga +sub=\L\u$& +res=Foo Bar Baz +br0=fOO +br1=bAr +br2=BaZ +[end] + +[test77.perl] +str=fOO bAr BaZ +pat=\w+ +flg=gp +sub=a\LA\Ua\Ea +res=aaAa aaAa aaAa +br0=fOO +br1=bAr +br2=BaZ +[end] + +[test77.all] +str=fOO bAr BaZ +pat=\w+ +flg=ga +sub=a\LA\Ua\Ea +res=aaAa aaAa aaAa +br0=fOO +br1=bAr +br2=BaZ +[end] + +[test78] +str=This (has) parens +pat=This (\Q(has)\E) (parens) +flg= +br0=This (has) parens +br1=(has) +br2=parens +[end] + +[test79] +str=This (has) parens +pat=This \Q(has) parens\E +flg= +br0=This (has) parens +[end] + +[test80] +str=This (has) parens +pat=This \Q(has) parens +flg= +br0=This (has) parens +[end] + +;[test81] +;str=THAT IS UPPERCASE is +;pat=IS +;flg=ig +;sub=\Uu\Ql$&\E$&n't +;res=THAT UL$&ISn't UPPERCASE UL$&isn't +;br0=is +;[end] + +[test82] +str=abba1234abba +pat=\d+ +flg= +br0=1234 +[end] + +[test83] +str=1234abba1234 +pat=\D+ +flg= +br0=abba +[end] + +[test84] +str=abba1234abba +pat=[\d]+ +flg= +br0=1234 +[end] + +[test85] +str=1234abba1234 +pat=[\D]+ +flg= +br0=abba +[end] + +[test86] +str=abba1234abba +pat=[^\D]+ +flg= +br0=1234 +[end] + +[test87] +str=1234abba1234 +pat=[^\d]+ +flg= +br0=abba +[end] + +[test88] +str=1234abba1234 +pat=[\W\D]+ +flg= +br0=abba +[end] + +[test89] +str=1234(.;)abba +pat=[^\w\d]+ +flg= +br0=(.;) +[end] + +[test90] +str=(boo[bar]baz) +pat=(\(()|\[()).*?(\)\2|\]\3) +flg= +br0=(boo[bar]baz) +br1=( +br2= +br3= +br4=) +[end] + +[test91] +str=[boo(bar)baz] +pat=(\(()|\[()).*?(\)\2|\]\3) +flg= +br0=[boo(bar)baz] +br1=[ +br2= +br3= +br4=] +[end] + +[test91] +str=[boo[bar]baz] +pat=(\(()|\[()).*?(\)\2|\]\3) +flg= +br0=[boo[bar] +br1=[ +br2= +br3= +br4=] +[end] + +[test92] +str=foobarfoo +pat=(?<=foo)bar +flg= +br0=bar +[end] + +[test93] +str=foobarfoo +pat=(?<=(f.o))bar +flg= +br0=bar +br1=foo +[end] + +[test94] +str=foOoo +pat=(?<=(fo))o +flg=i +br0=O +br1=fo +[end] + +[test95] +str=fOooo +pat=(?<!(fo))o +flg=i +br0=O +br1= +[end] + +[test96] +str=12foo12 +pat=[[:alpha:]]+ +flg= +br0=foo +[end] + +[test97] +str=;12foo12; +pat=[[:alpha:][:digit:]]+ +flg= +br0=12foo12 +[end] + +[test98] +str=aaaa +pat=(?<=())a +flg= +br0=a +br1= +[end] + +[test99] +str=ABCabc123foo +pat=(?<=(abc\d{3}))foo +flg= +br0=foo +br1=abc123 +[end] + +;[test100] +;str=aaAAa +;pat=aa +;flg=gi +;br0=AA +;[end] + +;[test101] +;str=aaAAaA +;pat=aa +;flg=gi +;br0=aA +;[end] + +;[test102] +;str=foobarFOO +;pat=foo +;flg=ir +;br0=FOO +;[end] + +[test103] +str=a\nxb\n +pat=(?!^)x +flg=m +[end] + +[test104] +str=a\nxb\n +pat=(?!^)x +flg= +br0=x +[end] + +[test105] +str=a\nxb\n +pat=(?!\A)x +flg=m +br0=x +[end] + +[test106] +str=(this) +pat=^(?:\(()|())\w+(?:\)\1|\2)$ +flg= +br0=(this) +br1= +br2= +[end] + +[test107] +str=this +pat=^(?:\(()|())\w+(?:\)\1|\2)$ +flg= +br0=this +br1= +br2= +[end] + +[test108] +str=this) +pat=^(?:\(()|())\w+(?:\)\1|\2)$ +flg= +[end] + +[test109] +str=(this +pat=^(?:\(()|())\w+(?:\)\1|\2)$ +flg= +[end] + +[test110] +str=abba123abba +pat=[[:^alpha:]]+ +flg= +br0=123 +[end] + +[test111] +str=abba123abba +pat=[[:^alpha:][:alpha:]]+ +flg= +br0=abba123abba +[end] + +[test112] +str=123abba123 +pat=[^[:^alpha:]]+ +flg= +br0=abba +[end] + +;[test113] +;str=123abba123 +;pat=[[:alpha:]\y]+ +;flg= +;br0=123abba123 +;[end] + +[test114] +str=abba123abba +pat=[^[:^alnum:][:^digit:]]+ +flg= +br0=123 +[end] + +[test115] +str=aaaaA +pat=^(a\1?){4}$ +flg=i +br0=aaaaA +br1=A +[end] + +[test116] +str=aaaaAa +pat=^(a\1?){4}$ +flg=i +br0=aaaaAa +br1=Aa +[end] + +; test for possible infinite recursion + +[test117] +str=ab +pat=(a|(?=b)(?R))+ +flg= +br0=a +br1= +[end] + +[test118] +str=abba +pat=(?R) +flg= +br0= +[end] + +[test119] +str=nothere(HE(hehe(a(b(c)))nothere +pat=\(((?>[^()]+)|(?R))*\) +flg= +br0=(a(b(c))) +br1=(b(c)) +[end] + +[test120] +str=1(abcd)(x(y)z)pqr +pat=\(((?>[^()]+)|(?R))*\) +flg=ga +br0=(abcd) +br1=abcd +br2=(x(y)z) +br3=z +[end] + +[test121] +str=() +pat=\((?:(?>[^()]+)|(?R))?\) +flg= +br0=() +[end] + +[test122] +str=12(abcde(fsh)xyz(foo(bar))lmno)89 +pat=\((?:(?>[^()]+)|(?R))?\) +flg= +br0=(fsh) +[end] + +[test123] +str=(ab(xy)cd) +pat=\((((?>[^()]+)|(?R))*)\) +flg= +br0=(ab(xy)cd) +br1=ab(xy)cd +br2=cd +[end] + +[test124] +str=(ab(xy)cd) +pat=\((123)?(((?>[^()]+)|(?R))*)\) +flg= +br0=(ab(xy)cd) +br1= +br2=ab(xy)cd +br3=cd +[end] + +[test125] +str=(123ab(xy)cd) +pat=\((123)?(((?>[^()]+)|(?R))*)\) +flg= +br0=(123ab(xy)cd) +br1=123 +br2=ab(xy)cd +br3=cd +[end] + +[test126] +str=(abcd(xyz<p>qrs)123) +pat=\((((?>[^()<>]+)|((?>[^()]+))|(?R))*)\) +flg= +br0=(abcd(xyz<p>qrs)123) +br1=abcd(xyz<p>qrs)123 +br2=123 +;br3=<p>qrs +br3= +[end] + +[test127] +str=foobar +pat=foo(?#This is a comment[)bar +flg= +br0=foobar +[end] + +[test128] +str=foobar +pat=^ f oo b ar $ +flg=x +br0=foobar +[end] + +[test129] +str=foobar +pat=^ f o * +flg=x +br0=foo +[end] + +[test129.1] +str=foobar +pat=^ f \157 * +flg=x +br0=foo +[end] + +[test130] +str=foo bar +pat=^ f oo\ b ar $ +flg=x +br0=foo bar +[end] + +[test131] +str=foo bar +pat=^ f oo [ ] b ar $ +flg=x +br0=foo bar +[end] + +[test132] +str=foo bar +pat=^ ( ? : f oo [ ] b ar ) $ # This is a comment +flg=x +br0=foo bar +[end] + +[test133] +str=foo bar +pat=^ f oo [ ] b ar # This is a comment +flg=x +br0=foo bar +[end] + +[test134] +str=foo bar#Thisisnotacomment +pat=^ f oo [ ] b ar \# This is not a comment +flg=x +br0=foo bar#Thisisnotacomment +[end] + +[test135] +str=f oo b ar +pat=^f o(?x) o (?-x) b ar +flg= +br0=f oo b ar +[end] + +;[test136] +;str=foofoo +;pat=(?:foo)\1 +;flg= +;[end] + +[test137] +str=a-- +pat=^(a?)*$ +flg= +[end] + +[test138] +str=a-- +pat=^(a?)*?$ +flg= +[end] + +[test139] +str=bc +pat=^(b?){2}bc$ +flg= +br0=bc +br1= +[end] + +[test140] +str=bbc +pat=^(b?){2}bc$ +flg= +br0=bbc +br1= +[end] + +[test141] +str=bbbc +pat=^(b?){2}bc$ +flg= +br0=bbbc +br1=b +[end] + +[test142] +str=bbbbc +pat=^(b?){2}bc$ +flg= +[end] + +[test143] +str=bbbbc +pat=^(b?)*d$ +flg= +[end] + +[test144] +str=bc +pat=^(b?){2}?bc$ +flg= +br0=bc +br1= +[end] + +[test145] +str=bbc +pat=^(b?){2}?bc$ +flg= +br0=bbc +br1= +[end] + +[test146] +str=bbbc +pat=^(b?){2}?bc$ +flg= +br0=bbbc +br1=b +[end] + +[test147] +str=bbbbc +pat=^(b?){2}?bc$ +flg= +[end] + +[test148] +str=bbbbc +pat=^(b?)*?d$ +flg= +[end] + +[test149] +str=bc +pat=^(b??){2}bc$ +flg= +br0=bc +br1= +[end] + +[test150] +str=bbc +pat=^(b??){2}bc$ +flg= +br0=bbc +br1=b +[end] + +[test151] +str=bbbc +pat=^(b??){2}bc$ +flg= +br0=bbbc +br1=b +[end] + +[test152] +str=bbbbc +pat=^(b??){2}bc$ +flg= +[end] + +[test153] +str=bbbbc +pat=^(b??)*d$ +flg= +[end] + +[test154] +str=bc +pat=^(b??){2}?bc$ +flg= +br0=bc +br1= +[end] + +[test155] +str=bbc +pat=^(b??){2}?bc$ +flg= +br0=bbc +br1=b +[end] + +[test156] +str=bbbc +pat=^(b??){2}?bc$ +flg= +br0=bbbc +br1=b +[end] + +[test157] +str=bbbbc +pat=^(b??){2}?bc$ +flg= +[end] + +[test158] +str=bbbbc +pat=^(b??)*?d$ +flg= +[end] + +[test159] +str=bbc +pat=^(|||b)*bc$ +flg= +br0=bbc +br1= +[end] + +[test160] +str=bbc +pat=^(|||b)*?bc$ +flg= +br0=bbc +br1=b +[end] + +[test161] +str=foo +pat=\w?? +sub=<$&> +flg=g +res=<><f><><o><><o><> +br0= +br1=f +br2= +br3=o +br4= +br5=o +br6= +[end] + +[test161.sed] +str=foo +pat=\w?? +sub=<&> +flg=gd +res=<><f><><o><><o><> +br0= +br1=f +br2= +br3=o +br4= +br5=o +br6= +[end] + +[test162] +str=foo +pat=() +sub=<$&> +flg=g +res=<>f<>o<>o<> +br0= +br1= +br2= +br3= +br4= +br5= +br6= +br7= +[end] + +[test163] +str=foo +pat=()* +sub=<$&> +flg=g +res=<>f<>o<>o<> +br0= +br1= +br2= +br3= +br4= +br5= +br6= +br7= +[end] + +[test164] +str=1yzZ^aAc2 +pat=[Z-a]+ +flg=i +br0=zZ^aA +[end] + +[test165] +str=1yzZ^aAc2 +pat=[Z-a]+ +flg= +br0=Z^a +[end] + +[test166] +str=G +pat=f|(?i)g +flg= +br0=G +[end] + +[test167] +str=aBBa +pat=[[:lower:]]+ +flg=i +br0=aBBa +[end] + +[test168] +str=aA +pat=\x61+ +flg=i +br0=aA +[end] + +[test169] +str=aA +pat=[\x61]+ +flg=i +br0=aA +[end] + +[test170] +str=aA +pat=\u0061+ +flg=i +br0=aA +[end] + +[test171] +str=aA +pat=[\u0061]+ +flg=i +br0=aA +[end] + +; Test for backreferences over 9 +[test172] +str=hellohello +pat=()()()()()()()()()()()(hello)\12 +br0=hellohello +br1= +br2= +br3= +br4= +br5= +br6= +br7= +br8= +br9= +br10= +br11= +br12=hello +[end] + +; test for named captures +[test173] +str=hellohello +pat=(?P<this>he(ll)o)(?P=this) +br0=hellohello +br1=hello +br2=ll +[end] + +; test for named captures +[test174] +str=hellohello +pat=(?P<this>he(ll)o)(?P=this) +flg=p +sub=\u\g<this>, world +res=Hello, world +br0=hellohello +br1=hello +br2=ll +[end] + +; test for quantified, non-capturing groups, bug report +[test174] +str=cabba\nabba\ndaba\n +pat=^(c[^\r\n]*(?:\r?\n|\r)(?:(?!c)[^\r\n]*(?:\r?\n|\r))*) +flg= +br0=cabba\nabba\ndaba\n +br1=cabba\nabba\ndaba\n +[end] + +; tests pilfered from Boost.Regex test_tricky_cases.cpp + +[tricky1] +str=abc +pat=a(((b)))c +flg=g +br0=abc +br1=b +br2=b +br3=b +[end] + +[tricky2] +str=abd +pat=a(b|(c))d +flg=g +br0=abd +br1=b +br2= +[end] + +[tricky3] +str=acd +pat=a(b|(c))d +flg=g +br0=acd +br1=c +br2=c +[end] + +[tricky4] +str=abbd +pat=a(b*|c)d +flg=g +br0=abbd +br1=bb +[end] + +[tricky5] +str=aaaaabaaaabaaaabaaaab +pat=a[ab]{20} +flg=g +br0=aaaaabaaaabaaaabaaaab +[end] + +[tricky6] +str=aaaaabaaaabaaaabaaaab +pat=a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab] +flg=g +br0=aaaaabaaaabaaaabaaaab +[end] + +[tricky7] +str=aaaaabaaaabaaaabaaaabweeknights +pat=a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab](wee|week)(knights|night) +flg=g +br0=aaaaabaaaabaaaabaaaabweeknights +br1=wee +br2=knights +[end] + +[tricky8] +str=a1234567890123456789012345678901234567890123456789012345678901234567890b +pat=1234567890123456789012345678901234567890123456789012345678901234567890 +flg=g +br0=1234567890123456789012345678901234567890123456789012345678901234567890 +[end] + +[tricky9] +str=xacegikmoq +pat=[ab][cd][ef][gh][ij][kl][mn] +flg=g +br0=acegikm +[end] + +[tricky10] +str=xacegikmoq +pat=[ab][cd][ef][gh][ij][kl][mn][op] +flg=g +br0=acegikmo +[end] + +[tricky11] +str=xacegikmoqy +pat=[ab][cd][ef][gh][ij][kl][mn][op][qr] +flg=g +br0=acegikmoq +[end] + +[tricky12] +str=xacegikmoqy +pat=[ab][cd][ef][gh][ij][kl][mn][op][q] +flg=g +br0=acegikmoq +[end] + +[tricky13] +str=zabcdefghi +pat=(a)(b)(c)(d)(e)(f)(g)(h) +flg=g +br0=abcdefgh +br1=a +br2=b +br3=c +br4=d +br5=e +br6=f +br7=g +br8=h +[end] + +[tricky14] +str=zabcdefghij +pat=(a)(b)(c)(d)(e)(f)(g)(h)(i) +flg=g +br0=abcdefghi +br1=a +br2=b +br3=c +br4=d +br5=e +br6=f +br7=g +br8=h +br9=i +[end] + +[tricky15] +str=zabcdefghijk +pat=(a)(b)(c)(d)(e)(f)(g)(h)(i)(j) +flg=g +br0=abcdefghij +br1=a +br2=b +br3=c +br4=d +br5=e +br6=f +br7=g +br8=h +br9=i +br10=j +[end] + +[tricky16] +str=zabcdefghijkl +pat=(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k) +flg=g +br0=abcdefghijk +br1=a +br2=b +br3=c +br4=d +br5=e +br6=f +br7=g +br8=h +br9=i +br10=j +br11=k +[end] + +[tricky17] +str=abc +pat=(a)d|(b)c +flg=g +br0=bc +br1= +br2=b +[end] + +[tricky18] +str=_wwwnocolon _mailto: +pat=_+((www)|(ftp)|(mailto)):_* +flg=g +br0=_mailto: +br1=mailto +br2= +br3= +br4=mailto +[end] + +; Boost.Regex bug +[tricky19] +str=acd +pat=a(b)?c\1d +flg=g +;br0=acd +;br1= +[end] + +[tricky20] +str=accd +pat=a(b?c)+d +flg=g +br0=accd +br1=c +[end] + +[tricky21] +str=weeknights +pat=(wee|week)(knights|night) +flg=g +br0=weeknights +br1=wee +br2=knights +[end] + +[tricky22] +str=abc +pat=.* +flg=g +br0=abc +br1= +[end] + +[tricky23] +str=abd +pat=a(b|(c))d +flg=g +br0=abd +br1=b +br2= +[end] + +[tricky24] +str=acd +pat=a(b|(c))d +flg=g +br0=acd +br1=c +br2=c +[end] + +[tricky25] +str=abbd +pat=a(b*|c|e)d +flg=g +br0=abbd +br1=bb +[end] + +[tricky26] +str=acd +pat=a(b*|c|e)d +flg=g +br0=acd +br1=c +[end] + +[tricky27] +str=ad +pat=a(b*|c|e)d +flg=g +br0=ad +br1= +[end] + +[tricky28] +str=abc +pat=a(b?)c +flg=g +br0=abc +br1=b +[end] + +[tricky29] +str=ac +pat=a(b?)c +flg=g +br0=ac +br1= +[end] + +[tricky30] +str=abc +pat=a(b+)c +flg=g +br0=abc +br1=b +[end] + +[tricky31] +str=abbbc +pat=a(b+)c +flg=g +br0=abbbc +br1=bbb +[end] + +[tricky32] +str=ac +pat=a(b*)c +flg=g +br0=ac +br1= +[end] + +[tricky33] +str=abcdef +pat=(a|ab)(bc([de]+)f|cde) +flg=g +br0=abcdef +br1=a +br2=bcdef +br3=de +[end] + +[tricky34] +str=abc +pat=a([bc]?)c +flg=g +br0=abc +br1=b +[end] + +[tricky35] +str=ac +pat=a([bc]?)c +flg=g +br0=ac +br1= +[end] + +[tricky36] +str=abc +pat=a([bc]+)c +flg=g +br0=abc +br1=b +[end] + +[tricky37] +str=abcc +pat=a([bc]+)c +flg=g +br0=abcc +br1=bc +[end] + +[tricky38] +str=abcbc +pat=a([bc]+)bc +flg=g +br0=abcbc +br1=bc +[end] + +[tricky39] +str=abb +pat=a(bb+|b)b +flg=g +br0=abb +br1=b +[end] + +[tricky40] +str=abb +pat=a(bbb+|bb+|b)b +flg=g +br0=abb +br1=b +[end] + +[tricky41] +str=abbb +pat=a(bbb+|bb+|b)b +flg=g +br0=abbb +br1=bb +[end] + +[tricky42] +str=abbb +pat=a(bbb+|bb+|b)bb +flg=g +br0=abbb +br1=b +[end] + +[tricky43] +str=abcdef +pat=(.*).* +flg=g +br0=abcdef +br1=abcdef +br2= +br3= +[end] + +[tricky44] +str=bc +pat=(a*)* +flg=g +br0= +br1= +br2= +br3= +br4= +br5= +[end] + +[tricky45] +str=bc +pat=Z(((((((a+)+)+)+)+)+)+)+|Y(((((((a+)+)+)+)+)+)+)+|X(((((((a+)+)+)+)+)+)+)+|W(((((((a+)+)+)+)+)+)+)+|V(((((((a+)+)+)+)+)+)+)+|CZ(((((((a+)+)+)+)+)+)+)+|CY(((((((a+)+)+)+)+)+)+)+|CX(((((((a+)+)+)+)+)+)+)+|CW(((((((a+)+)+)+)+)+)+)+|CV(((((((a+)+)+)+)+)+)+)+|(a+)+ +flg=g +[end] + +[tricky46] +str=aaa +pat=Z(((((((a+)+)+)+)+)+)+)+|Y(((((((a+)+)+)+)+)+)+)+|X(((((((a+)+)+)+)+)+)+)+|W(((((((a+)+)+)+)+)+)+)+|V(((((((a+)+)+)+)+)+)+)+|CZ(((((((a+)+)+)+)+)+)+)+|CY(((((((a+)+)+)+)+)+)+)+|CX(((((((a+)+)+)+)+)+)+)+|CW(((((((a+)+)+)+)+)+)+)+|CV(((((((a+)+)+)+)+)+)+)+|(a+)+ +flg=g +br0=aaa +br1= +br2= +br3= +br4= +br5= +br6= +br7= +br8= +br9= +br10= +br11= +br12= +br13= +br14= +br15= +br16= +br17= +br18= +br19= +br20= +br21= +br22= +br23= +br24= +br25= +br26= +br27= +br28= +br29= +br30= +br31= +br32= +br33= +br34= +br35= +br36= +br37= +br38= +br39= +br40= +br41= +br42= +br43= +br44= +br45= +br46= +br47= +br48= +br49= +br50= +br51= +br52= +br53= +br54= +br55= +br56= +br57= +br58= +br59= +br60= +br61= +br62= +br63= +br64= +br65= +br66= +br67= +br68= +br69= +br70= +br71=aaa +[end] + +[tricky47] +str=Zaaa +pat=Z(((((((a+)+)+)+)+)+)+)+|Y(((((((a+)+)+)+)+)+)+)+|X(((((((a+)+)+)+)+)+)+)+|W(((((((a+)+)+)+)+)+)+)+|V(((((((a+)+)+)+)+)+)+)+|CZ(((((((a+)+)+)+)+)+)+)+|CY(((((((a+)+)+)+)+)+)+)+|CX(((((((a+)+)+)+)+)+)+)+|CW(((((((a+)+)+)+)+)+)+)+|CV(((((((a+)+)+)+)+)+)+)+|(a+)+ +flg=g +br0=Zaaa +br1=aaa +br2=aaa +br3=aaa +br4=aaa +br5=aaa +br6=aaa +br7=aaa +br8= +br9= +br10= +br11= +br12= +br13= +br14= +br15= +br16= +br17= +br18= +br19= +br20= +br21= +br22= +br23= +br24= +br25= +br26= +br27= +br28= +br29= +br30= +br31= +br32= +br33= +br34= +br35= +br36= +br37= +br38= +br39= +br40= +br41= +br42= +br43= +br44= +br45= +br46= +br47= +br48= +br49= +br50= +br51= +br52= +br53= +br54= +br55= +br56= +br57= +br58= +br59= +br60= +br61= +br62= +br63= +br64= +br65= +br66= +br67= +br68= +br69= +br70= +br71= +[end] + +[tricky48] +str=xyxxxxyxxxz +pat=xyx*xz +flg=g +br0=xyxxxz +[end] + +[tricky49] +str=ad +pat=a(b|c)*d +flg=g +br0=ad +br1= +[end] + +[tricky50] +str=abcd +pat=a(b|c)*d +flg=g +br0=abcd +br1=c +[end] + +[tricky51] +str=abd +pat=a(b|c)+d +flg=g +br0=abd +br1=b +[end] + +[tricky52] +str=abcd +pat=a(b|c)+d +flg=g +br0=abcd +br1=c +[end] + +[tricky53] +str=ad +pat=a(b|c?)+d +flg=g +br0=ad +br1= +[end] + +[tricky54] +str=ad +pat=a(b|c){0,0}d +flg=g +br0=ad +br1= +[end] + +[tricky55] +str=ad +pat=a(b|c){0,1}d +flg=g +br0=ad +br1= +[end] + +[tricky56] +str=abd +pat=a(b|c){0,1}d +flg=g +br0=abd +br1=b +[end] + +[tricky57] +str=ad +pat=a(b|c){0,2}d +flg=g +br0=ad +br1= +[end] + +[tricky58] +str=abcd +pat=a(b|c){0,2}d +flg=g +br0=abcd +br1=c +[end] + +[tricky59] +str=ad +pat=a(b|c){0,}d +flg=g +br0=ad +br1= +[end] + +[tricky60] +str=abcd +pat=a(b|c){0,}d +flg=g +br0=abcd +br1=c +[end] + +[tricky61] +str=abd +pat=a(b|c){1,1}d +flg=g +br0=abd +br1=b +[end] + +[tricky62] +str=abd +pat=a(b|c){1,2}d +flg=g +br0=abd +br1=b +[end] + +[tricky63] +str=abcd +pat=a(b|c){1,2}d +flg=g +br0=abcd +br1=c +[end] + +[tricky64] +str=abd +pat=a(b|c){1,}d +flg=g +br0=abd +br1=b +[end] + +[tricky65] +str=abcd +pat=a(b|c){1,}d +flg=g +br0=abcd +br1=c +[end] + +[tricky66] +str=acbd +pat=a(b|c){2,2}d +flg=g +br0=acbd +br1=b +[end] + +[tricky67] +str=abcd +pat=a(b|c){2,2}d +flg=g +br0=abcd +br1=c +[end] + +[tricky68] +str=abcd +pat=a(b|c){2,4}d +flg=g +br0=abcd +br1=c +[end] + +[tricky69] +str=abcbd +pat=a(b|c){2,4}d +flg=g +br0=abcbd +br1=b +[end] + +[tricky70] +str=abcbcd +pat=a(b|c){2,4}d +flg=g +br0=abcbcd +br1=c +[end] + +[tricky71] +str=abcd +pat=a(b|c){2,}d +flg=g +br0=abcd +br1=c +[end] + +[tricky72] +str=abcbd +pat=a(b|c){2,}d +flg=g +br0=abcbd +br1=b +[end] + +[tricky73] +str=abc +pat=a(((b)))c +flg=g +br0=abc +br1=b +br2=b +br3=b +[end] + +[tricky74] +str=abd +pat=a(b|(c))d +flg=g +br0=abd +br1=b +br2= +[end] + +[tricky75] +str=acd +pat=a(b|(c))d +flg=g +br0=acd +br1=c +br2=c +[end] + +[tricky76] +str=abbd +pat=a(b*|c)d +flg=g +br0=abbd +br1=bb +[end] + +[tricky77] +str=aaaaabaaaabaaaabaaaab +pat=a[ab]{20} +flg=g +br0=aaaaabaaaabaaaabaaaab +[end] + +[tricky78] +str=aaaaabaaaabaaaabaaaab +pat=a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab] +flg=g +br0=aaaaabaaaabaaaabaaaab +[end] + +[tricky79] +str=aaaaabaaaabaaaabaaaabweeknights +pat=a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab](wee|week)(knights|night) +flg=g +br0=aaaaabaaaabaaaabaaaabweeknights +br1=wee +br2=knights +[end] + +[tricky80] +str=a1234567890123456789012345678901234567890123456789012345678901234567890b +pat=1234567890123456789012345678901234567890123456789012345678901234567890 +flg=g +br0=1234567890123456789012345678901234567890123456789012345678901234567890 +[end] + +[tricky81] +str=xacegikmoq +pat=[ab][cd][ef][gh][ij][kl][mn] +flg=g +br0=acegikm +[end] + +[tricky82] +str=xacegikmoq +pat=[ab][cd][ef][gh][ij][kl][mn][op] +flg=g +br0=acegikmo +[end] + +[tricky83] +str=xacegikmoqy +pat=[ab][cd][ef][gh][ij][kl][mn][op][qr] +flg=g +br0=acegikmoq +[end] + +[tricky84] +str=xacegikmoqy +pat=[ab][cd][ef][gh][ij][kl][mn][op][q] +flg=g +br0=acegikmoq +[end] + +[tricky85] +str=zabcdefghi +pat=(a)(b)(c)(d)(e)(f)(g)(h) +flg=g +br0=abcdefgh +br1=a +br2=b +br3=c +br4=d +br5=e +br6=f +br7=g +br8=h +[end] + +[tricky86] +str=zabcdefghij +pat=(a)(b)(c)(d)(e)(f)(g)(h)(i) +flg=g +br0=abcdefghi +br1=a +br2=b +br3=c +br4=d +br5=e +br6=f +br7=g +br8=h +br9=i +[end] + +[tricky87] +str=zabcdefghijk +pat=(a)(b)(c)(d)(e)(f)(g)(h)(i)(j) +flg=g +br0=abcdefghij +br1=a +br2=b +br3=c +br4=d +br5=e +br6=f +br7=g +br8=h +br9=i +br10=j +[end] + +[tricky88] +str=zabcdefghijkl +pat=(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k) +flg=g +br0=abcdefghijk +br1=a +br2=b +br3=c +br4=d +br5=e +br6=f +br7=g +br8=h +br9=i +br10=j +br11=k +[end] + +[tricky89] +str=abc +pat=(a)d|(b)c +flg=g +br0=bc +br1= +br2=b +[end] + +[tricky90] +str=_wwwnocolon _mailto: +pat=_+((www)|(ftp)|(mailto)):_* +flg=g +br0=_mailto: +br1=mailto +br2= +br3= +br4=mailto +[end] + +[tricky91] +str=accd +pat=a(b?c)+d +flg=g +br0=accd +br1=c +[end] + +[tricky92] +str=weeknights +pat=(wee|week)(knights|night) +flg=g +br0=weeknights +br1=wee +br2=knights +[end] + +[tricky93] +str=abc +pat=.* +flg=g +br0=abc +br1= +[end] + +[tricky94] +str=abd +pat=a(b|(c))d +flg=g +br0=abd +br1=b +br2= +[end] + +[tricky95] +str=acd +pat=a(b|(c))d +flg=g +br0=acd +br1=c +br2=c +[end] + +[tricky96] +str=abbd +pat=a(b*|c|e)d +flg=g +br0=abbd +br1=bb +[end] + +[tricky97] +str=acd +pat=a(b*|c|e)d +flg=g +br0=acd +br1=c +[end] + +[tricky98] +str=ad +pat=a(b*|c|e)d +flg=g +br0=ad +br1= +[end] + +[tricky99] +str=abc +pat=a(b?)c +flg=g +br0=abc +br1=b +[end] + +[tricky100] +str=ac +pat=a(b?)c +flg=g +br0=ac +br1= +[end] + +[tricky101] +str=abc +pat=a(b+)c +flg=g +br0=abc +br1=b +[end] + +[tricky102] +str=abbbc +pat=a(b+)c +flg=g +br0=abbbc +br1=bbb +[end] + +[tricky103] +str=ac +pat=a(b*)c +flg=g +br0=ac +br1= +[end] + +[tricky104] +str=abcdef +pat=(a|ab)(bc([de]+)f|cde) +flg=g +br0=abcdef +br1=a +br2=bcdef +br3=de +[end] + +[tricky105] +str=abc +pat=a([bc]?)c +flg=g +br0=abc +br1=b +[end] + +[tricky106] +str=ac +pat=a([bc]?)c +flg=g +br0=ac +br1= +[end] + +[tricky107] +str=abc +pat=a([bc]+)c +flg=g +br0=abc +br1=b +[end] + +[tricky108] +str=abcc +pat=a([bc]+)c +flg=g +br0=abcc +br1=bc +[end] + +[tricky109] +str=abcbc +pat=a([bc]+)bc +flg=g +br0=abcbc +br1=bc +[end] + +[tricky110] +str=abb +pat=a(bb+|b)b +flg=g +br0=abb +br1=b +[end] + +[tricky111] +str=abb +pat=a(bbb+|bb+|b)b +flg=g +br0=abb +br1=b +[end] + +[tricky112] +str=abbb +pat=a(bbb+|bb+|b)b +flg=g +br0=abbb +br1=bb +[end] + +[tricky113] +str=abbb +pat=a(bbb+|bb+|b)bb +flg=g +br0=abbb +br1=b +[end] + +[tricky114] +str=abcdef +pat=(.*).* +flg=g +br0=abcdef +br1=abcdef +br2= +br3= +[end] + +[tricky115] +str=bc +pat=(a*)* +flg=g +br0= +br1= +br2= +br3= +br4= +br5= +[end] + +[tricky116] +str=xyxxxxyxxxz +pat=xyx*xz +flg=g +br0=xyxxxz +[end] + +[tricky117] +str=ad +pat=a(b|c)*d +flg=g +br0=ad +br1= +[end] + +[tricky118] +str=abcd +pat=a(b|c)*d +flg=g +br0=abcd +br1=c +[end] + +[tricky119] +str=abd +pat=a(b|c)+d +flg=g +br0=abd +br1=b +[end] + +[tricky120] +str=abcd +pat=a(b|c)+d +flg=g +br0=abcd +br1=c +[end] + +[tricky121] +str=ad +pat=a(b|c?)+d +flg=g +br0=ad +br1= +[end] + +[tricky122] +str=ad +pat=a(b|c){0,0}d +flg=g +br0=ad +br1= +[end] + +[tricky123] +str=ad +pat=a(b|c){0,1}d +flg=g +br0=ad +br1= +[end] + +[tricky124] +str=abd +pat=a(b|c){0,1}d +flg=g +br0=abd +br1=b +[end] + +[tricky125] +str=ad +pat=a(b|c){0,2}d +flg=g +br0=ad +br1= +[end] + +[tricky126] +str=abcd +pat=a(b|c){0,2}d +flg=g +br0=abcd +br1=c +[end] + +[tricky127] +str=ad +pat=a(b|c){0,}d +flg=g +br0=ad +br1= +[end] + +[tricky128] +str=abcd +pat=a(b|c){0,}d +flg=g +br0=abcd +br1=c +[end] + +[tricky129] +str=abd +pat=a(b|c){1,1}d +flg=g +br0=abd +br1=b +[end] + +[tricky130] +str=abd +pat=a(b|c){1,2}d +flg=g +br0=abd +br1=b +[end] + +[tricky131] +str=abcd +pat=a(b|c){1,2}d +flg=g +br0=abcd +br1=c +[end] + +[tricky132] +str=abd +pat=a(b|c){1,}d +flg=g +br0=abd +br1=b +[end] + +[tricky133] +str=abcd +pat=a(b|c){1,}d +flg=g +br0=abcd +br1=c +[end] + +[tricky134] +str=acbd +pat=a(b|c){2,2}d +flg=g +br0=acbd +br1=b +[end] + +[tricky135] +str=abcd +pat=a(b|c){2,2}d +flg=g +br0=abcd +br1=c +[end] + +[tricky136] +str=abcd +pat=a(b|c){2,4}d +flg=g +br0=abcd +br1=c +[end] + +[tricky137] +str=abcbd +pat=a(b|c){2,4}d +flg=g +br0=abcbd +br1=b +[end] + +[tricky138] +str=abcbcd +pat=a(b|c){2,4}d +flg=g +br0=abcbcd +br1=c +[end] + +[tricky139] +str=abcd +pat=a(b|c){2,}d +flg=g +br0=abcd +br1=c +[end] + +[tricky140] +str=abcbd +pat=a(b|c){2,}d +flg=g +br0=abcbd +br1=b +[end] + +[tricky141] +str=abcd +pat=a(b|c?)+d +flg=g +br0=abcd +br1= +[end] + +[tricky142] +str=abd +pat=a(b+|((c)*))+d +flg=g +br0=abd +br1= +br2= +br3= +[end] + +; Boost.Regex bug +[tricky143] +str=abcd +pat=a(b+|((c)*))+d +flg=g +br0=abcd +br1= +br2= +;br3=c +br3= +[end] + +; Boost.Regex bug +[tricky144] +str=abcd +pat=a(b|c?)+d +flg=g +br0=abcd +;br1=c +br1= +[end] + +; Boost.Regex bug +[tricky145] +str=abcd +pat=a(b|((c)*))+d +flg=g +br0=abcd +;br1=c +;br2=c +;br3=c +br1= +br2= +br3= +[end] + +; Boost.Regex bug +[tricky146] +str=abd +pat=a(b+|((c)*))+d +flg=g +br0=abd +;br1=b +br1= +br2= +br3= +[end] + +; Boost.Regex bug +[tricky147] +str=abcd +pat=a(b+|((c)*))+d +flg=g +br0=abcd +;br1=c +;br2=c +;br3=c +br1= +br2= +br3= +[end] + +[tricky148] +str=++i //here is a line comment\n +pat=//[^\n]* +flg=g +br0=//here is a line comment +[end] + +[tricky149] +str=/* here is a block comment */ +pat=/\*([^*]|\*+[^*/])*\*+/ +flg=g +br0=/* here is a block comment */ +br1= +[end] + +[tricky150] +str=/**/ +pat=/\*([^*]|\*+[^*/])*\*+/ +flg=g +br0=/**/ +br1= +[end] + +[tricky151] +str=/***/ +pat=/\*([^*]|\*+[^*/])*\*+/ +flg=g +br0=/***/ +br1= +[end] + +[tricky152] +str=/****/ +pat=/\*([^*]|\*+[^*/])*\*+/ +flg=g +br0=/****/ +br1= +[end] + +[tricky153] +str=/*****/ +pat=/\*([^*]|\*+[^*/])*\*+/ +flg=g +br0=/*****/ +br1= +[end] + +[tricky154] +str=/*****/*/ +pat=/\*([^*]|\*+[^*/])*\*+/ +flg=g +br0=/*****/ +br1= +[end] + +[tricky155] +str=#define some_symbol +pat=^[[:blank:]]*#([^\n]*\\[[:space:]]+)*[^\n]* +flg=g +br0=#define some_symbol +br1= +[end] + +[tricky156] +str=#define some_symbol(x) #x +pat=^[[:blank:]]*#([^\n]*\\[[:space:]]+)*[^\n]* +flg=g +br0=#define some_symbol(x) #x +br1= +[end] + +[tricky157] +str=#define some_symbol(x) \\ \r\n foo();\\\r\n printf(#x); +pat=^[[:blank:]]*#([^\n]*\\[[:space:]]+)*[^\n]* +flg=g +br0=#define some_symbol(x) \\ \r\n foo();\\\r\n printf(#x); +br1=foo();\\\r\n +[end] + +[tricky158] +str=aaaabab +pat=(aaa)(ab)* +flg=g +br0=aaaabab +br1=aaa +br2=ab +[end] + +[tricky159] +str=0xFF +pat=((0x[[:xdigit:]]+)|([[:digit:]]+))u?((int(8|16|32|64))|L)? +flg=g +br0=0xFF +br1=0xFF +br2=0xFF +br3= +br4= +br5= +br6= +[end] + +[tricky160] +str=35 +pat=((0x[[:xdigit:]]+)|([[:digit:]]+))u?((int(8|16|32|64))|L)? +flg=g +br0=35 +br1=35 +br2= +br3=35 +br4= +br5= +br6= +[end] + +[tricky161] +str=0xFFu +pat=((0x[[:xdigit:]]+)|([[:digit:]]+))u?((int(8|16|32|64))|L)? +flg=g +br0=0xFFu +br1=0xFF +br2=0xFF +br3= +br4= +br5= +br6= +[end] + +[tricky162] +str=0xFFL +pat=((0x[[:xdigit:]]+)|([[:digit:]]+))u?((int(8|16|32|64))|L)? +flg=g +br0=0xFFL +br1=0xFF +br2=0xFF +br3= +br4=L +br5= +br6= +[end] + +[tricky163] +str=0xFFFFFFFFFFFFFFFFuint64 +pat=((0x[[:xdigit:]]+)|([[:digit:]]+))u?((int(8|16|32|64))|L)? +flg=g +br0=0xFFFFFFFFFFFFFFFFuint64 +br1=0xFFFFFFFFFFFFFFFF +br2=0xFFFFFFFFFFFFFFFF +br3= +br4=int64 +br5=int64 +br6=64 +[end] + +[tricky164] +str='\\x3A' +pat='([^\\']|\\.)*' +flg=g +br0='\\x3A' +br1=A +[end] + +[tricky165] +str='\\'' +pat='([^\\']|\\.)*' +flg=g +br0='\\'' +br1=\\' +[end] + +[tricky166] +str='\\n' +pat='([^\\']|\\.)*' +flg=g +br0='\\n' +br1=\\n +[end] + +[tricky167] +str=0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|} +pat=0123456789@abcdefghijklmnopqrstuvwxyz\[\\\]\^_`ABCDEFGHIJKLMNOPQRSTUVWXYZ\{\|\} +flg=gi +br0=0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|} +[end] + +[tricky168] +str=A +pat=a +flg=gi +br0=A +[end] + +[tricky169] +str=a +pat=A +flg=gi +br0=a +[end] + +[tricky170] +str=abcABC +pat=[abc]+ +flg=gi +br0=abcABC +[end] + +[tricky171] +str=abcABC +pat=[ABC]+ +flg=gi +br0=abcABC +[end] + +[tricky172] +str=abcABC +pat=[a-z]+ +flg=gi +br0=abcABC +[end] + +[tricky173] +str=abzANZ +pat=[A-Z]+ +flg=gi +br0=abzANZ +[end] + +; Boost.Regex bug +;[tricky174] +;str=abzABZ +;pat=[a-Z]+ +;flg=gi +;br0=abzABZ +;[end] + +[tricky175] +str=abzABZ +pat=[A-z]+ +flg=gi +br0=abzABZ +[end] + +[tricky176] +str=abyzABYZ +pat=[[:lower:]]+ +flg=gi +br0=abyzABYZ +[end] + +[tricky177] +str=abzABZ +pat=[[:upper:]]+ +flg=gi +br0=abzABZ +[end] + +[tricky178] +str=abcZZZ +pat=\w+ +flg=gi +br0=abcZZZ +[end] + +[tricky179] +str=abyzABYZ +pat=[[:alpha:]]+ +flg=gi +br0=abyzABYZ +[end] + +[tricky180] +str=09abyzABYZ +pat=[[:alnum:]]+ +flg=gi +br0=09abyzABYZ +[end] + +[tricky181] +str=( +pat=\( +flg=g +br0=( +[end] + +[tricky182] +str=) +pat=\) +flg=g +br0=) +[end] + +[tricky183] +str=$ +pat=\$ +flg=g +br0=$ +[end] + +[tricky184] +str=^ +pat=\^ +flg=g +br0=^ +[end] + +[tricky185] +str=. +pat=\. +flg=g +br0=. +[end] + +[tricky186] +str=* +pat=\* +flg=g +br0=* +[end] + +[tricky187] +str=+ +pat=\+ +flg=g +br0=+ +[end] + +[tricky188] +str=? +pat=\? +flg=g +br0=? +[end] + +[tricky189] +str=[ +pat=\[ +flg=g +br0=[ +[end] + +[tricky190] +str=] +pat=\] +flg=g +br0=] +[end] + +[tricky191] +str=| +pat=\| +flg=g +br0=| +[end] + +[tricky192] +str=\\ +pat=\\ +flg=g +br0=\ +[end] + +[tricky193] +str=# +pat=# +flg=g +br0=# +[end] + +[tricky194] +str=# +pat=\# +flg=g +br0=# +[end] + +[tricky195] +str=a- +pat=a- +flg=g +br0=a- +[end] + +[tricky196] +str=- +pat=\- +flg=g +br0=- +[end] + +[tricky197] +str={ +pat=\{ +flg=g +br0={ +[end] + +[tricky198] +str=} +pat=\} +flg=g +br0=} +[end] + +[tricky199] +str=0 +pat=0 +flg=g +br0=0 +[end] + +[tricky200] +str=1 +pat=1 +flg=g +br0=1 +[end] + +[tricky201] +str=9 +pat=9 +flg=g +br0=9 +[end] + +[tricky202] +str=b +pat=b +flg=g +br0=b +[end] + +[tricky203] +str=B +pat=B +flg=g +br0=B +[end] + +[tricky204] +str=< +pat=< +flg=g +br0=< +[end] + +[tricky205] +str=> +pat=> +flg=g +br0=> +[end] + +[tricky206] +str=w +pat=w +flg=g +br0=w +[end] + +[tricky207] +str=W +pat=W +flg=g +br0=W +[end] + +[tricky208] +str=` +pat=` +flg=g +br0=` +[end] + +[tricky209] +str= +pat= +flg=g +br0= +[end] + +[tricky210] +str=\n +pat=\n +flg=g +br0=\n +[end] + +[tricky211] +str=, +pat=, +flg=g +br0=, +[end] + +[tricky212] +str=a +pat=a +flg=g +br0=a +[end] + +[tricky213] +str=f +pat=f +flg=g +br0=f +[end] + +[tricky214] +str=n +pat=n +flg=g +br0=n +[end] + +[tricky215] +str=r +pat=r +flg=g +br0=r +[end] + +[tricky216] +str=t +pat=t +flg=g +br0=t +[end] + +[tricky217] +str=v +pat=v +flg=g +br0=v +[end] + +[tricky218] +str=c +pat=c +flg=g +br0=c +[end] + +[tricky219] +str=x +pat=x +flg=g +br0=x +[end] + +[tricky220] +str=: +pat=: +flg=g +br0=: +[end] + +[tricky221] +str=w.a.b +pat=(\.[[:alnum:]]+){2} +flg=g +br0=.a.b +br1=.b +[end] + +[tricky222] +str=foobar +pat=(?!foo)bar +flg=g +br0=bar +[end] + +[tricky223] +str=??bar +pat=(?!foo)bar +flg=g +br0=bar +[end] + +[tricky224] +str=barfoo +pat=(?!foo)bar +flg=g +br0=bar +[end] + +[tricky225] +str=bar?? +pat=(?!foo)bar +flg=g +br0=bar +[end] + +[tricky226] +str=bar +pat=(?!foo)bar +flg=g +br0=bar +[end] + +[tricky227] +str=a\nb +pat=a\Z +flg=g +[end] + +[tricky228] +str=abc +pat=() +flg=g +br0= +br1= +br2= +br3= +br4= +br5= +br6= +br7= +[end] + +[tricky229] +str=abc +pat=^() +flg=g +br0= +br1= +[end] + +[tricky230] +str=abc +pat=^()+ +flg=g +br0= +br1= +[end] + +[tricky231] +str=abc +pat=^(){1} +flg=g +br0= +br1= +[end] + +[tricky232] +str=abc +pat=^(){2} +flg=g +br0= +br1= +[end] + +[tricky233] +str=abc +pat=^((){2}) +flg=g +br0= +br1= +br2= +[end] + +[tricky234] +str=a +pat=()\1 +flg=g +br0= +br1= +br2= +br3= +[end] + +[tricky235] +str=ab +pat=a()\1b +flg=g +br0=ab +br1= +[end] + +[tricky236] +str=ab +pat=a()b\1 +flg=g +br0=ab +br1= +[end] + +[tricky237] +str=abcbc +pat=([a-c]+)\1 +flg=g +br0=bcbc +br1=bc +[end] + +[tricky238] +str=xxxxxxxxyyyyyyyyab +pat=.+abc +flg=g +[end] + +[tricky239] +str=abcdxxxyyyxxxyyy +pat=(.+)\1 +flg=g +br0=xxxyyyxxxyyy +br1=xxxyyy +[end] + +[tricky240] +str=___________________________________________x +pat=[_]+$ +flg=g +[end] + +;[tricky241] +;str=abcXYZ +;pat=\l+ +;flg=gi +;br0=abcXYZ +;[end] + +;[tricky242] +;str=abcXYZ +;pat=\u+ +;flg=gi +;br0=abcXYZ +;[end] + +; Boost.Regex bug +[tricky243] +str=abcd +pat=a(b|(((c))*))+d +flg=g +br0=abcd +;br1=c +;br2=c +;br3=c +br1= +br2= +br3= +br4=c +[end] + +[replace1] +str=acab +pat=(a(c)?)|(b) +flg=iga +sub=(?1(?2(C:):A):B:) +res=C:AB: +br0=ac +br1=ac +br2=c +br3= +br4=a +br5=a +br6= +br7= +br8=b +br9= +br10= +br11=b +[end] + +[track2157.1] +str=abc\ndef\nghi +pat=^.+$ +flg=m +br0=abc +[end] + +[track2157.2] +str=abc\ndef\nghi +pat=.$ +flg=m +br0=c +[end] + +[track2157.3] +str=abc\ndef\nghi +pat=^.+$ +flg= +[end] + +[track2157.4] +str=abc\ndef\nghi +pat=.$ +flg= +br0=i +[end] + +[track2157.5] +str=abc\r\ndef\r\nghi +pat=^.+$ +flg=m +br0=abc +[end] + +[track2157.6] +str=abc\r\ndef\r\nghi +pat=.$ +flg=m +br0=c +[end] + +[nocasealternate] +str=common HighLight and Blow this +pat=highlight|blow +flg=ig +sub=<b>$&</b> +res=common <b>HighLight</b> and <b>Blow</b> this +br0=HighLight +br1=Blow +[end] + +[track2296] +str=> "" +pat=(?P<f>.+):(?P<l>[0-9]+):((?P<c>[0-9]+):)?.* +flg= +[end] diff --git a/src/boost/libs/xpressive/test/regress_u.cpp b/src/boost/libs/xpressive/test/regress_u.cpp new file mode 100644 index 00000000..7d15bfbc --- /dev/null +++ b/src/boost/libs/xpressive/test/regress_u.cpp @@ -0,0 +1,15 @@ +////////////////////////////////////////////////////////////////////////////// +// regress_u.cpp +// +// (C) Copyright Eric Niebler 2004. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +/* + Revision history: + 6 January 2006 : Initial version. +*/ + +#define BOOST_XPRESSIVE_TEST_WREGEX +#include "./regress.ipp" diff --git a/src/boost/libs/xpressive/test/test.hpp b/src/boost/libs/xpressive/test/test.hpp new file mode 100644 index 00000000..d4b3deae --- /dev/null +++ b/src/boost/libs/xpressive/test/test.hpp @@ -0,0 +1,184 @@ +/////////////////////////////////////////////////////////////////////////////// +// test.hpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_XPRESSIVE_TEST_TEST_HPP_EAN_10_04_2005 +#define BOOST_XPRESSIVE_TEST_TEST_HPP_EAN_10_04_2005 + +// MS compatible compilers support #pragma once +#if defined(_MSC_VER) +# pragma once +#endif + +#include <string> +#include <vector> +#include <cstdio> +#include <cstdarg> +#include <functional> +#include <boost/range/iterator_range.hpp> +#include <boost/xpressive/xpressive_static.hpp> +#include <boost/test/unit_test.hpp> + +using namespace boost::unit_test; +using namespace boost::xpressive; + +#define L(x) BOOST_XPR_CSTR_(char_type, x) + +#define BOOST_XPR_CHECK(pred) \ + if( pred ) {} else { BOOST_ERROR( this->section_ << " : " << #pred ); } + +using namespace boost::xpressive; + +/////////////////////////////////////////////////////////////////////////////// +// backrefs +// +#if defined(__cplusplus_cli) +#pragma managed(push, off) +#endif +template<typename Char> +inline std::vector<std::basic_string<Char> > backrefs(Char const *br0, ...) +{ + using namespace std; + std::vector<std::basic_string<Char> > backrefs; + if(0 != br0) + { + backrefs.push_back(br0); + va_list va; + va_start(va, br0); + Char const *brN; + while(0 != (brN = va_arg(va, Char const *))) + { + backrefs.push_back(brN); + } + va_end(va); + } + return backrefs; +} +#if defined(__cplusplus_cli) +#pragma managed(pop) +#endif + +/////////////////////////////////////////////////////////////////////////////// +// +struct no_match_t {}; +no_match_t const no_match = {}; + +/////////////////////////////////////////////////////////////////////////////// +// xpr_test_case +// +template<typename BidiIter> +struct xpr_test_case +{ + typedef BidiIter iterator_type; + typedef typename boost::iterator_value<iterator_type>::type char_type; + typedef basic_regex<iterator_type> regex_type; + typedef std::basic_string<char_type> string_type; + typedef std::vector<string_type> backrefs_type; + + xpr_test_case(std::string section, string_type str, regex_type rex, backrefs_type brs) + : section_(section) + , str_(str) + , rex_(rex) + , brs_(brs) + { + } + + xpr_test_case(std::string section, string_type str, regex_type rex, no_match_t) + : section_(section) + , str_(str) + , rex_(rex) + , brs_() + { + } + + void run() const + { + char_type const empty[] = {0}; + match_results<BidiIter> what; + if(regex_search(this->str_, what, this->rex_)) + { + // match succeeded: was it expected to succeed? + BOOST_XPR_CHECK(what.size() == this->brs_.size()); + + for(std::size_t i = 0; i < what.size() && i < this->brs_.size(); ++i) + { + BOOST_XPR_CHECK((!what[i].matched && this->brs_[i] == empty) || this->brs_[i] == what[i].str()); + } + } + else + { + // match failed: was it expected to fail? + BOOST_XPR_CHECK(0 == this->brs_.size()); + } + } + +private: + + std::string section_; + string_type str_; + regex_type rex_; + std::vector<string_type> brs_; +}; + +/////////////////////////////////////////////////////////////////////////////// +// test_runner +template<typename BidiIter> +struct test_runner +{ + typedef xpr_test_case<BidiIter> argument_type; + typedef void result_type; + + void operator ()(xpr_test_case<BidiIter> const &test) const + { + test.run(); + } +}; + +/////////////////////////////////////////////////////////////////////////////// +// helpful debug routines +/////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +// remove all occurances of sz from str +inline void string_remove(std::string &str, char const *sz) +{ + std::string::size_type i = 0, n = std::strlen(sz); + while(std::string::npos != (i=str.find(sz,i))) + { + str.erase(i,n); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// display_type2 +// for type T, write typeid::name after performing some substitutions +template<typename T> +inline void display_type2() +{ + std::string str = typeid(T).name(); + + string_remove(str, "struct "); + string_remove(str, "boost::"); + string_remove(str, "xpressive::"); + string_remove(str, "detail::"); + string_remove(str, "fusion::"); + + //std::printf("%s\n\n", str.c_str()); + std::printf("%s\nwdith=%d\nuse_simple_repeat=%s\n\n", str.c_str() + , detail::width_of<T, char>::value + , detail::use_simple_repeat<T, char>::value ? "true" : "false"); +} + +/////////////////////////////////////////////////////////////////////////////// +// display_type +// display the type of the deduced template argument +template<typename T> +inline void display_type(T const &) +{ + display_type2<T>(); +} + +#endif diff --git a/src/boost/libs/xpressive/test/test1.cpp b/src/boost/libs/xpressive/test/test1.cpp new file mode 100644 index 00000000..f272ee18 --- /dev/null +++ b/src/boost/libs/xpressive/test/test1.cpp @@ -0,0 +1,29 @@ +/////////////////////////////////////////////////////////////////////////////// +// test1.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <algorithm> +#include "./test1.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// read the tests from the input file and execute them +void test_main() +{ + typedef std::string::const_iterator iterator_type; + boost::iterator_range<xpr_test_case<iterator_type> const *> rng = get_test_cases<iterator_type>(); + std::for_each(rng.begin(), rng.end(), test_runner<iterator_type>()); +} + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test1"); + test->add(BOOST_TEST_CASE(&test_main)); + return test; +} diff --git a/src/boost/libs/xpressive/test/test1.hpp b/src/boost/libs/xpressive/test/test1.hpp new file mode 100644 index 00000000..4eebdcdb --- /dev/null +++ b/src/boost/libs/xpressive/test/test1.hpp @@ -0,0 +1,139 @@ +/////////////////////////////////////////////////////////////////////////////// +// test1.h +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include "./test.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// get_test_cases +// +template<typename BidiIterT> +boost::iterator_range<xpr_test_case<BidiIterT> const *> get_test_cases() +{ + typedef typename boost::iterator_value<BidiIterT>::type char_type; + typedef xpr_test_case<BidiIterT> xpr_test_case; + typedef basic_regex<BidiIterT> regex_type; + + static char_type const *nilbr = 0; + static xpr_test_case const test_cases[] = + { + xpr_test_case + ( + "test1" + , L("foobarboo") + , regex_type(as_xpr(L("foo"))) + , backrefs(L("foo"), nilbr) + ) + , xpr_test_case + ( + "test2" + , L("foobarboo") + , regex_type(as_xpr(L("bar"))) + , backrefs(L("bar"), nilbr) + ) + , xpr_test_case + ( + "test3" + , L("foobarboo") + , regex_type(as_xpr(L("bat"))) + , no_match + ) + , xpr_test_case + ( + "test4" + , L("foobarboo") + , regex_type(L('b') >> *_ >> L("ar")) + , backrefs(L("bar"), nilbr) + ) + , xpr_test_case + ( + "test5" + , L("foobarboo") + , regex_type(L('b') >> *_ >> L('r')) + , backrefs(L("bar"), nilbr) + ) + , xpr_test_case + ( + "test6" + , L("foobarboo") + , regex_type(L('b') >> *_ >> L('b')) + , backrefs(L("barb"), nilbr) + ) + , xpr_test_case + ( + "test7" + , L("foobarboo") + , regex_type(L('b') >> *_ >> L('o')) + , backrefs(L("barboo"), nilbr) + ) + , xpr_test_case + ( + "test8" + , L("foobarboo") + , regex_type(L('b') >> *_ >> L("oo")) + , backrefs(L("barboo"), nilbr) + ) + , xpr_test_case + ( + "test9" + , L("foobarboo") + , regex_type(L('b') >> +_ >> L("ar")) + , no_match + ) + , xpr_test_case + ( + "test10" + , L("foobarboo") + , regex_type(L('b') >> +_ >> L('r')) + , backrefs(L("bar"), nilbr) + ) + , xpr_test_case + ( + "test11" + , L("foobarboo") + , regex_type(L('b') >> +_ >> L('b')) + , backrefs(L("barb"), nilbr) + ) + , xpr_test_case + ( + "test12" + , L("foobarboo") + , regex_type(L('b') >> +_ >> L('o')) + , backrefs(L("barboo"), nilbr) + ) + , xpr_test_case + ( + "test13" + , L("foobarboo") + , regex_type(L('b') >> +_ >> L("oo")) + , backrefs(L("barboo"), nilbr) + ) + , xpr_test_case + ( + "test14" + , L("foobarboo") + , regex_type(bos >> L("foo")) + , backrefs(L("foo"), nilbr) + ) + , xpr_test_case + ( + "test15" + , L("foobarboo") + , regex_type(bos >> L('b') >> *_ >> L("ar")) + , no_match + ) + , xpr_test_case + ( + "test15.1" + , L("fOo") + , regex_type(!icase(L('f') >> *as_xpr(L('o')))) + , backrefs(L("fOo"), nilbr) + ) + }; + + return boost::make_iterator_range(test_cases); +} + diff --git a/src/boost/libs/xpressive/test/test10.cpp b/src/boost/libs/xpressive/test/test10.cpp new file mode 100644 index 00000000..a6281a28 --- /dev/null +++ b/src/boost/libs/xpressive/test/test10.cpp @@ -0,0 +1,29 @@ +/////////////////////////////////////////////////////////////////////////////// +// test10.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <algorithm> +#include "./test10.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// read the tests from the input file and execute them +void test_main() +{ + typedef std::string::const_iterator iterator_type; + boost::iterator_range<xpr_test_case<iterator_type> const *> rng = get_test_cases<iterator_type>(); + std::for_each(rng.begin(), rng.end(), test_runner<iterator_type>()); +} + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test10"); + test->add(BOOST_TEST_CASE(&test_main)); + return test; +} diff --git a/src/boost/libs/xpressive/test/test10.hpp b/src/boost/libs/xpressive/test/test10.hpp new file mode 100644 index 00000000..28f1afad --- /dev/null +++ b/src/boost/libs/xpressive/test/test10.hpp @@ -0,0 +1,65 @@ +/////////////////////////////////////////////////////////////////////////////// +// test10.hpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include "./test.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// get_test_cases +// +template<typename BidiIterT> +boost::iterator_range<xpr_test_case<BidiIterT> const *> get_test_cases() +{ + typedef typename boost::iterator_value<BidiIterT>::type char_type; + typedef xpr_test_case<BidiIterT> xpr_test_case; + typedef basic_regex<BidiIterT> regex_type; + + static char_type const *nilbr = 0; + static xpr_test_case const test_cases[] = + { + xpr_test_case + ( + "test16" + , L("foobarboo") + , regex_type(L('b') >> +_ >> L("ar") >> eos) + , no_match + ) + , xpr_test_case + ( + "test17" + , L("foobarboo") + , regex_type(L('b') >> +_ >> L('o') >> eos) + , backrefs(L("barboo"), nilbr) + ) + , xpr_test_case + ( + "test18" + , L("foobarboo") + , regex_type(L('b') >> +_ >> L("oo") >> eos) + , backrefs(L("barboo"), nilbr) + ) + , xpr_test_case + ( + "test19" + , L("+1234.56789F") + , regex_type(bos >> (s1= !(set=L('-'),L('+')) >> +range(L('0'),L('9')) + >> !(s2= L('.') >> *range(L('0'),L('9')))) + >> (s3= (set=L('C'),L('F'))) >> eos) + , backrefs(L("+1234.56789F"), L("+1234.56789"), L(".56789"), L("F"), nilbr) + ) + , xpr_test_case + ( + "test20" + , L("+1234.56789") + , regex_type( !(s1= as_xpr(L('+'))|L('-')) >> (s2= +range(L('0'),L('9')) >> !as_xpr(L('.')) >> *range(L('0'),L('9')) | + L('.') >> +range(L('0'),L('9'))) >> !(s3= (set=L('e'),L('E')) >> !(s4= as_xpr(L('+'))|L('-')) >> +range(L('0'),L('9')))) + , backrefs(L("+1234.56789"), L("+"), L("1234.56789"), L(""), L(""), nilbr) + ) + }; + + return boost::make_iterator_range(test_cases); +} + diff --git a/src/boost/libs/xpressive/test/test10u.cpp b/src/boost/libs/xpressive/test/test10u.cpp new file mode 100644 index 00000000..926faaed --- /dev/null +++ b/src/boost/libs/xpressive/test/test10u.cpp @@ -0,0 +1,31 @@ +/////////////////////////////////////////////////////////////////////////////// +// test10.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <algorithm> +#include "./test10.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// read the tests from the input file and execute them +void test_main() +{ +#ifndef BOOST_XPRESSIVE_NO_WREGEX + typedef std::wstring::const_iterator iterator_type; + boost::iterator_range<xpr_test_case<iterator_type> const *> rng = get_test_cases<iterator_type>(); + std::for_each(rng.begin(), rng.end(), test_runner<iterator_type>()); +#endif +} + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test10u"); + test->add(BOOST_TEST_CASE(&test_main)); + return test; +} diff --git a/src/boost/libs/xpressive/test/test11.cpp b/src/boost/libs/xpressive/test/test11.cpp new file mode 100644 index 00000000..230b3b1e --- /dev/null +++ b/src/boost/libs/xpressive/test/test11.cpp @@ -0,0 +1,29 @@ +/////////////////////////////////////////////////////////////////////////////// +// test11.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <algorithm> +#include "./test11.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// read the tests from the input file and execute them +void test_main() +{ + typedef std::string::const_iterator iterator_type; + boost::iterator_range<xpr_test_case<iterator_type> const *> rng = get_test_cases<iterator_type>(); + std::for_each(rng.begin(), rng.end(), test_runner<iterator_type>()); +} + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test11"); + test->add(BOOST_TEST_CASE(&test_main)); + return test; +} diff --git a/src/boost/libs/xpressive/test/test11.hpp b/src/boost/libs/xpressive/test/test11.hpp new file mode 100644 index 00000000..0c920eff --- /dev/null +++ b/src/boost/libs/xpressive/test/test11.hpp @@ -0,0 +1,83 @@ +/////////////////////////////////////////////////////////////////////////////// +// test11.hpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include "./test.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// get_test_cases +// +template<typename BidiIterT> +boost::iterator_range<xpr_test_case<BidiIterT> const *> get_test_cases() +{ + typedef typename boost::iterator_value<BidiIterT>::type char_type; + typedef xpr_test_case<BidiIterT> xpr_test_case; + typedef basic_regex<BidiIterT> regex_type; + + static char_type const *nilbr = 0; + static xpr_test_case const test_cases[] = + { + xpr_test_case + ( + "test166" + , L("G") + , regex_type(L('f') | icase(L('g'))) + , backrefs(L("G"), nilbr) + ) + , xpr_test_case + ( + "test167" + , L("aBBa") + , regex_type(icase(+lower)) + , backrefs(L("aBBa"), nilbr) + ) + , xpr_test_case + ( + "test168" + , L("aA") + , regex_type(icase(+as_xpr(L('\x61')))) + , backrefs(L("aA"), nilbr) + ) + , xpr_test_case + ( + "test169" + , L("aA") + , regex_type(icase(+set[L('\x61')])) + , backrefs(L("aA"), nilbr) + ) + , xpr_test_case + ( + "test170" + , L("aA") + , regex_type(icase(+as_xpr(L('\x0061')))) + , backrefs(L("aA"), nilbr) + ) + , xpr_test_case + ( + "test171" + , L("aA") + , regex_type(icase(+set[L('\x0061')])) + , backrefs(L("aA"), nilbr) + ) + , xpr_test_case + ( + "test172" + , L("abcd") + , regex_type(L('a') >> +(s1= L('b') | (s2= *(s3= L('c')))) >> L('d')) + , backrefs(L("abcd"), L(""), L(""), L(""), nilbr) + ) + , xpr_test_case + ( + "test173" + , L("abcd") + , regex_type(L('a') >> +(s1= L('b') | (s2= !(s3= L('c')))) >> L('d')) + , backrefs(L("abcd"), L(""), L(""), L(""), nilbr) + ) + }; + + return boost::make_iterator_range(test_cases); +} + diff --git a/src/boost/libs/xpressive/test/test11u.cpp b/src/boost/libs/xpressive/test/test11u.cpp new file mode 100644 index 00000000..533da6c1 --- /dev/null +++ b/src/boost/libs/xpressive/test/test11u.cpp @@ -0,0 +1,31 @@ +/////////////////////////////////////////////////////////////////////////////// +// test11u.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <algorithm> +#include "./test11.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// read the tests from the input file and execute them +void test_main() +{ +#ifndef BOOST_XPRESSIVE_NO_WREGEX + typedef std::wstring::const_iterator iterator_type; + boost::iterator_range<xpr_test_case<iterator_type> const *> rng = get_test_cases<iterator_type>(); + std::for_each(rng.begin(), rng.end(), test_runner<iterator_type>()); +#endif +} + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test11u"); + test->add(BOOST_TEST_CASE(&test_main)); + return test; +} diff --git a/src/boost/libs/xpressive/test/test1u.cpp b/src/boost/libs/xpressive/test/test1u.cpp new file mode 100644 index 00000000..ca975fa5 --- /dev/null +++ b/src/boost/libs/xpressive/test/test1u.cpp @@ -0,0 +1,31 @@ +/////////////////////////////////////////////////////////////////////////////// +// test1.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <algorithm> +#include "./test1.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// read the tests from the input file and execute them +void test_main() +{ +#ifndef BOOST_XPRESSIVE_NO_WREGEX + typedef std::wstring::const_iterator iterator_type; + boost::iterator_range<xpr_test_case<iterator_type> const *> rng = get_test_cases<iterator_type>(); + std::for_each(rng.begin(), rng.end(), test_runner<iterator_type>()); +#endif +} + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test1u"); + test->add(BOOST_TEST_CASE(&test_main)); + return test; +} diff --git a/src/boost/libs/xpressive/test/test2.cpp b/src/boost/libs/xpressive/test/test2.cpp new file mode 100644 index 00000000..2baf9ae4 --- /dev/null +++ b/src/boost/libs/xpressive/test/test2.cpp @@ -0,0 +1,29 @@ +/////////////////////////////////////////////////////////////////////////////// +// test2.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <algorithm> +#include "./test2.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// read the tests from the input file and execute them +void test_main() +{ + typedef std::string::const_iterator iterator_type; + boost::iterator_range<xpr_test_case<iterator_type> const *> rng = get_test_cases<iterator_type>(); + std::for_each(rng.begin(), rng.end(), test_runner<iterator_type>()); +} + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test2"); + test->add(BOOST_TEST_CASE(&test_main)); + return test; +} diff --git a/src/boost/libs/xpressive/test/test2.hpp b/src/boost/libs/xpressive/test/test2.hpp new file mode 100644 index 00000000..d3de9aba --- /dev/null +++ b/src/boost/libs/xpressive/test/test2.hpp @@ -0,0 +1,173 @@ +/////////////////////////////////////////////////////////////////////////////// +// test2.hpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include "./test.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// get_test_cases +// +template<typename BidiIterT> +boost::iterator_range<xpr_test_case<BidiIterT> const *> get_test_cases() +{ + typedef typename boost::iterator_value<BidiIterT>::type char_type; + typedef xpr_test_case<BidiIterT> xpr_test_case; + typedef basic_regex<BidiIterT> regex_type; + + // "(\\+|-)?([0-9]+\\.?[0-9]*|\\.[0-9]+)([eE](\\+|-)?[0-9]+)?" + static regex_type const test21 = !(s1= as_xpr(L('+'))|L('-')) >> (s2= +range(L('0'),L('9')) >> !as_xpr(L('.')) >> *range(L('0'),L('9')) | + L('.') >> +range(L('0'),L('9'))) >> !(s3= (set=L('e'),L('E')) >> !(s4= as_xpr(L('+'))|L('-')) >> +range(L('0'),L('9'))); + + // "^(\\+|-)?([0-9]+\\.?[0-9]*|\\.[0-9]+)([eE](\\+|-)?[0-9]+)?$" + static regex_type const test23 = bos >> test21 >> eos; + + static char_type const *nilbr = 0; + static xpr_test_case const test_cases[] = + { + xpr_test_case + ( + "test21" + , L("-1234.56789") + , test21 + , backrefs(L("-1234.56789"), L("-"), L("1234.56789"), L(""), L(""), nilbr) + ) + , xpr_test_case + ( + "test22" + , L("-1234.56789e-123123123") + , test21 + , backrefs(L("-1234.56789e-123123123"), L("-"), L("1234.56789"), L("e-123123123"), L("-"), nilbr) + ) + , xpr_test_case + ( + "test23" + , L("-.1234.56789") + , test23 + , no_match + ) + , xpr_test_case + ( + "test24" + , L("-1234.56789e-12312e123") + , test23 + , no_match + ) + , xpr_test_case + ( + "test25" + , L("aaaaaaaaac") + , regex_type(*as_xpr(L('a')) >> *as_xpr(L('a')) >> *as_xpr(L('a')) >> *as_xpr(L('a')) >> *as_xpr(L('a')) >> L('b')) + , no_match + ) + , xpr_test_case + ( + "test26" + , L("ThIs iS a TeSt") + , regex_type(*set[range(L('a'),L('z')) | range(L('A'),L('Z'))]) + , backrefs(L("ThIs"), nilbr) + ) + , xpr_test_case + ( + "test27" + , L("a^b") + , regex_type(L('a') >> bos >> L('b')) + , no_match + ) + , xpr_test_case + ( + "test28" + , L("a^b") + , regex_type(as_xpr(L("a^b"))) + , backrefs(L("a^b"), nilbr) + ) + , xpr_test_case + ( + "test29" + , L("a^b") + , regex_type(L('a') >> ~set[L(' ')] >> L('b')) + , backrefs(L("a^b"), nilbr) + ) + , xpr_test_case + ( + "test30" + , L("a^b") + , regex_type(L('a') >> ~set[L('^')] >> L('b')) + , no_match + ) + , xpr_test_case + ( + "test31" + , L("a^b") + , regex_type(L('a') >> ~set[L('^')] >> L('b')) + , no_match + ) + , xpr_test_case + ( + "test31.1" + , L("a^b") + , regex_type(L('a') >> set[L('^')] >> L('b')) + , backrefs(L("a^b"), nilbr) + ) + , xpr_test_case + ( + "test32" + , L("foobazFOObar") + , regex_type(icase(L("foo") >> before(L("bar")))) + , backrefs(L("FOO"), nilbr) + ) + , xpr_test_case + ( + "test33" + , L("foobarFOObaz") + , regex_type(icase(L("foo") >> ~before(L("bar")))) + , backrefs(L("FOO"), nilbr) + ) + , xpr_test_case + ( + "test34" + , L("foobarFOO") + , regex_type(icase(L("foo") >> ~before(L("bar")))) + , backrefs(L("FOO"), nilbr) + ) + , xpr_test_case + ( + "test35" + , L("foobarFOObarfoo") + , regex_type(icase(+(s1= keep(s2= L("foo")) >> L("bar")))) + , backrefs(L("foobarFOObar"), L("FOObar"), L("FOO"), nilbr) + ) + , xpr_test_case + ( + "test37" + , L("foobar") + , regex_type(+(s1= L("bar") | (s2= L("foo")))) + , backrefs(L("foobar"), L("bar"), L("foo"), nilbr) + ) + , xpr_test_case + ( + "test38" + , L("foobar") + , regex_type(+(s1= (s2= L("bar")) | L("foo"))) + , backrefs(L("foobar"), L("bar"), L("bar"), nilbr) + ) + , xpr_test_case + ( + "test39" + , L("foobar") + , regex_type(+(s1= L("foo") | (s2= L("bar")))) + , backrefs(L("foobar"), L("bar"), L("bar"), nilbr) + ) + , xpr_test_case + ( + "test40" + , L("foobar") + , regex_type(+(s1= (s2= L("foo")) | L("bar"))) + , backrefs(L("foobar"), L("bar"), L("foo"), nilbr) + ) + }; + + return boost::make_iterator_range(test_cases); +} diff --git a/src/boost/libs/xpressive/test/test2u.cpp b/src/boost/libs/xpressive/test/test2u.cpp new file mode 100644 index 00000000..9ca9b84b --- /dev/null +++ b/src/boost/libs/xpressive/test/test2u.cpp @@ -0,0 +1,31 @@ +/////////////////////////////////////////////////////////////////////////////// +// test2.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <algorithm> +#include "./test2.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// read the tests from the input file and execute them +void test_main() +{ +#ifndef BOOST_XPRESSIVE_NO_WREGEX + typedef std::wstring::const_iterator iterator_type; + boost::iterator_range<xpr_test_case<iterator_type> const *> rng = get_test_cases<iterator_type>(); + std::for_each(rng.begin(), rng.end(), test_runner<iterator_type>()); +#endif +} + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test2u"); + test->add(BOOST_TEST_CASE(&test_main)); + return test; +} diff --git a/src/boost/libs/xpressive/test/test3.cpp b/src/boost/libs/xpressive/test/test3.cpp new file mode 100644 index 00000000..eb1f2da1 --- /dev/null +++ b/src/boost/libs/xpressive/test/test3.cpp @@ -0,0 +1,29 @@ +/////////////////////////////////////////////////////////////////////////////// +// test3.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <algorithm> +#include "./test3.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// read the tests from the input file and execute them +void test_main() +{ + typedef std::string::const_iterator iterator_type; + boost::iterator_range<xpr_test_case<iterator_type> const *> rng = get_test_cases<iterator_type>(); + std::for_each(rng.begin(), rng.end(), test_runner<iterator_type>()); +} + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test3"); + test->add(BOOST_TEST_CASE(&test_main)); + return test; +} diff --git a/src/boost/libs/xpressive/test/test3.hpp b/src/boost/libs/xpressive/test/test3.hpp new file mode 100644 index 00000000..67e6a37d --- /dev/null +++ b/src/boost/libs/xpressive/test/test3.hpp @@ -0,0 +1,196 @@ +/////////////////////////////////////////////////////////////////////////////// +// test3.hpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include "./test.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// get_test_cases +// +template<typename BidiIterT> +boost::iterator_range<xpr_test_case<BidiIterT> const *> get_test_cases() +{ + typedef typename boost::iterator_value<BidiIterT>::type char_type; + typedef xpr_test_case<BidiIterT> xpr_test_case; + typedef basic_regex<BidiIterT> regex_type; + + static char_type const *nilbr = 0; + static xpr_test_case const test_cases[] = + { + xpr_test_case + ( + "test41" + , L("foobarFOObarfoo") + , regex_type((s1= icase(L("FOO"))) >> (s2= -*_) >> s1) + , backrefs(L("foobarFOObarfoo"), L("foo"), L("barFOObar"), nilbr) + ) + , xpr_test_case + ( + "test42" + , L("foobarFOObarfoo") + , regex_type((s1= icase(L("FOO"))) >> (s2= -*_) >> icase(s1)) + , backrefs(L("foobarFOO"), L("foo"), L("bar"), nilbr) + ) + , xpr_test_case + ( + "test42.1" + , L("fooFOOOFOOOOObar") + , regex_type(+(s1= L("foo") | icase(s1 >> L('O')))) + , backrefs(L("fooFOOOFOOOO"), L("FOOOO"), nilbr) + ) + , xpr_test_case + ( + "test43" + , L("zoo") + , regex_type(bos >> set[range(L('A'),L('Z')) | range(L('a'),L('m'))]) + , no_match + ) + , xpr_test_case + ( + "test44" + , L("Here is a URL: http://www.cnn.com. OK?") + , regex_type((s1= L("http") >> !as_xpr(L('s')) >> L(":/") | L("www.")) + >> +set[_w | (set=L('.'),L('/'),L(','),L('?'),L('@'),L('#'),L('%'),L('!'),L('_'),L('='),L('~'),L('&'),L('-'))] + >> _w) + , backrefs(L("http://www.cnn.com"), L("http:/"), nilbr) + ) + , xpr_test_case + ( + "test45" + , L("fooooooooo") + , regex_type(L('f') >> repeat<2,5>(L('o'))) + , backrefs(L("fooooo"), nilbr) + ) + , xpr_test_case + ( + "test46" + , L("fooooooooo") + , regex_type(L('f') >> -repeat<2,5>(L('o'))) + , backrefs(L("foo"), nilbr) + ) + , xpr_test_case + ( + "test45.1" + , L("fooooooooo") + , regex_type(L('f') >> repeat<2,5>(L('o')) >> L('o')) + , backrefs(L("foooooo"), nilbr) + ) + , xpr_test_case + ( + "test46.1" + , L("fooooooooo") + , regex_type(L('f') >> -repeat<2,5>(L('o')) >> L('o')) + , backrefs(L("fooo"), nilbr) + ) + , xpr_test_case + ( + "test47" + , L("{match this}") + , regex_type(bos >> L('{') >> *_ >> L('}') >> eos) + , backrefs(L("{match this}"), nilbr) + ) + , xpr_test_case + ( + "test48" + , L("+-+-") + , regex_type(+(set=L('+'),L('-'))) + , backrefs(L("+-+-"), nilbr) + ) + , xpr_test_case + ( + "test49" + , L("+-+-") + , regex_type(+(set=L('-'),L('+'))) + , backrefs(L("+-+-"), nilbr) + ) + , xpr_test_case + ( + "test50" + , L("\\05g-9e") + , regex_type(+set[_d | L('-') | L('g')]) + , backrefs(L("05g-9"), nilbr) + ) + , xpr_test_case + ( + "test51" + , L("\\05g-9e") + , regex_type(+set[_d | L('-') | L('g')]) + , backrefs(L("05g-9"), nilbr) + ) + , xpr_test_case + ( + "test52" + , L("\\05g-9e") + , regex_type(+set[L('g') | as_xpr(L('-')) | _d]) + , backrefs(L("05g-9"), nilbr) + ) + , xpr_test_case + ( + "test53" + , L("\\05g-9e") + , regex_type(+set[L('g') | as_xpr(L('-')) | _d]) + , backrefs(L("05g-9"), nilbr) + ) + , xpr_test_case + ( + "test54" + , L("aBcdefg\\") + , regex_type(icase(+range(L('a'),L('g')))) + , backrefs(L("aBcdefg"), nilbr) + ) + , xpr_test_case + ( + "test55" + , L("ab/.-ba") + , regex_type(+range(L('-'),L('/'))) + , backrefs(L("/.-"), nilbr) + ) + , xpr_test_case + ( + "test56" + , L("ab+,-ba") + , regex_type(+range(L('+'),L('-'))) + , backrefs(L("+,-"), nilbr) + ) + , xpr_test_case + ( + "test56.1" + , L("aaabbbb----") + , regex_type(+range(L('b'),L('b'))) + , backrefs(L("bbbb"), nilbr) + ) + , xpr_test_case + ( + "test57" + , L("foobarFOO5") + , regex_type(icase((s1= L("foo")) >> *_ >> L('\15'))) + , no_match + ) + , xpr_test_case + ( + "test58" + , L("Her number is 804-867-5309.") + , regex_type(repeat<2>(repeat<3>(_d) >> L('-')) >> repeat<4>(_d)) + , backrefs(L("804-867-5309"), nilbr) + ) + , xpr_test_case + ( + "test59" + , L("foo") + , regex_type(L('f') >> +as_xpr(L('o'))) + , backrefs(L("foo"), nilbr) + ) + , xpr_test_case + ( + "test60" + , L("fooFOObar") + , regex_type(icase(+(s1= L("foo")) >> L("foobar"))) + , backrefs(L("fooFOObar"), L("foo"), nilbr) + ) + }; + + return boost::make_iterator_range(test_cases); +} diff --git a/src/boost/libs/xpressive/test/test3u.cpp b/src/boost/libs/xpressive/test/test3u.cpp new file mode 100644 index 00000000..550f4e0b --- /dev/null +++ b/src/boost/libs/xpressive/test/test3u.cpp @@ -0,0 +1,31 @@ +/////////////////////////////////////////////////////////////////////////////// +// test3.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <algorithm> +#include "./test3.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// read the tests from the input file and execute them +void test_main() +{ +#ifndef BOOST_XPRESSIVE_NO_WREGEX + typedef std::wstring::const_iterator iterator_type; + boost::iterator_range<xpr_test_case<iterator_type> const *> rng = get_test_cases<iterator_type>(); + std::for_each(rng.begin(), rng.end(), test_runner<iterator_type>()); +#endif +} + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test3u"); + test->add(BOOST_TEST_CASE(&test_main)); + return test; +} diff --git a/src/boost/libs/xpressive/test/test4.cpp b/src/boost/libs/xpressive/test/test4.cpp new file mode 100644 index 00000000..2e449548 --- /dev/null +++ b/src/boost/libs/xpressive/test/test4.cpp @@ -0,0 +1,29 @@ +/////////////////////////////////////////////////////////////////////////////// +// test4.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <algorithm> +#include "./test4.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// read the tests from the input file and execute them +void test_main() +{ + typedef std::string::const_iterator iterator_type; + boost::iterator_range<xpr_test_case<iterator_type> const *> rng = get_test_cases<iterator_type>(); + std::for_each(rng.begin(), rng.end(), test_runner<iterator_type>()); +} + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test4"); + test->add(BOOST_TEST_CASE(&test_main)); + return test; +} diff --git a/src/boost/libs/xpressive/test/test4.hpp b/src/boost/libs/xpressive/test/test4.hpp new file mode 100644 index 00000000..98c17df4 --- /dev/null +++ b/src/boost/libs/xpressive/test/test4.hpp @@ -0,0 +1,109 @@ +/////////////////////////////////////////////////////////////////////////////// +// test4.hpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include "./test.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// get_test_cases +// +template<typename BidiIterT> +boost::iterator_range<xpr_test_case<BidiIterT> const *> get_test_cases() +{ + typedef typename boost::iterator_value<BidiIterT>::type char_type; + typedef xpr_test_case<BidiIterT> xpr_test_case; + typedef basic_regex<BidiIterT> regex_type; + + // for testing recursive static regexes + //regex_type parens = L('(') >> *( keep( +~(set=L('('),L(')')) ) | self ) >> L(')'); + + regex_type parens; + parens = L('(') >> *( keep( +~(set=L('('),L(')')) ) | by_ref(parens) ) >> L(')'); + + static char_type const *nilbr = 0; + static xpr_test_case const test_cases[] = + { + xpr_test_case + ( + "test61" + , L("this is sublist(now(is(the(time),for(all),good(men))to(come)))ok?") + , regex_type(_b >> L("sublist") >> parens) + , backrefs(L("sublist(now(is(the(time),for(all),good(men))to(come)))"), nilbr) + ) + , xpr_test_case + ( + "test62" + , L("this is sublist(now(is(the(time),for(all),good(men))to(come))ok?") + , regex_type(_b >> L("sublist") >> parens) + , no_match + ) + , xpr_test_case + ( + "test63" + , L("foobar") + , regex_type(bos >> L("baz") | L("bar")) + , backrefs(L("bar"), nilbr) + ) + , xpr_test_case + ( + "test69" + , L("FooBarfoobar") + , regex_type(icase(*_ >> L("foo"))) + , backrefs(L("FooBarfoo"), nilbr) + ) + , xpr_test_case + ( + "test70" + , L("FooBarfoobar") + , regex_type(icase(*_ >> L("boo"))) + , no_match + ) + , xpr_test_case + ( + "test71" + , L("FooBarfoobar") + , regex_type(icase(*_ >> L("boo") | L("bar"))) + , backrefs(L("Bar"), nilbr) + ) + , xpr_test_case + ( + "test72" + , L("FooBarfoobar") + , regex_type(icase(L("bar"))) + , backrefs(L("Bar"), nilbr) + ) + , xpr_test_case + ( + "test75" + , L("fooooo") + , regex_type(L('f') >> repeat<1,repeat_max>(L('o'))) + , backrefs(L("fooooo"), nilbr) + ) + , xpr_test_case + ( + "test78" + , L("This (has) parens") + , regex_type(L("This ") >> (s1= L("(has)")) >> L(' ') >> (s2= L("parens"))) + , backrefs(L("This (has) parens"), L("(has)"), L("parens"), nilbr) + ) + , xpr_test_case + ( + "test79" + , L("This (has) parens") + , regex_type(as_xpr(L("This (has) parens"))) + , backrefs(L("This (has) parens"), nilbr) + ) + , xpr_test_case + ( + "test80" + , L("This (has) parens") + , regex_type(as_xpr(L("This (has) parens"))) + , backrefs(L("This (has) parens"), nilbr) + ) + }; + + return boost::make_iterator_range(test_cases); +} diff --git a/src/boost/libs/xpressive/test/test4u.cpp b/src/boost/libs/xpressive/test/test4u.cpp new file mode 100644 index 00000000..c941502e --- /dev/null +++ b/src/boost/libs/xpressive/test/test4u.cpp @@ -0,0 +1,31 @@ +/////////////////////////////////////////////////////////////////////////////// +// test4.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <algorithm> +#include "./test4.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// read the tests from the input file and execute them +void test_main() +{ +#ifndef BOOST_XPRESSIVE_NO_WREGEX + typedef std::wstring::const_iterator iterator_type; + boost::iterator_range<xpr_test_case<iterator_type> const *> rng = get_test_cases<iterator_type>(); + std::for_each(rng.begin(), rng.end(), test_runner<iterator_type>()); +#endif +} + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test4u"); + test->add(BOOST_TEST_CASE(&test_main)); + return test; +} diff --git a/src/boost/libs/xpressive/test/test5.cpp b/src/boost/libs/xpressive/test/test5.cpp new file mode 100644 index 00000000..c1640cae --- /dev/null +++ b/src/boost/libs/xpressive/test/test5.cpp @@ -0,0 +1,29 @@ +/////////////////////////////////////////////////////////////////////////////// +// test5.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <algorithm> +#include "./test5.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// read the tests from the input file and execute them +void test_main() +{ + typedef std::string::const_iterator iterator_type; + boost::iterator_range<xpr_test_case<iterator_type> const *> rng = get_test_cases<iterator_type>(); + std::for_each(rng.begin(), rng.end(), test_runner<iterator_type>()); +} + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test5"); + test->add(BOOST_TEST_CASE(&test_main)); + return test; +} diff --git a/src/boost/libs/xpressive/test/test5.hpp b/src/boost/libs/xpressive/test/test5.hpp new file mode 100644 index 00000000..b8ed5ffa --- /dev/null +++ b/src/boost/libs/xpressive/test/test5.hpp @@ -0,0 +1,159 @@ +/////////////////////////////////////////////////////////////////////////////// +// test5.hpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include "./test.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// get_test_cases +// +template<typename BidiIterT> +boost::iterator_range<xpr_test_case<BidiIterT> const *> get_test_cases() +{ + typedef typename boost::iterator_value<BidiIterT>::type char_type; + typedef xpr_test_case<BidiIterT> xpr_test_case; + typedef basic_regex<BidiIterT> regex_type; + + static char_type const *nilbr = 0; + static xpr_test_case const test_cases[] = + { + xpr_test_case + ( + "test82" + , L("abba1234abba") + , regex_type(+_d) + , backrefs(L("1234"), nilbr) + ) + , xpr_test_case + ( + "test83" + , L("1234abba1234") + , regex_type(+~_d) + , backrefs(L("abba"), nilbr) + ) + , xpr_test_case + ( + "test84" + , L("abba1234abba") + , regex_type(+set[_d]) + , backrefs(L("1234"), nilbr) + ) + , xpr_test_case + ( + "test85" + , L("1234abba1234") + , regex_type(+set[~_d]) + , backrefs(L("abba"), nilbr) + ) + , xpr_test_case + ( + "test86" + , L("abba1234abba") + , regex_type(+~set[~_d]) + , backrefs(L("1234"), nilbr) + ) + , xpr_test_case + ( + "test87" + , L("1234abba1234") + , regex_type(+~set[_d]) + , backrefs(L("abba"), nilbr) + ) + , xpr_test_case + ( + "test88" + , L("1234abba1234") + , regex_type(+set[~_w | ~_d]) + , backrefs(L("abba"), nilbr) + ) + , xpr_test_case + ( + "test89" + , L("1234(.;)abba") + , regex_type(+~set[_w | _d]) + , backrefs(L("(.;)"), nilbr) + ) + , xpr_test_case + ( + "test90" + , L("(boo[bar]baz)") + , regex_type((s1= L('(') >> (s2= nil) | L('[') >> (s3= nil)) >> -*_ >> (s4= L(')') >> s2 | L(']') >> s3)) + , backrefs(L("(boo[bar]baz)"), L("("), L(""), L(""), L(")"), nilbr) + ) + , xpr_test_case + ( + "test91" + , L("[boo(bar)baz]") + , regex_type((s1= L('(') >> (s2= nil) | L('[') >> (s3= nil)) >> -*_ >> (s4= L(')') >> s2 | L(']') >> s3)) + , backrefs(L("[boo(bar)baz]"), L("["), L(""), L(""), L("]"), nilbr) + ) + , xpr_test_case + ( + "test91" + , L("[boo[bar]baz]") + , regex_type((s1= L('(') >> (s2= nil) | L('[') >> (s3= nil)) >> -*_ >> (s4= L(')') >> s2 | L(']') >> s3)) + , backrefs(L("[boo[bar]"), L("["), L(""), L(""), L("]"), nilbr) + ) + , xpr_test_case + ( + "test92" + , L("foobarfoo") + , regex_type(after(L("foo")) >> L("bar")) + , backrefs(L("bar"), nilbr) + ) + , xpr_test_case + ( + "test93" + , L("foobarfoo") + , regex_type(after(s1= L('f') >> _ >> L('o')) >> L("bar")) + , backrefs(L("bar"), L("foo"), nilbr) + ) + , xpr_test_case + ( + "test94" + , L("foOoo") + , regex_type(icase(after(s1= L("fo")) >> L('o'))) + , backrefs(L("O"), L("fo"), nilbr) + ) + , xpr_test_case + ( + "test95" + , L("fOooo") + , regex_type(icase(~after(s1= L("fo")) >> L('o'))) + , backrefs(L("O"), L(""), nilbr) + ) + , xpr_test_case + ( + "test96" + , L("12foo12") + , regex_type(+alpha) + , backrefs(L("foo"), nilbr) + ) + , xpr_test_case + ( + "test97" + , L(";12foo12;") + , regex_type(+set[alpha | digit]) + , backrefs(L("12foo12"), nilbr) + ) + , xpr_test_case + ( + "test98" + , L("aaaa") + , regex_type(after(s1= nil) >> L('a')) + , backrefs(L("a"), L(""), nilbr) + ) + , xpr_test_case + ( + "test99" + , L("ABCabc123foo") + , regex_type(after(s1= L("abc") >> repeat<3>(_d)) >> L("foo")) + , backrefs(L("foo"), L("abc123"), nilbr) + ) + }; + + return boost::make_iterator_range(test_cases); +} diff --git a/src/boost/libs/xpressive/test/test5u.cpp b/src/boost/libs/xpressive/test/test5u.cpp new file mode 100644 index 00000000..82a65fa4 --- /dev/null +++ b/src/boost/libs/xpressive/test/test5u.cpp @@ -0,0 +1,31 @@ +/////////////////////////////////////////////////////////////////////////////// +// test5.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <algorithm> +#include "./test5.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// read the tests from the input file and execute them +void test_main() +{ +#ifndef BOOST_XPRESSIVE_NO_WREGEX + typedef std::wstring::const_iterator iterator_type; + boost::iterator_range<xpr_test_case<iterator_type> const *> rng = get_test_cases<iterator_type>(); + std::for_each(rng.begin(), rng.end(), test_runner<iterator_type>()); +#endif +} + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test5u"); + test->add(BOOST_TEST_CASE(&test_main)); + return test; +} diff --git a/src/boost/libs/xpressive/test/test6.cpp b/src/boost/libs/xpressive/test/test6.cpp new file mode 100644 index 00000000..26f570a2 --- /dev/null +++ b/src/boost/libs/xpressive/test/test6.cpp @@ -0,0 +1,29 @@ +/////////////////////////////////////////////////////////////////////////////// +// test6.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <algorithm> +#include "./test6.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// read the tests from the input file and execute them +void test_main() +{ + typedef std::string::const_iterator iterator_type; + boost::iterator_range<xpr_test_case<iterator_type> const *> rng = get_test_cases<iterator_type>(); + std::for_each(rng.begin(), rng.end(), test_runner<iterator_type>()); +} + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test6"); + test->add(BOOST_TEST_CASE(&test_main)); + return test; +} diff --git a/src/boost/libs/xpressive/test/test6.hpp b/src/boost/libs/xpressive/test/test6.hpp new file mode 100644 index 00000000..20a62874 --- /dev/null +++ b/src/boost/libs/xpressive/test/test6.hpp @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// test6.hpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include "./test.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// get_test_cases +// +template<typename BidiIterT> +boost::iterator_range<xpr_test_case<BidiIterT> const *> get_test_cases() +{ + typedef typename boost::iterator_value<BidiIterT>::type char_type; + typedef xpr_test_case<BidiIterT> xpr_test_case; + typedef basic_regex<BidiIterT> regex_type; + + static char_type const *nilbr = 0; + static xpr_test_case const test_cases[] = + { + xpr_test_case + ( + "test103" + , L("a\nxb\n") + , regex_type(~before(bol) >> L('x')) + , no_match + ) + , xpr_test_case + ( + "test104" + , L("a\nxb\n") + , regex_type(~before(bos) >> L('x')) + , backrefs(L("x"), nilbr) + ) + , xpr_test_case + ( + "test105" + , L("a\nxb\n") + , regex_type(~before(bos) >> L('x')) + , backrefs(L("x"), nilbr) + ) + , xpr_test_case + ( + "test106" + , L("(this)") + , regex_type(bos >> (L('(') >> (s1= nil) | (s2= nil)) >> +_w >> (L(')') >> s1 | s2) >> eos) + , backrefs(L("(this)"), L(""), L(""), nilbr) + ) + , xpr_test_case + ( + "test107" + , L("this") + , regex_type(bos >> (L('(') >> (s1= nil) | (s2= nil)) >> +_w >> (L(')') >> s1 | s2) >> eos) + , backrefs(L("this"), L(""), L(""), nilbr) + ) + , xpr_test_case + ( + "test108" + , L("this)") + , regex_type(bos >> (L('(') >> (s1= nil) | (s2= nil)) >> +_w >> (L(')') >> s1 | s2) >> eos) + , no_match + ) + , xpr_test_case + ( + "test109" + , L("(this") + , regex_type(bos >> (L('(') >> (s1= nil) | (s2= nil)) >> +_w >> (L(')') >> s1 | s2) >> eos) + , no_match + ) + , xpr_test_case + ( + "test110" + , L("abba123abba") + , regex_type(+~alpha) + , backrefs(L("123"), nilbr) + ) + , xpr_test_case + ( + "test111" + , L("abba123abba") + , regex_type(+set[alpha | ~alpha]) + , backrefs(L("abba123abba"), nilbr) + ) + , xpr_test_case + ( + "test112" + , L("123abba123") + , regex_type(+~set[~alpha]) + , backrefs(L("abba"), nilbr) + ) + //, xpr_test_case + // ( + // "test113" + // , L("123abba123") + // , regex_type(as_xpr(L("[[:alpha:]\\y]+"))) + // , backrefs(L("123abba123"), nilbr) + // ) + , xpr_test_case + ( + "test114" + , L("abba123abba") + , regex_type(+~set[~alnum | ~digit]) + , backrefs(L("123"), nilbr) + ) + , xpr_test_case + ( + "test115" + , L("aaaaA") + , regex_type(icase(bos >> repeat<4>(s1= L('a') >> !s1) >> eos)) + , backrefs(L("aaaaA"), L("A"), nilbr) + ) + , xpr_test_case + ( + "test116" + , L("aaaaAa") + , regex_type(icase(bos >> repeat<4>(s1= L('a') >> !s1) >> eos)) + , backrefs(L("aaaaAa"), L("Aa"), nilbr) + ) + }; + + return boost::make_iterator_range(test_cases); +} diff --git a/src/boost/libs/xpressive/test/test6u.cpp b/src/boost/libs/xpressive/test/test6u.cpp new file mode 100644 index 00000000..44a951f6 --- /dev/null +++ b/src/boost/libs/xpressive/test/test6u.cpp @@ -0,0 +1,31 @@ +/////////////////////////////////////////////////////////////////////////////// +// test6.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <algorithm> +#include "./test6.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// read the tests from the input file and execute them +void test_main() +{ +#ifndef BOOST_XPRESSIVE_NO_WREGEX + typedef std::wstring::const_iterator iterator_type; + boost::iterator_range<xpr_test_case<iterator_type> const *> rng = get_test_cases<iterator_type>(); + std::for_each(rng.begin(), rng.end(), test_runner<iterator_type>()); +#endif +} + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test6u"); + test->add(BOOST_TEST_CASE(&test_main)); + return test; +} diff --git a/src/boost/libs/xpressive/test/test7.cpp b/src/boost/libs/xpressive/test/test7.cpp new file mode 100644 index 00000000..de1ac5f8 --- /dev/null +++ b/src/boost/libs/xpressive/test/test7.cpp @@ -0,0 +1,29 @@ +/////////////////////////////////////////////////////////////////////////////// +// test7.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <algorithm> +#include "./test7.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// read the tests from the input file and execute them +void test_main() +{ + typedef std::string::const_iterator iterator_type; + boost::iterator_range<xpr_test_case<iterator_type> const *> rng = get_test_cases<iterator_type>(); + std::for_each(rng.begin(), rng.end(), test_runner<iterator_type>()); +} + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test7"); + test->add(BOOST_TEST_CASE(&test_main)); + return test; +} diff --git a/src/boost/libs/xpressive/test/test7.hpp b/src/boost/libs/xpressive/test/test7.hpp new file mode 100644 index 00000000..998c9941 --- /dev/null +++ b/src/boost/libs/xpressive/test/test7.hpp @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// test7.hpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include "./test.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// get_test_cases +// +template<typename BidiIterT> +boost::iterator_range<xpr_test_case<BidiIterT> const *> get_test_cases() +{ + typedef typename boost::iterator_value<BidiIterT>::type char_type; + typedef xpr_test_case<BidiIterT> xpr_test_case; + typedef basic_regex<BidiIterT> regex_type; + + static char_type const *nilbr = 0; + static xpr_test_case const test_cases[] = + { + xpr_test_case + ( + "test127" + , L("foobar") + , regex_type(as_xpr(L("foo")) >> /*This is a comment[*/ L("bar")) + , backrefs(L("foobar"), nilbr) + ) + , xpr_test_case + ( + "test128" + , L("foobar") + , regex_type(bos >> L("foobar") >> eos) + , backrefs(L("foobar"), nilbr) + ) + , xpr_test_case + ( + "test129" + , L("foobar") + , regex_type(bos >> L('f') >> *as_xpr(L('o'))) + , backrefs(L("foo"), nilbr) + ) + , xpr_test_case + ( + "test129.1" + , L("foobar") + , regex_type(bos >> L('f') >> *as_xpr(L('\157'))) + , backrefs(L("foo"), nilbr) + ) + , xpr_test_case + ( + "test130" + , L("foo bar") + , regex_type(bos >> L("foo bar") >> eos) + , backrefs(L("foo bar"), nilbr) + ) + , xpr_test_case + ( + "test131" + , L("foo bar") + , regex_type(bos >> L("foo") >> set[L(' ')] >> L("bar") >> eos) + , backrefs(L("foo bar"), nilbr) + ) + , xpr_test_case + ( + "test132" + , L("foo bar") + , regex_type(bos >> (L("foo") >> set[L(' ')] >> L("bar")) >> eos /*This is a comment*/) + , backrefs(L("foo bar"), nilbr) + ) + , xpr_test_case + ( + "test133" + , L("foo bar") + , regex_type(bos >> L("foo") >> set[L(' ')] >> L("bar") /*This is a comment*/) + , backrefs(L("foo bar"), nilbr) + ) + , xpr_test_case + ( + "test134" + , L("foo bar#Thisisnotacomment") + , regex_type(bos >> L("foo") >> set[L(' ')] >> L("bar#Thisisnotacomment")) + , backrefs(L("foo bar#Thisisnotacomment"), nilbr) + ) + , xpr_test_case + ( + "test135" + , L("f oo b ar") + , regex_type(bos >> L("f oo b ar")) + , backrefs(L("f oo b ar"), nilbr) + ) + , xpr_test_case + ( + "test137" + , L("a--") + , regex_type(bos >> *(s1= optional(L('a'))) >> eos) + , no_match + ) + , xpr_test_case + ( + "test138" + , L("a--") + , regex_type(bos >> -*(s1= optional(L('a'))) >> eos) + , no_match + ) + , xpr_test_case + ( + "test139" + , L("bc") + , regex_type(bos >> repeat<2>(s1= optional(L('b'))) >> L("bc") >> eos) + , backrefs(L("bc"), L(""), nilbr) + ) + , xpr_test_case + ( + "test140" + , L("bbc") + , regex_type(bos >> repeat<2>(s1= optional(L('b'))) >> L("bc") >> eos) + , backrefs(L("bbc"), L(""), nilbr) + ) + }; + + return boost::make_iterator_range(test_cases); +} diff --git a/src/boost/libs/xpressive/test/test7u.cpp b/src/boost/libs/xpressive/test/test7u.cpp new file mode 100644 index 00000000..53e6613b --- /dev/null +++ b/src/boost/libs/xpressive/test/test7u.cpp @@ -0,0 +1,31 @@ +/////////////////////////////////////////////////////////////////////////////// +// test7.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <algorithm> +#include "./test7.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// read the tests from the input file and execute them +void test_main() +{ +#ifndef BOOST_XPRESSIVE_NO_WREGEX + typedef std::wstring::const_iterator iterator_type; + boost::iterator_range<xpr_test_case<iterator_type> const *> rng = get_test_cases<iterator_type>(); + std::for_each(rng.begin(), rng.end(), test_runner<iterator_type>()); +#endif +} + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test7u"); + test->add(BOOST_TEST_CASE(&test_main)); + return test; +} diff --git a/src/boost/libs/xpressive/test/test8.cpp b/src/boost/libs/xpressive/test/test8.cpp new file mode 100644 index 00000000..e9e50589 --- /dev/null +++ b/src/boost/libs/xpressive/test/test8.cpp @@ -0,0 +1,29 @@ +/////////////////////////////////////////////////////////////////////////////// +// test8.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <algorithm> +#include "./test8.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// read the tests from the input file and execute them +void test_main() +{ + typedef std::string::const_iterator iterator_type; + boost::iterator_range<xpr_test_case<iterator_type> const *> rng = get_test_cases<iterator_type>(); + std::for_each(rng.begin(), rng.end(), test_runner<iterator_type>()); +} + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test8"); + test->add(BOOST_TEST_CASE(&test_main)); + return test; +} diff --git a/src/boost/libs/xpressive/test/test8.hpp b/src/boost/libs/xpressive/test/test8.hpp new file mode 100644 index 00000000..360e9bbb --- /dev/null +++ b/src/boost/libs/xpressive/test/test8.hpp @@ -0,0 +1,96 @@ +/////////////////////////////////////////////////////////////////////////////// +// test8.hpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include "./test.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// get_test_cases +// +template<typename BidiIterT> +boost::iterator_range<xpr_test_case<BidiIterT> const *> get_test_cases() +{ + typedef typename boost::iterator_value<BidiIterT>::type char_type; + typedef xpr_test_case<BidiIterT> xpr_test_case; + typedef basic_regex<BidiIterT> regex_type; + + static char_type const *nilbr = 0; + static xpr_test_case const test_cases[] = + { + xpr_test_case + ( + "test141" + , L("bbbc") + , regex_type(bos >> repeat<2>(s1= optional(L('b'))) >> L("bc") >> eos) + , backrefs(L("bbbc"), L("b"), nilbr) + ) + , xpr_test_case + ( + "test142" + , L("bbbbc") + , regex_type(bos >> repeat<2>(s1= optional(L('b'))) >> L("bc") >> eos) + , no_match + ) + , xpr_test_case + ( + "test143" + , L("bbbbc") + , regex_type(bos >> *(s1= optional(L('b'))) >> L('d') >> eos) + , no_match + ) + , xpr_test_case + ( + "test144" + , L("bc") + , regex_type(bos >> -repeat<2>(s1= optional(L('b'))) >> L("bc") >> eos) + , backrefs(L("bc"), L(""), nilbr) + ) + , xpr_test_case + ( + "test145" + , L("bbc") + , regex_type(bos >> -repeat<2>(s1= optional(L('b'))) >> L("bc") >> eos) + , backrefs(L("bbc"), L(""), nilbr) + ) + , xpr_test_case + ( + "test146" + , L("bbbc") + , regex_type(bos >> -repeat<2>(s1= optional(L('b'))) >> L("bc") >> eos) + , backrefs(L("bbbc"), L("b"), nilbr) + ) + , xpr_test_case + ( + "test147" + , L("bbbbc") + , regex_type(bos >> -repeat<2>(s1= optional(L('b'))) >> L("bc") >> eos) + , no_match + ) + , xpr_test_case + ( + "test148" + , L("bbbbc") + , regex_type(bos >> -*(s1= optional(L('b'))) >> L('d') >> eos) + , no_match + ) + , xpr_test_case + ( + "test149" + , L("bc") + , regex_type(bos >> repeat<2>(s1= -optional(L('b'))) >> L("bc") >> eos) + , backrefs(L("bc"), L(""), nilbr) + ) + , xpr_test_case + ( + "test150" + , L("bbc") + , regex_type(bos >> repeat<2>(s1= -optional(L('b'))) >> L("bc") >> eos) + , backrefs(L("bbc"), L("b"), nilbr) + ) + }; + + return boost::make_iterator_range(test_cases); +} diff --git a/src/boost/libs/xpressive/test/test8u.cpp b/src/boost/libs/xpressive/test/test8u.cpp new file mode 100644 index 00000000..6cb75efc --- /dev/null +++ b/src/boost/libs/xpressive/test/test8u.cpp @@ -0,0 +1,31 @@ +/////////////////////////////////////////////////////////////////////////////// +// test8.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <algorithm> +#include "./test8.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// read the tests from the input file and execute them +void test_main() +{ +#ifndef BOOST_XPRESSIVE_NO_WREGEX + typedef std::wstring::const_iterator iterator_type; + boost::iterator_range<xpr_test_case<iterator_type> const *> rng = get_test_cases<iterator_type>(); + std::for_each(rng.begin(), rng.end(), test_runner<iterator_type>()); +#endif +} + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test8u"); + test->add(BOOST_TEST_CASE(&test_main)); + return test; +} diff --git a/src/boost/libs/xpressive/test/test9.cpp b/src/boost/libs/xpressive/test/test9.cpp new file mode 100644 index 00000000..c0f126d8 --- /dev/null +++ b/src/boost/libs/xpressive/test/test9.cpp @@ -0,0 +1,29 @@ +/////////////////////////////////////////////////////////////////////////////// +// test9.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <algorithm> +#include "./test9.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// read the tests from the input file and execute them +void test_main() +{ + typedef std::string::const_iterator iterator_type; + boost::iterator_range<xpr_test_case<iterator_type> const *> rng = get_test_cases<iterator_type>(); + std::for_each(rng.begin(), rng.end(), test_runner<iterator_type>()); +} + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test9"); + test->add(BOOST_TEST_CASE(&test_main)); + return test; +} diff --git a/src/boost/libs/xpressive/test/test9.hpp b/src/boost/libs/xpressive/test/test9.hpp new file mode 100644 index 00000000..3bab751d --- /dev/null +++ b/src/boost/libs/xpressive/test/test9.hpp @@ -0,0 +1,110 @@ +/////////////////////////////////////////////////////////////////////////////// +// test9.hpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include "./test.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// get_test_cases +// +template<typename BidiIterT> +boost::iterator_range<xpr_test_case<BidiIterT> const *> get_test_cases() +{ + typedef typename boost::iterator_value<BidiIterT>::type char_type; + typedef xpr_test_case<BidiIterT> xpr_test_case; + typedef basic_regex<BidiIterT> regex_type; + + static char_type const *nilbr = 0; + static xpr_test_case const test_cases[] = + { + xpr_test_case + ( + "test151" + , L("bbbc") + , regex_type(bos >> repeat<2>(s1= -optional(L('b'))) >> L("bc") >> eos) + , backrefs(L("bbbc"), L("b"), nilbr) + ) + , xpr_test_case + ( + "test152" + , L("bbbbc") + , regex_type(bos >> repeat<2>(s1= -optional(L('b'))) >> L("bc") >> eos) + , no_match + ) + , xpr_test_case + ( + "test153" + , L("bbbbc") + , regex_type(bos >> *(s1= -optional(L('b'))) >> L('d') >> eos) + , no_match + ) + , xpr_test_case + ( + "test154" + , L("bc") + , regex_type(bos >> -repeat<2>(s1= -optional(L('b'))) >> L("bc") >> eos) + , backrefs(L("bc"), L(""), nilbr) + ) + , xpr_test_case + ( + "test155" + , L("bbc") + , regex_type(bos >> -repeat<2>(s1= -optional(L('b'))) >> L("bc") >> eos) + , backrefs(L("bbc"), L("b"), nilbr) + ) + , xpr_test_case + ( + "test156" + , L("bbbc") + , regex_type(bos >> -repeat<2>(s1= -optional(L('b'))) >> L("bc") >> eos) + , backrefs(L("bbbc"), L("b"), nilbr) + ) + , xpr_test_case + ( + "test157" + , L("bbbbc") + , regex_type(bos >> -repeat<2>(s1= -optional(L('b'))) >> L("bc") >> eos) + , no_match + ) + , xpr_test_case + ( + "test158" + , L("bbbbc") + , regex_type(bos >> -*(s1= -optional(L('b'))) >> L('d') >> eos) + , no_match + ) + , xpr_test_case + ( + "test159" + , L("bbc") + , regex_type(bos >> *(s1= nil | nil | nil | L('b')) >> L("bc") >> eos) + , backrefs(L("bbc"), L(""), nilbr) + ) + , xpr_test_case + ( + "test160" + , L("bbc") + , regex_type(bos >> -*(s1= nil | nil | nil | L('b')) >> L("bc") >> eos) + , backrefs(L("bbc"), L("b"), nilbr) + ) + , xpr_test_case + ( + "test164" + , L("1yzZ^aAc2") + , regex_type(icase(+range(L('Z'),L('a')))) + , backrefs(L("zZ^aA"), nilbr) + ) + , xpr_test_case + ( + "test165" + , L("1yzZ^aAc2") + , regex_type(+range(L('Z'),L('a'))) + , backrefs(L("Z^a"), nilbr) + ) + }; + + return boost::make_iterator_range(test_cases); +} diff --git a/src/boost/libs/xpressive/test/test9u.cpp b/src/boost/libs/xpressive/test/test9u.cpp new file mode 100644 index 00000000..51b1986e --- /dev/null +++ b/src/boost/libs/xpressive/test/test9u.cpp @@ -0,0 +1,31 @@ +/////////////////////////////////////////////////////////////////////////////// +// test9.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <algorithm> +#include "./test9.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// read the tests from the input file and execute them +void test_main() +{ +#ifndef BOOST_XPRESSIVE_NO_WREGEX + typedef std::wstring::const_iterator iterator_type; + boost::iterator_range<xpr_test_case<iterator_type> const *> rng = get_test_cases<iterator_type>(); + std::for_each(rng.begin(), rng.end(), test_runner<iterator_type>()); +#endif +} + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test9u"); + test->add(BOOST_TEST_CASE(&test_main)); + return test; +} diff --git a/src/boost/libs/xpressive/test/test_actions.cpp b/src/boost/libs/xpressive/test/test_actions.cpp new file mode 100644 index 00000000..44b443b5 --- /dev/null +++ b/src/boost/libs/xpressive/test/test_actions.cpp @@ -0,0 +1,287 @@ +/////////////////////////////////////////////////////////////////////////////// +// test_actions.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +//#define BOOST_XPRESSIVE_BETTER_ERRORS + +#include <map> +#include <list> +#include <stack> +#include <numeric> +#include <boost/version.hpp> +#include <boost/xpressive/xpressive_static.hpp> +#include <boost/xpressive/regex_actions.hpp> +#include <boost/test/unit_test.hpp> + +namespace xp = boost::xpressive; + +/////////////////////////////////////////////////////////////////////////////// +// test1 +// simple action which builds a string +void test1() +{ + using namespace boost::xpressive; + + std::string result; + std::string str("foo bar baz foo bar baz"); + sregex rx = (+_w)[ xp::ref(result) += _ ] >> *(' ' >> (+_w)[ xp::ref(result) += ',' + _ ]); + + if(!regex_match(str, rx)) + { + BOOST_ERROR("oops"); + } + else + { + BOOST_CHECK_EQUAL(result, "foo,bar,baz,foo,bar,baz"); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// test2 +// test backtracking over actions +void test2() +{ + using namespace boost::xpressive; + + std::string result; + std::string str("foo bar baz foo bar baz"); + sregex rx = (+_w)[ xp::ref(result) += _ ] >> *(' ' >> (+_w)[ xp::ref(result) += ',' + _ ]) >> repeat<4>(_); + + if(!regex_match(str, rx)) + { + BOOST_ERROR("oops"); + } + else + { + BOOST_CHECK_EQUAL(result, "foo,bar,baz,foo,bar"); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// test3 +// cast string to int, push back into list, use alternate ->* syntax +void test3() +{ + using namespace boost::xpressive; + + std::list<int> result; + std::string str("1 23 456 7890"); +#if BOOST_VERSION >= 103500 + sregex rx = (+_d)[ xp::ref(result)->*push_back( as<int>(_) ) ] + >> *(' ' >> (+_d)[ xp::ref(result)->*push_back( as<int>(_) ) ]); +#else + sregex rx = (+_d)[ push_back(xp::ref(result), as<int>(_) ) ] + >> *(' ' >> (+_d)[ push_back(xp::ref(result), as<int>(_) ) ]); +#endif + + if(!regex_match(str, rx)) + { + BOOST_ERROR("oops"); + } + else + { + BOOST_REQUIRE_EQUAL(result.size(), 4u); + BOOST_CHECK_EQUAL(*result.begin(), 1); + BOOST_CHECK_EQUAL(*++result.begin(), 23); + BOOST_CHECK_EQUAL(*++++result.begin(), 456); + BOOST_CHECK_EQUAL(*++++++result.begin(), 7890); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// test4 +// build a map of strings to integers +void test4() +{ + using namespace boost::xpressive; + + std::map<std::string, int> result; + std::string str("aaa=>1 bbb=>23 ccc=>456"); + sregex pair = ( (s1= +_w) >> "=>" >> (s2= +_d) )[ xp::ref(result)[s1] = as<int>(s2) ]; + sregex rx = pair >> *(+_s >> pair); + + if(!regex_match(str, rx)) + { + BOOST_ERROR("oops"); + } + else + { + BOOST_REQUIRE_EQUAL(result.size(), 3u); + BOOST_CHECK_EQUAL(result["aaa"], 1); + BOOST_CHECK_EQUAL(result["bbb"], 23); + BOOST_CHECK_EQUAL(result["ccc"], 456); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// test4_aux +// build a map of strings to integers, with a late-bound action argument. +void test4_aux() +{ + using namespace boost::xpressive; + placeholder< std::map<std::string, int> > const _map = {{}}; + + sregex pair = ( (s1= +_w) >> "=>" >> (s2= +_d) )[ _map[s1] = as<int>(s2) ]; + sregex rx = pair >> *(+_s >> pair); + + std::string str("aaa=>1 bbb=>23 ccc=>456"); + smatch what; + std::map<std::string, int> result; + what.let(_map = result); // bind the argument! + + BOOST_REQUIRE(regex_match(str, what, rx)); + BOOST_REQUIRE_EQUAL(result.size(), 3u); + BOOST_CHECK_EQUAL(result["aaa"], 1); + BOOST_CHECK_EQUAL(result["bbb"], 23); + BOOST_CHECK_EQUAL(result["ccc"], 456); + + // Try the same test with regex_iterator + result.clear(); + sregex_iterator it(str.begin(), str.end(), pair, let(_map=result)), end; + BOOST_REQUIRE_EQUAL(3, std::distance(it, end)); + BOOST_REQUIRE_EQUAL(result.size(), 3u); + BOOST_CHECK_EQUAL(result["aaa"], 1); + BOOST_CHECK_EQUAL(result["bbb"], 23); + BOOST_CHECK_EQUAL(result["ccc"], 456); + + // Try the same test with regex_token_iterator + result.clear(); + sregex_token_iterator it2(str.begin(), str.end(), pair, (s1,s2), let(_map=result)), end2; + BOOST_REQUIRE_EQUAL(6, std::distance(it2, end2)); + BOOST_REQUIRE_EQUAL(result.size(), 3u); + BOOST_CHECK_EQUAL(result["aaa"], 1); + BOOST_CHECK_EQUAL(result["bbb"], 23); + BOOST_CHECK_EQUAL(result["ccc"], 456); +} + +/////////////////////////////////////////////////////////////////////////////// +// test5 +// calculator that calculates. This is just silly, but hey. +void test5() +{ + using namespace boost::xpressive; + + // test for "local" variables. + local<int> left, right; + + // test for reference<> to an existing variable + std::stack<int> stack_; + reference<std::stack<int> > stack(stack_); + + std::string str("4+5*(3-1)"); + + sregex group, factor, term, expression; + + group = '(' >> by_ref(expression) >> ')'; + factor = (+_d)[ push(stack, as<int>(_)) ] | group; + term = factor >> *( + ('*' >> factor) + [ right = top(stack) + , pop(stack) + , left = top(stack) + , pop(stack) + , push(stack, left * right) + ] + | ('/' >> factor) + [ right = top(stack) + , pop(stack) + , left = top(stack) + , pop(stack) + , push(stack, left / right) + ] + ); + expression = term >> *( + ('+' >> term) + [ right = top(stack) + , pop(stack) + , left = top(stack) + , pop(stack) + , push(stack, left + right) + ] + | ('-' >> term) + [ right = top(stack) + , pop(stack) + , left = top(stack) + , pop(stack) + , push(stack, left - right) + ] + ); + + if(!regex_match(str, expression)) + { + BOOST_ERROR("oops"); + } + else + { + BOOST_REQUIRE_EQUAL(stack_.size(), 1u); + BOOST_CHECK_EQUAL(stack_.top(), 14); + + BOOST_REQUIRE_EQUAL(stack.get().size(), 1u); + BOOST_CHECK_EQUAL(stack.get().top(), 14); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// test6 +// Test as<>() with wide strings. Bug #4496. +void test6() +{ + using namespace boost::xpressive; + + std::wstring version(L"0.9.500"); + + local<int> maj1(0), min1(0), build1(0); + + wsregex re1 = (+_d)[maj1 = as<int>(_)] >> L"." >> + (+_d)[min1 = as<int>(_)] >> L"." >> + (+_d)[build1 = as<int>(_)]; + + BOOST_REQUIRE(regex_match(version, re1)); + + BOOST_CHECK_EQUAL(maj1.get(), 0); + BOOST_CHECK_EQUAL(min1.get(), 9); + BOOST_CHECK_EQUAL(build1.get(), 500); +} + +/////////////////////////////////////////////////////////////////////////////// +// test7 +// Test regex_replace with an xpressive lambda +void test7() +{ + namespace xp = boost::xpressive; + using namespace xp; + + std::map<std::string, std::string> env; + env["XXX"] = "!!!"; + env["YYY"] = "???"; + + std::string text("This is a %XXX% string %YYY% and stuff."); + sregex var = '%' >> (s1 = +_w) >> '%'; + + text = regex_replace(text, var, xp::ref(env)[s1]); + + BOOST_CHECK_EQUAL(text, "This is a !!! string ??? and stuff."); +} + +using namespace boost::unit_test; + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test_actions"); + test->add(BOOST_TEST_CASE(&test1)); + test->add(BOOST_TEST_CASE(&test2)); + test->add(BOOST_TEST_CASE(&test3)); + test->add(BOOST_TEST_CASE(&test4)); + test->add(BOOST_TEST_CASE(&test4_aux)); + test->add(BOOST_TEST_CASE(&test5)); + test->add(BOOST_TEST_CASE(&test6)); + test->add(BOOST_TEST_CASE(&test7)); + return test; +} + diff --git a/src/boost/libs/xpressive/test/test_assert.cpp b/src/boost/libs/xpressive/test/test_assert.cpp new file mode 100644 index 00000000..de0c0ae9 --- /dev/null +++ b/src/boost/libs/xpressive/test/test_assert.cpp @@ -0,0 +1,94 @@ +/////////////////////////////////////////////////////////////////////////////// +// test_assert.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <iostream> +#include <boost/xpressive/xpressive_static.hpp> +#include <boost/xpressive/regex_actions.hpp> +#include <boost/test/unit_test.hpp> + +using namespace boost::xpressive; + +bool three_or_six(ssub_match const &sub) +{ + return sub.length() == 3 || sub.length() == 6; +} + +/////////////////////////////////////////////////////////////////////////////// +// test1 +// simple custom assert that checks the length of a matched sub-expression +void test1() +{ + std::string str("foo barbaz fink"); + // match words of 3 characters or 6 characters. + sregex rx = (bow >> +_w >> eow)[ check(&three_or_six) ] ; + + sregex_iterator first(str.begin(), str.end(), rx), last; + BOOST_CHECK_EQUAL(std::distance(first, last), 2); +} + +/////////////////////////////////////////////////////////////////////////////// +// test2 +// same as above, but using a lambda +void test2() +{ + std::string str("foo barbaz fink"); + // match words of 3 characters or 6 characters. + sregex rx = (bow >> +_w >> eow)[ check(length(_)==3 || length(_)==6) ] ; + + sregex_iterator first(str.begin(), str.end(), rx), last; + BOOST_CHECK_EQUAL(std::distance(first, last), 2); +} + +/////////////////////////////////////////////////////////////////////////////// +// test3 +// more complicated use of custom assertions to validate a date +void test3() +{ + int const days_per_month[] = + {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 31, 31}; + + mark_tag month(1), day(2); + // find a valid date of the form month/day/year. + sregex date = + ( + // Month must be between 1 and 12 inclusive + (month= _d >> !_d) [ check(as<int>(_) >= 1 + && as<int>(_) <= 12) ] + >> '/' + // Day must be between 1 and 31 inclusive + >> (day= _d >> !_d) [ check(as<int>(_) >= 1 + && as<int>(_) <= 31) ] + >> '/' + // Only consider years between 1970 and 2038 + >> (_d >> _d >> _d >> _d) [ check(as<int>(_) >= 1970 + && as<int>(_) <= 2038) ] + ) + // Ensure the month actually has that many days. + [ check( ref(days_per_month)[as<int>(month)-1] >= as<int>(day) ) ] + ; + + smatch what; + std::string str("99/99/9999 2/30/2006 2/28/2006"); + + BOOST_REQUIRE(regex_search(str, what, date)); + BOOST_CHECK_EQUAL(what[0], "2/28/2006"); +} + +using namespace boost::unit_test; + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test_assert"); + test->add(BOOST_TEST_CASE(&test1)); + test->add(BOOST_TEST_CASE(&test2)); + test->add(BOOST_TEST_CASE(&test3)); + return test; +} + diff --git a/src/boost/libs/xpressive/test/test_assert_with_placeholder.cpp b/src/boost/libs/xpressive/test/test_assert_with_placeholder.cpp new file mode 100644 index 00000000..df8be5a0 --- /dev/null +++ b/src/boost/libs/xpressive/test/test_assert_with_placeholder.cpp @@ -0,0 +1,76 @@ +/////////////////////////////////////////////////////////////////////////////// +// test_assert_with_placeholder.hpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/xpressive/xpressive.hpp> +#include <boost/xpressive/regex_actions.hpp> +#include <boost/test/unit_test.hpp> + +using namespace boost::xpressive; + +placeholder<int> const _cnt = {{}}; + +struct count_a_impl +{ + typedef void result_type; + + void operator()(int &cnt) const + { + ++cnt; + } +}; + +boost::xpressive::function<count_a_impl>::type const count_a = {{}}; + +struct check_a_impl +{ + typedef bool result_type; + + bool operator()(int &cnt, int val) const + { + if(cnt < val) + { + ++cnt; + return true; + } + return false; + } +}; + +boost::xpressive::function<check_a_impl>::type const check_a = {{}}; + +void test_assert_with_placeholder() +{ + int cnt = 0; + std::string a_str("a_aaaaa___a_aa_aaa_"); + const sregex expr1(*(as_xpr('a')[count_a(_cnt)] | '_')); + const sregex expr2(*(as_xpr('a')[check(check_a(_cnt, 5))] | '_')); + + sregex_iterator iter1(a_str.begin(), a_str.end(), expr1, + let(_cnt = cnt)); + BOOST_CHECK_EQUAL(iter1->str(0), a_str); + BOOST_CHECK_EQUAL(cnt, 12); + + cnt = 0; + sregex_iterator iter2(a_str.begin(), a_str.end(), expr2, + let(_cnt = cnt)); + + BOOST_CHECK_EQUAL(iter2->str(0), std::string("a_aaaa")); + BOOST_CHECK_EQUAL(cnt, 5); +} + +using namespace boost::unit_test; +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test that custom assertions can use argument placeholders"); + + test->add(BOOST_TEST_CASE(&test_assert_with_placeholder)); + + return test; +} diff --git a/src/boost/libs/xpressive/test/test_basic_regex.cpp b/src/boost/libs/xpressive/test/test_basic_regex.cpp new file mode 100644 index 00000000..13ff2e62 --- /dev/null +++ b/src/boost/libs/xpressive/test/test_basic_regex.cpp @@ -0,0 +1,9 @@ +/////////////////////////////////////////////////////////////////////////////// +// test_basic_regex.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/xpressive/basic_regex.hpp> + diff --git a/src/boost/libs/xpressive/test/test_cycles.cpp b/src/boost/libs/xpressive/test/test_cycles.cpp new file mode 100644 index 00000000..844d2ea3 --- /dev/null +++ b/src/boost/libs/xpressive/test/test_cycles.cpp @@ -0,0 +1,236 @@ +/////////////////////////////////////////////////////////////////////////////// +// test_cycles.hpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// defining this causes regex_impl objects to be counted, allowing us to detect +// leaks portably. +#define BOOST_XPRESSIVE_DEBUG_CYCLE_TEST + +#include <iostream> +#include <boost/test/unit_test.hpp> +#include <boost/xpressive/xpressive.hpp> + +#if defined(_MSC_VER) && defined(_DEBUG) +# define _CRTDBG_MAP_ALLOC +# include <crtdbg.h> +#endif + +using namespace boost::unit_test; +using namespace boost::xpressive; + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// regexes referred to by other regexes are kept alive via reference counting. +// but cycles are handled naturally. the following works as expected and doesn't leak. +void test_main() +{ + { + sregex v; + { + sregex a,b,c; + a = 'a' >> !by_ref(b); + //std::cout << a << std::endl; + //std::cout << b << std::endl; + //std::cout << c << std::endl; + + // just for giggles + c = a; + c = epsilon >> 'a'; + + b = epsilon >> by_ref(c); + //std::cout << a << std::endl; + //std::cout << b << std::endl; + //std::cout << c << std::endl; + + c = epsilon >> by_ref(a); + //std::cout << a << std::endl; + //std::cout << b << std::endl; + //std::cout << c << std::endl; + + v = a; + } + std::string const s("aaa"); + smatch m; + if(!regex_match(s, m, v)) + { + BOOST_ERROR("cycle test 1 failed"); + } + } + + if(0 != detail::regex_impl<std::string::const_iterator>::instances) + { + BOOST_ERROR("leaks detected (cycle test 1)"); + detail::regex_impl<std::string::const_iterator>::instances = 0; + } + + { + sregex v; + { + sregex a,b,c; + b = epsilon >> by_ref(c); + a = 'a' >> !by_ref(b); + c = epsilon >> by_ref(a); + + //std::cout << a << std::endl; + //std::cout << b << std::endl; + //std::cout << c << std::endl; + + v = a; + } + std::string const s("aaa"); + smatch m; + if(!regex_match(s, m, v)) + { + BOOST_ERROR("cycle test 2 failed"); + } + } + + if(0 != detail::regex_impl<std::string::const_iterator>::instances) + { + BOOST_ERROR("leaks detected (cycle test 2)"); + detail::regex_impl<std::string::const_iterator>::instances = 0; + } + + { + sregex v; + { + sregex a,b,c; + + b = epsilon >> by_ref(c); + c = epsilon >> by_ref(a); + a = 'a' >> !by_ref(b); + + //std::cout << a << std::endl; + //std::cout << b << std::endl; + //std::cout << c << std::endl; + + v = a; + } + std::string const s("aaa"); + smatch m; + if(!regex_match(s, m, v)) + { + BOOST_ERROR("cycle test 3 failed"); + } + } + + if(0 != detail::regex_impl<std::string::const_iterator>::instances) + { + BOOST_ERROR("leaks detected (cycle test 3)"); + detail::regex_impl<std::string::const_iterator>::instances = 0; + } + + { + sregex v; + { + sregex a,b,c; + c = epsilon >> by_ref(a); + b = epsilon >> by_ref(c); + a = 'a' >> !by_ref(b); + + //std::cout << a << std::endl; + //std::cout << b << std::endl; + //std::cout << c << std::endl; + + v = a; + } + std::string const s("aaa"); + smatch m; + if(!regex_match(s, m, v)) + { + BOOST_ERROR("cycle test 4 failed"); + } + } + + if(0 != detail::regex_impl<std::string::const_iterator>::instances) + { + BOOST_ERROR("leaks detected (cycle test 4)"); + detail::regex_impl<std::string::const_iterator>::instances = 0; + } + + { + sregex v; + { + sregex a,b,c; + a = 'a' >> !by_ref(b); + b = epsilon >> by_ref(c); + c = epsilon >> by_ref(a); + + sregex d,e; + d = epsilon >> by_ref(e); + e = epsilon >> "aa"; + + c = d; + + //std::cout << a << std::endl; + //std::cout << b << std::endl; + //std::cout << c << std::endl; + //std::cout << e << std::endl; + + e = 'a' >> by_ref(c); + + //std::cout << "-new loop!\n"; + //std::cout << a << std::endl; + //std::cout << b << std::endl; + //std::cout << c << std::endl; + //std::cout << e << std::endl; + + v = a; + + //std::cout << v << std::endl; + + } + std::string const s("aaa"); + smatch m; + if(regex_match(s, m, v)) // OK, this shouldn't match + { + BOOST_ERROR("cycle test 5 failed"); + } + } + + if(0 != detail::regex_impl<std::string::const_iterator>::instances) + { + BOOST_ERROR("leaks detected (cycle test 5)"); + detail::regex_impl<std::string::const_iterator>::instances = 0; + } +} + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test_cycles"); + test->add(BOOST_TEST_CASE(&test_main)); + return test; +} + +/////////////////////////////////////////////////////////////////////////////// +// Debug stuff +// +namespace +{ + const struct debug_init + { + debug_init() + { + #ifdef _MSC_VER + // Send warnings, errors and asserts to STDERR + _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); + _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); + _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); + _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); + _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); + _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); + + // Check for leaks at program termination + _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF | _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG)); + + //_CrtSetBreakAlloc(221); + #endif + } + } dbg; +} diff --git a/src/boost/libs/xpressive/test/test_dynamic.cpp b/src/boost/libs/xpressive/test/test_dynamic.cpp new file mode 100644 index 00000000..b1d2c30c --- /dev/null +++ b/src/boost/libs/xpressive/test/test_dynamic.cpp @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////////// +// test_dynamic.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/xpressive/xpressive_dynamic.hpp> +#include <boost/test/unit_test.hpp> + +/////////////////////////////////////////////////////////////////////////////// +// test_main +void test_main() +{ + using namespace boost::xpressive; + + std::string str("bar"); + sregex rx = sregex::compile("b.*ar"); + smatch what; + + if(!regex_match(str, what, rx)) + { + BOOST_ERROR("oops"); + } +} + +using namespace boost::unit_test; + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test_dynamic"); + test->add(BOOST_TEST_CASE(&test_main)); + return test; +} + diff --git a/src/boost/libs/xpressive/test/test_dynamic_grammar.cpp b/src/boost/libs/xpressive/test/test_dynamic_grammar.cpp new file mode 100644 index 00000000..c11f8267 --- /dev/null +++ b/src/boost/libs/xpressive/test/test_dynamic_grammar.cpp @@ -0,0 +1,107 @@ +////////////////////////////////////////////////////////////////////////////// +// test_dynamic_grammar.cpp +// +// (C) Copyright Eric Niebler 2004. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +/* + Revision history: + 5 March 2007 : Initial version. +*/ + +// defining this causes regex_impl objects to be counted, allowing us to detect +// leaks portably. +#define BOOST_XPRESSIVE_DEBUG_CYCLE_TEST + +#include <boost/xpressive/xpressive.hpp> +#include <boost/test/unit_test.hpp> + +void test_dynamic_grammar() +{ + using namespace boost::xpressive; + + { + sregex expr; + { + sregex_compiler compiler; + regex_constants::syntax_option_type x = regex_constants::ignore_white_space; + + compiler.compile( "(? $group = ) \\( (? $expr ) \\) ", x); + compiler.compile( "(? $factor = ) \\d+ | (? $group ) ", x); + compiler.compile( "(? $term = ) (? $factor ) (?: \\* (? $factor ) | / (? $factor ) )* ", x); + expr = compiler.compile( "(? $expr = ) (? $term ) (?: \\+ (? $term ) | - (? $term ) )* ", x); + } + + std::string str("foo 9*(10+3) bar"); + smatch what; + + if(regex_search(str, what, expr)) + { + BOOST_CHECK_EQUAL(what[0].str(), "9*(10+3)"); + BOOST_CHECK_EQUAL((*what.nested_results().begin())[0].str(), "9*(10+3)"); + BOOST_CHECK_EQUAL((*(*what.nested_results().begin()).nested_results().begin())[0].str(), "9"); + BOOST_CHECK_EQUAL((*++(*what.nested_results().begin()).nested_results().begin())[0].str(), "(10+3)"); + } + else + { + BOOST_ERROR("regex_search test 1 failed"); + } + } + + // Test that all regex_impl instances have been cleaned up correctly + BOOST_CHECK_EQUAL(0, detail::regex_impl<std::string::const_iterator>::instances); +} + +void test_dynamic_grammar2() +{ + using namespace boost::xpressive; + + { + sregex expr; + { + sregex_compiler compiler; + regex_constants::syntax_option_type x = regex_constants::ignore_white_space; + + compiler["group"] = compiler.compile( "\\( (? $expr ) \\) ", x); + compiler["factor"] = compiler.compile( "\\d+ | (? $group ) ", x); + compiler["term"] = compiler.compile( "(? $factor ) (?: \\* (? $factor ) | / (? $factor ) )* ", x); + compiler["expr"] = compiler.compile( "(? $term ) (?: \\+ (? $term ) | - (? $term ) )* ", x); + + expr = compiler["expr"]; + } + + std::string str("foo 9*(10+3) bar"); + smatch what; + + if(regex_search(str, what, expr)) + { + BOOST_CHECK_EQUAL(what[0].str(), "9*(10+3)"); + BOOST_CHECK_EQUAL((*what.nested_results().begin())[0].str(), "9*(10+3)"); + BOOST_CHECK_EQUAL((*(*what.nested_results().begin()).nested_results().begin())[0].str(), "9"); + BOOST_CHECK_EQUAL((*++(*what.nested_results().begin()).nested_results().begin())[0].str(), "(10+3)"); + } + else + { + BOOST_ERROR("regex_search test 2 failed"); + } + } + + // Test that all regex_impl instances have been cleaned up correctly + BOOST_CHECK_EQUAL(0, detail::regex_impl<std::string::const_iterator>::instances); +} + +using namespace boost; +using namespace unit_test; + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("testing dynamic grammars"); + test->add(BOOST_TEST_CASE(&test_dynamic_grammar)); + test->add(BOOST_TEST_CASE(&test_dynamic_grammar2)); + return test; +} diff --git a/src/boost/libs/xpressive/test/test_format.cpp b/src/boost/libs/xpressive/test/test_format.cpp new file mode 100644 index 00000000..66941f3b --- /dev/null +++ b/src/boost/libs/xpressive/test/test_format.cpp @@ -0,0 +1,133 @@ +/////////////////////////////////////////////////////////////////////////////// +// test_format.hpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// Test all the different ways to call regex_replace with a formatter. + +#include <map> +#include <string> +#include <boost/test/unit_test.hpp> +#include <boost/xpressive/xpressive.hpp> + +using namespace boost::xpressive; + +std::map<std::string, std::string> replacements; + +struct format1 +{ + template<typename BidiIter> + std::string operator()(match_results<BidiIter> const &what) const + { + return replacements[what[1].str()]; + } +}; + +struct format2 +{ + template<typename BidiIter, typename OutIter> + OutIter operator()(match_results<BidiIter> const &what, OutIter out) const + { + std::map<std::string, std::string>::const_iterator where = replacements.find(what[1].str()); + if(where != replacements.end()) + out = std::copy((*where).second.begin(), (*where).second.end(), out); + return out; + } +}; + +struct format3 +{ + template<typename BidiIter, typename OutIter> + OutIter operator()(match_results<BidiIter> const &what, OutIter out, regex_constants::match_flag_type) const + { + std::map<std::string, std::string>::const_iterator where = replacements.find(what[1].str()); + if(where != replacements.end()) + out = std::copy((*where).second.begin(), (*where).second.end(), out); + return out; + } +}; + +std::string format_fun(smatch const &what) +{ + return replacements[what[1].str()]; +} + +std::string c_format_fun(cmatch const &what) +{ + return replacements[what[1].str()]; +} + +void test_main() +{ + replacements["X"] = "this"; + replacements["Y"] = "that"; + + std::string input("\"$(X)\" has the value \"$(Y)\""), output; + sregex rx = sregex::compile("\\$\\(([^\\)]+)\\)"); + cregex crx = cregex::compile("\\$\\(([^\\)]+)\\)"); + + std::string result("\"this\" has the value \"that\""); + + output = regex_replace(input, rx, format1()); + BOOST_CHECK_EQUAL(output, result); + + output = regex_replace(input.c_str(), crx, format1()); + BOOST_CHECK_EQUAL(output, result); + + output = regex_replace(input, rx, format2()); + BOOST_CHECK_EQUAL(output, result); + + output = regex_replace(input.c_str(), crx, format2()); + BOOST_CHECK_EQUAL(output, result); + + output = regex_replace(input, rx, format3()); + BOOST_CHECK_EQUAL(output, result); + + output = regex_replace(input.c_str(), crx, format3()); + BOOST_CHECK_EQUAL(output, result); + + output = regex_replace(input, rx, format_fun); + BOOST_CHECK_EQUAL(output, result); + + output = regex_replace(input.c_str(), crx, c_format_fun); + BOOST_CHECK_EQUAL(output, result); + + output = regex_replace(input, rx, &format_fun); + BOOST_CHECK_EQUAL(output, result); + + output = regex_replace(input.c_str(), crx, &c_format_fun); + BOOST_CHECK_EQUAL(output, result); + + output.clear(); + regex_replace(std::back_inserter(output), input.begin(), input.end(), rx, format1()); + BOOST_CHECK_EQUAL(output, result); + + output.clear(); + regex_replace(std::back_inserter(output), input.begin(), input.end(), rx, format2()); + BOOST_CHECK_EQUAL(output, result); + + output.clear(); + regex_replace(std::back_inserter(output), input.begin(), input.end(), rx, format2()); + BOOST_CHECK_EQUAL(output, result); + + output.clear(); + regex_replace(std::back_inserter(output), input.begin(), input.end(), rx, format_fun); + BOOST_CHECK_EQUAL(output, result); + + output.clear(); + regex_replace(std::back_inserter(output), input.begin(), input.end(), rx, &format_fun); + BOOST_CHECK_EQUAL(output, result); +} + +using namespace boost::unit_test; +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test_format"); + test->add(BOOST_TEST_CASE(&test_main)); + return test; +} diff --git a/src/boost/libs/xpressive/test/test_match_results.cpp b/src/boost/libs/xpressive/test/test_match_results.cpp new file mode 100644 index 00000000..879a83a5 --- /dev/null +++ b/src/boost/libs/xpressive/test/test_match_results.cpp @@ -0,0 +1,9 @@ +/////////////////////////////////////////////////////////////////////////////// +// test_match_results.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/xpressive/match_results.hpp> + diff --git a/src/boost/libs/xpressive/test/test_non_char.cpp b/src/boost/libs/xpressive/test/test_non_char.cpp new file mode 100644 index 00000000..ebfb3d68 --- /dev/null +++ b/src/boost/libs/xpressive/test/test_non_char.cpp @@ -0,0 +1,101 @@ +/////////////////////////////////////////////////////////////////////////////// +// test_non_char.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <algorithm> +#include <boost/xpressive/xpressive.hpp> +#include <boost/xpressive/traits/null_regex_traits.hpp> +#include "./test.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// test_static +void test_static() +{ + static int const data[] = {0, 1, 2, 3, 4, 5, 6}; + null_regex_traits<int> nul; + basic_regex<int const *> rex = imbue(nul)(1 >> +((set= 2,3) | 4) >> 5); + match_results<int const *> what; + + if(!regex_search(data, data + (sizeof(data)/sizeof(*data)), what, rex)) + { + BOOST_ERROR("regex_search on integral data failed"); + } + else + { + BOOST_CHECK(*what[0].first == 1); + BOOST_CHECK(*what[0].second == 6); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// UChar +struct UChar +{ + UChar(unsigned int code = 0) + : code_(code) + {} + + operator unsigned int () const + { + return this->code_; + } + +private: + unsigned int code_; +}; + +/////////////////////////////////////////////////////////////////////////////// +// UChar_traits +struct UChar_traits + : null_regex_traits<UChar> +{}; + +/////////////////////////////////////////////////////////////////////////////// +// test_dynamic +void test_dynamic() +{ + typedef std::vector<UChar>::const_iterator uchar_iterator; + typedef basic_regex<uchar_iterator> uregex; + typedef match_results<uchar_iterator> umatch; + typedef regex_compiler<uchar_iterator, UChar_traits> uregex_compiler; + + std::string pattern_("b.*r"), str_("foobarboo"); + std::vector<UChar> pattern(pattern_.begin(), pattern_.end()); + std::vector<UChar> str(str_.begin(), str_.end()); + + UChar_traits tr; + uregex_compiler compiler(tr); + uregex urx = compiler.compile(pattern); + umatch what; + + if(!regex_search(str, what, urx)) + { + BOOST_ERROR("regex_search on UChar failed"); + } + else + { + BOOST_CHECK_EQUAL(3, what.position()); + BOOST_CHECK_EQUAL(3, what.length()); + } + + // test for range-based regex_replace + std::vector<UChar> output = regex_replace(str, urx, pattern_); + std::string output_(output.begin(), output.end()); + std::string expected("foob.*rboo"); + BOOST_CHECK_EQUAL(output_, expected); +} + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test_non_char"); + test->add(BOOST_TEST_CASE(&test_static)); + test->add(BOOST_TEST_CASE(&test_dynamic)); + return test; +} + diff --git a/src/boost/libs/xpressive/test/test_partial_match.cpp b/src/boost/libs/xpressive/test/test_partial_match.cpp new file mode 100644 index 00000000..03dfcb73 --- /dev/null +++ b/src/boost/libs/xpressive/test/test_partial_match.cpp @@ -0,0 +1,21 @@ +/////////////////////////////////////////////////////////////////////////////// +// test_partial_match.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include "./test.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// read the tests from the input file and execute them +void test_main() +{ + + + + + return 0; +} + diff --git a/src/boost/libs/xpressive/test/test_regex_algorithms.cpp b/src/boost/libs/xpressive/test/test_regex_algorithms.cpp new file mode 100644 index 00000000..240baa29 --- /dev/null +++ b/src/boost/libs/xpressive/test/test_regex_algorithms.cpp @@ -0,0 +1,9 @@ +/////////////////////////////////////////////////////////////////////////////// +// test_regex_algorithms.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/xpressive/regex_algorithms.hpp> + diff --git a/src/boost/libs/xpressive/test/test_regex_compiler.cpp b/src/boost/libs/xpressive/test/test_regex_compiler.cpp new file mode 100644 index 00000000..53f1f75e --- /dev/null +++ b/src/boost/libs/xpressive/test/test_regex_compiler.cpp @@ -0,0 +1,9 @@ +/////////////////////////////////////////////////////////////////////////////// +// test_regex_compiler.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/xpressive/regex_compiler.hpp> + diff --git a/src/boost/libs/xpressive/test/test_regex_constants.cpp b/src/boost/libs/xpressive/test/test_regex_constants.cpp new file mode 100644 index 00000000..6cf44a33 --- /dev/null +++ b/src/boost/libs/xpressive/test/test_regex_constants.cpp @@ -0,0 +1,9 @@ +/////////////////////////////////////////////////////////////////////////////// +// test_regex_constants.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/xpressive/regex_constants.hpp> + diff --git a/src/boost/libs/xpressive/test/test_regex_error.cpp b/src/boost/libs/xpressive/test/test_regex_error.cpp new file mode 100644 index 00000000..b7bb464a --- /dev/null +++ b/src/boost/libs/xpressive/test/test_regex_error.cpp @@ -0,0 +1,9 @@ +/////////////////////////////////////////////////////////////////////////////// +// test_regex_error.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/xpressive/regex_error.hpp> + diff --git a/src/boost/libs/xpressive/test/test_regex_iterator.cpp b/src/boost/libs/xpressive/test/test_regex_iterator.cpp new file mode 100644 index 00000000..a2f1628b --- /dev/null +++ b/src/boost/libs/xpressive/test/test_regex_iterator.cpp @@ -0,0 +1,9 @@ +/////////////////////////////////////////////////////////////////////////////// +// test_regex_iterator.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/xpressive/regex_iterator.hpp> + diff --git a/src/boost/libs/xpressive/test/test_regex_primitives.cpp b/src/boost/libs/xpressive/test/test_regex_primitives.cpp new file mode 100644 index 00000000..f1fac0d0 --- /dev/null +++ b/src/boost/libs/xpressive/test/test_regex_primitives.cpp @@ -0,0 +1,9 @@ +/////////////////////////////////////////////////////////////////////////////// +// test_regex_primitives.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/xpressive/regex_primitives.hpp> + diff --git a/src/boost/libs/xpressive/test/test_regex_token_iterator.cpp b/src/boost/libs/xpressive/test/test_regex_token_iterator.cpp new file mode 100644 index 00000000..a3843827 --- /dev/null +++ b/src/boost/libs/xpressive/test/test_regex_token_iterator.cpp @@ -0,0 +1,9 @@ +/////////////////////////////////////////////////////////////////////////////// +// test_regex_token_iterator.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/xpressive/regex_token_iterator.hpp> + diff --git a/src/boost/libs/xpressive/test/test_regex_traits.cpp b/src/boost/libs/xpressive/test/test_regex_traits.cpp new file mode 100644 index 00000000..bb254903 --- /dev/null +++ b/src/boost/libs/xpressive/test/test_regex_traits.cpp @@ -0,0 +1,9 @@ +/////////////////////////////////////////////////////////////////////////////// +// test_regex_traits.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/xpressive/regex_traits.hpp> + diff --git a/src/boost/libs/xpressive/test/test_skip.cpp b/src/boost/libs/xpressive/test/test_skip.cpp new file mode 100644 index 00000000..ba36194d --- /dev/null +++ b/src/boost/libs/xpressive/test/test_skip.cpp @@ -0,0 +1,96 @@ +/////////////////////////////////////////////////////////////////////////////// +// test_skip.hpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <map> +#include <iostream> +#include <boost/xpressive/xpressive.hpp> +#include <boost/xpressive/regex_actions.hpp> +#include <boost/test/unit_test.hpp> + +using namespace boost::unit_test; +using namespace boost::xpressive; + +void test1() +{ + std::string s = "a a b b c c"; + + sregex rx = + "a a" >> + skip(_s) + ( + (s1= as_xpr('b')) >> + as_xpr('b') >> + *as_xpr('c') // causes backtracking + ) >> + "c c"; + + smatch what; + BOOST_CHECK( regex_match(s, what, rx) ); + + s = "123,456,789"; + sregex rx2 = skip(',')(+_d); + BOOST_CHECK( regex_match(s, what, rx2) ); + + s = "foo"; + sregex rx3 = skip(_s)(after("fo") >> 'o'); + BOOST_CHECK( regex_search(s, what, rx3) ); +} + +template<typename Expr> +void test_skip_aux(Expr const &expr) +{ + sregex rx = skip(_s)(expr); +} + +void test_skip() +{ + int i=0; + std::map<std::string, int> syms; + std::locale loc; + + test_skip_aux( 'a' ); + test_skip_aux( _ ); + test_skip_aux( +_ ); + test_skip_aux( -+_ ); + test_skip_aux( !_ ); + test_skip_aux( -!_ ); + test_skip_aux( repeat<0,42>(_) ); + test_skip_aux( -repeat<0,42>(_) ); + test_skip_aux( _ >> 'a' ); + test_skip_aux( _ >> 'a' | _ ); + test_skip_aux( _ >> 'a' | _ >> 'b' ); + test_skip_aux( s1= _ >> 'a' | _ >> 'b' ); + test_skip_aux( icase(_ >> 'a' | _ >> 'b') ); + test_skip_aux( imbue(loc)(_ >> 'a' | _ >> 'b') ); + test_skip_aux( (set='a') ); + test_skip_aux( (set='a','b') ); + test_skip_aux( ~(set='a') ); + test_skip_aux( ~(set='a','b') ); + test_skip_aux( range('a','b') ); + test_skip_aux( ~range('a','b') ); + test_skip_aux( set['a' | alpha] ); + test_skip_aux( ~set['a' | alpha] ); + test_skip_aux( before(_) ); + test_skip_aux( ~before(_) ); + test_skip_aux( after(_) ); + test_skip_aux( ~after(_) ); + test_skip_aux( keep(*_) ); + test_skip_aux( (*_)[ref(i) = as<int>(_) + 1] ); + test_skip_aux( (a1= syms)[ref(i) = a1 + 1] ); +} + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test skip()"); + + test->add(BOOST_TEST_CASE(&test1)); + + return test; +} diff --git a/src/boost/libs/xpressive/test/test_static.cpp b/src/boost/libs/xpressive/test/test_static.cpp new file mode 100644 index 00000000..1057c2f2 --- /dev/null +++ b/src/boost/libs/xpressive/test/test_static.cpp @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////////// +// test_static.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/xpressive/xpressive_static.hpp> +#include <boost/test/unit_test.hpp> + +/////////////////////////////////////////////////////////////////////////////// +// test_main +void test_main() +{ + using namespace boost::xpressive; + + std::string str("bar"); + sregex rx = 'b' >> *_ >> "ar"; + smatch what; + + if(!regex_match(str, what, rx)) + { + BOOST_ERROR("oops"); + } +} + +using namespace boost::unit_test; + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test_static"); + test->add(BOOST_TEST_CASE(&test_main)); + return test; +} + diff --git a/src/boost/libs/xpressive/test/test_sub_match.cpp b/src/boost/libs/xpressive/test/test_sub_match.cpp new file mode 100644 index 00000000..9a39fd56 --- /dev/null +++ b/src/boost/libs/xpressive/test/test_sub_match.cpp @@ -0,0 +1,9 @@ +/////////////////////////////////////////////////////////////////////////////// +// test_sub_match.cpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/xpressive/sub_match.hpp> + diff --git a/src/boost/libs/xpressive/test/test_symbols.cpp b/src/boost/libs/xpressive/test/test_symbols.cpp new file mode 100644 index 00000000..677e3cf8 --- /dev/null +++ b/src/boost/libs/xpressive/test/test_symbols.cpp @@ -0,0 +1,354 @@ +/////////////////////////////////////////////////////////////////////////////// +// test_symbols.cpp +// +// Copyright 2008 David Jenkins. +// Copyright 2008 Eric Niebler. +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <string> +#include <map> +#include <boost/version.hpp> +#include <boost/xpressive/xpressive_static.hpp> +#include <boost/xpressive/regex_actions.hpp> +#include <boost/test/unit_test.hpp> + +#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP() + +namespace xp = boost::xpressive; + +/////////////////////////////////////////////////////////////////////////////// +// test1 +// simple action which builds a *translated* string +void test1() +{ + using namespace boost::xpressive; + + local<std::string> result; + std::string str("foo bar baz foo bar baz"); + std::map<std::string,std::string> map1; + map1["foo"] = "1"; + map1["bar"] = "2"; + map1["baz"] = "3"; + + sregex rx = skip(_s) (+(a1=map1) + [ result += if_else(length(result) > 0, ",", "") + a1 ] + ); + + if(!regex_match(str, rx)) + { + BOOST_ERROR("oops"); + } + else + { + BOOST_CHECK_EQUAL(result.get(), "1,2,3,1,2,3"); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// test2 +// find longest match in symbol table +void test2() +{ + using namespace boost::xpressive; + + local<std::string> result; + std::string str("foobarbazfoobazbazfoobazbar"); + std::map<std::string,std::string> map1; + map1["foo"] = "1"; + map1["bar"] = "2"; + map1["baz"] = "3"; + map1["foobaz"] = "4"; + map1["foobazbaz"] = "5"; + + sregex rx = skip(_s) (+(a1=map1) + [ result += if_else(length(result) > 0, ",", "") + a1 ] + ); + + if(!regex_match(str, rx)) + { + BOOST_ERROR("oops"); + } + else + { + BOOST_CHECK_EQUAL(result.get(), "1,2,3,5,4,2"); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// test3 +// *map* string to int, push back into list, use alternate ->* syntax +void test3() +{ + using namespace boost::xpressive; + + std::list<int> result; + std::string str("foo bar baz bop"); + std::map<std::string,int> map1; + map1["foo"] = 1; + map1["bar"] = 23; + map1["baz"] = 456; + map1["bop"] = 7890; + +#if BOOST_VERSION >= 103500 + sregex rx = skip(_s) (+(a1=map1) + [ xp::ref(result)->*push_back( a1 ) ] + ); +#else + sregex rx = skip(_s) (+(a1=map1) + [ push_back(xp::ref(result), a1 ) ] + ); +#endif + + if(!regex_match(str, rx)) + { + BOOST_ERROR("oops"); + } + else + { + BOOST_REQUIRE_EQUAL(result.size(), 4u); + BOOST_CHECK_EQUAL(*result.begin(), 1); + BOOST_CHECK_EQUAL(*++result.begin(), 23); + BOOST_CHECK_EQUAL(*++++result.begin(), 456); + BOOST_CHECK_EQUAL(*++++++result.begin(), 7890); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// test4 +// use two input maps to build an output map, with a late-bound action argument. +void test4() +{ + using namespace boost::xpressive; + placeholder< std::map<std::string, int> > const _map = {}; + + std::string str("aaa=>1 bbb=>2 ccc=>3"); + std::map<std::string,std::string> map1; + map1["aaa"] = "foo"; + map1["bbb"] = "bar"; + map1["ccc"] = "baz"; + std::map<std::string,int> map2; + map2["1"] = 1; + map2["2"] = 23; + map2["3"] = 456; + + sregex pair = ( (a1=map1) >> "=>" >> (a2= map2) )[ _map[a1] = a2 ]; + sregex rx = pair >> *(+_s >> pair); + + smatch what; + std::map<std::string, int> result; + what.let(_map = result); // bind the argument! + + if(!regex_match(str, what, rx)) + { + BOOST_ERROR("oops"); + } + else + { + BOOST_REQUIRE_EQUAL(result.size(), 3u); + BOOST_CHECK_EQUAL(result["foo"], 1); + BOOST_CHECK_EQUAL(result["bar"], 23); + BOOST_CHECK_EQUAL(result["baz"], 456); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// test5 +// test nine maps and attributes +void test5() +{ + using namespace boost::xpressive; + + local<int> result(0); + std::string str("abcdefghi"); + std::map<std::string,int> map1; + std::map<std::string,int> map2; + std::map<std::string,int> map3; + std::map<std::string,int> map4; + std::map<std::string,int> map5; + std::map<std::string,int> map6; + std::map<std::string,int> map7; + std::map<std::string,int> map8; + std::map<std::string,int> map9; + map1["a"] = 1; + map2["b"] = 2; + map3["c"] = 3; + map4["d"] = 4; + map5["e"] = 5; + map6["f"] = 6; + map7["g"] = 7; + map8["h"] = 8; + map9["i"] = 9; + + sregex rx = + (a1=map1)[ result += a1 ] + >> (a2=map2)[ result += a2 ] + >> (a3=map3)[ result += a3 ] + >> (a4=map4)[ result += a4 ] + >> (a5=map5)[ result += a5 ] + >> (a6=map6)[ result += a6 ] + >> (a7=map7)[ result += a7 ] + >> (a8=map8)[ result += a8 ] + >> (a9=map9)[ result += a9 ]; + + if(!regex_match(str, rx)) + { + BOOST_ERROR("oops"); + } + else + { + BOOST_CHECK_EQUAL(result.get(), 45); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// test6 +// test case-sensitivity +void test6() +{ + using namespace boost::xpressive; + + local<std::string> result; + std::map<std::string,std::string> map1; + map1["a"] = "1"; + map1["A"] = "2"; + map1["b"] = "3"; + map1["B"] = "4"; + std::string str("a A b B a A b B"); + sregex rx = skip(_s)( + icase(a1= map1) [ result = a1 ] + >> repeat<3>( (icase(a1= map1) [ result += ',' + a1 ]) ) + >> repeat<4>( ((a1= map1) [ result += ',' + a1 ]) ) + ); + if(!regex_match(str, rx)) + { + BOOST_ERROR("oops"); + } + else + { + BOOST_CHECK_EQUAL(result.get(), "1,1,3,3,1,2,3,4"); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// test7 +// test multiple mutually-exclusive maps and default attribute value +void test7() +{ + using namespace boost::xpressive; + + local<std::string> result; + std::map<std::string,std::string> map1; + map1["a"] = "1"; + map1["b"] = "2"; + std::map<std::string,std::string> map2; + map2["c"] = "3"; + map2["d"] = "4"; + std::string str("abcde"); + sregex rx = *((a1= map1) | (a1= map2) | 'e') [ result += (a1 | "9") ]; + if(!regex_match(str, rx)) + { + BOOST_ERROR("oops"); + } + else + { + BOOST_CHECK_EQUAL(result.get(), "12349"); + } +} + +#ifndef BOOST_XPRESSIVE_NO_WREGEX +struct City +{ + std::wstring name; + char const* nickname; + int population; +}; + +BOOST_TYPEOF_REGISTER_TYPE(City) + +/////////////////////////////////////////////////////////////////////////////// +// test8 +// test wide strings with structure result +void test8() +{ + using namespace boost::xpressive; + + City cities[] = { + {L"Chicago", "The Windy City", 945000}, + {L"New York", "The Big Apple", 16626000}, + {L"\u041c\u043E\u0441\u043A\u0432\u0430", "Moscow", 9299000} + }; + int const nbr_cities = sizeof(cities)/sizeof(*cities); + + std::map<std::wstring, City> map1; + for(int i=0; i<nbr_cities; ++i) + { + map1[cities[i].name] = cities[i]; + } + + std::wstring str(L"Chicago \u041c\u043E\u0441\u043A\u0432\u0430"); + local<City> result1, result2; + wsregex rx = (a1= map1)[ result1 = a1 ] >> +_s + >> (a1= map1)[ result2 = a1 ]; + if(!regex_match(str, rx)) + { + BOOST_ERROR("oops"); + } + else + { + BOOST_CHECK_EQUAL(result1.get().nickname, "The Windy City"); + BOOST_CHECK_EQUAL(result2.get().nickname, "Moscow"); + } +} +#else +void test8() +{ + // This test is empty +} +#endif + +/////////////////////////////////////////////////////////////////////////////// +// test9 +// test "not before" using a map +void test9() +{ + using namespace boost::xpressive; + + std::string result; + std::string str("foobar"); + std::map<std::string,int> map1; + map1["foo"] = 1; + sregex rx = ~before((a1=map1)[a1]) >> + (s1=*_w)[ xp::ref(result) = s1 ]; + if(!regex_match(str, rx)) + { + BOOST_CHECK_EQUAL(result, ""); + } + else + { + BOOST_ERROR("oops"); + } +} + +using namespace boost::unit_test; + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test_symbols"); + test->add(BOOST_TEST_CASE(&test1)); + test->add(BOOST_TEST_CASE(&test2)); + test->add(BOOST_TEST_CASE(&test3)); + test->add(BOOST_TEST_CASE(&test4)); + test->add(BOOST_TEST_CASE(&test5)); + test->add(BOOST_TEST_CASE(&test6)); + test->add(BOOST_TEST_CASE(&test7)); + test->add(BOOST_TEST_CASE(&test8)); + test->add(BOOST_TEST_CASE(&test9)); + return test; +} + diff --git a/src/boost/libs/xpressive/test/test_typeof.cpp b/src/boost/libs/xpressive/test/test_typeof.cpp new file mode 100644 index 00000000..85917e4b --- /dev/null +++ b/src/boost/libs/xpressive/test/test_typeof.cpp @@ -0,0 +1,235 @@ +/////////////////////////////////////////////////////////////////////////////// +// test_typeof.cpp +// +// Copyright 2008 David Jenkins. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#define BOOST_TYPEOF_LIMIT_SIZE 200 +#define BOOST_TYPEOF_EMULATION 1 + +#include <string> +#include <boost/version.hpp> +#include <boost/xpressive/xpressive_static.hpp> +#include <boost/xpressive/xpressive_typeof.hpp> +#include <boost/test/unit_test.hpp> + +// I couldn't find these registrations anywhere else, so I put them here +// They are necessary for this program to compile +#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP() +BOOST_TYPEOF_REGISTER_TEMPLATE(boost::mpl::int_, (int)) +BOOST_TYPEOF_REGISTER_TEMPLATE(boost::reference_wrapper, (typename)) + +// Here's the test for typeof registration, to be used on static regular expressions +#define TYPEOF_TEST(Expr) { BOOST_PROTO_AUTO(Dummy, Expr); } + +namespace xp = boost::xpressive; + +/////////////////////////////////////////////////////////////////////////////// +// test_misc1 +// miscelaneous regular expressions +static void test_misc1() +{ + using namespace boost::xpressive; + + TYPEOF_TEST(epsilon); + TYPEOF_TEST(nil); + TYPEOF_TEST(alnum); + TYPEOF_TEST(bos); + TYPEOF_TEST(eos); + TYPEOF_TEST(bol); + TYPEOF_TEST(eol); + TYPEOF_TEST(bow); + TYPEOF_TEST(eow); + TYPEOF_TEST(_b); + TYPEOF_TEST(_w); + TYPEOF_TEST(_d); + TYPEOF_TEST(_s); + TYPEOF_TEST(_n); + TYPEOF_TEST(_ln); + TYPEOF_TEST(_); + TYPEOF_TEST(self); +} + +/////////////////////////////////////////////////////////////////////////////// +// test_misc2 +// miscelaneous regular expressions +static void test_misc2() +{ + using namespace boost::xpressive; + + TYPEOF_TEST(+set[_d | '-' | 'g']); + TYPEOF_TEST(+set['g' | as_xpr('-') | _d]); + TYPEOF_TEST(icase(+range('a','g'))); + TYPEOF_TEST(+range('-','/')); + TYPEOF_TEST(+range('+','-')); + TYPEOF_TEST(+range('b','b')); + TYPEOF_TEST(icase((s1= "foo") >> *_ >> '\15')); + TYPEOF_TEST(repeat<2>(repeat<3>(_d) >> '-') >> repeat<4>(_d)); + TYPEOF_TEST('f' >> +as_xpr('o')); + TYPEOF_TEST(icase(+(s1= "foo") >> "foobar")); + cregex parens = '(' >> *( keep( +~(set='(',')') ) | by_ref(parens) ) >> ')'; + TYPEOF_TEST(_b >> "sublist" >> parens); + TYPEOF_TEST(bos >> "baz" | "bar"); + TYPEOF_TEST(icase(*_ >> "foo")); + TYPEOF_TEST(icase(*_ >> "boo" | "bar")); + TYPEOF_TEST(icase("bar")); + + TYPEOF_TEST(('f' >> repeat<1,repeat_max>('o'))); + TYPEOF_TEST("This " >> (s1= "(has)") >> ' ' >> (s2= "parens")); + TYPEOF_TEST(as_xpr("This (has parens")); + TYPEOF_TEST(+_d); + TYPEOF_TEST(+~_d); + TYPEOF_TEST(+set[_d]); + TYPEOF_TEST(+set[~_d]); + TYPEOF_TEST(+~set[~_d]); + TYPEOF_TEST(+~set[_d]); + TYPEOF_TEST(+set[~_w | ~_d]); + TYPEOF_TEST(+~set[_w | _d]); + TYPEOF_TEST((s1= '(' >> (s2= nil) | '[' >> (s3= nil)) >> -*_ >> (s4= ')') >> s2 | ']' >> s3); + TYPEOF_TEST(after("foo") >> "bar"); + TYPEOF_TEST(after(s1= 'f' >> _ >> 'o') >> "bar"); + TYPEOF_TEST(icase(after(s1= "fo") >> 'o')); + TYPEOF_TEST(icase(~after(s1= "fo") >> 'o')); + TYPEOF_TEST(+alpha); + TYPEOF_TEST(+set[alpha | digit]); + TYPEOF_TEST(after(s1= nil) >> 'a'); + TYPEOF_TEST(after(s1= "abc" >> repeat<3>(_d)) >> "foo"); + TYPEOF_TEST(~before(bol) >> 'x'); + TYPEOF_TEST(~before(bos) >> 'x'); +} + +/////////////////////////////////////////////////////////////////////////////// +// test_misc3 +// miscelaneous regular expressions + +static void test_misc3() +{ + using namespace boost::xpressive; + + TYPEOF_TEST(as_xpr("foo")); + TYPEOF_TEST('b' >> *_ >> "ar"); + TYPEOF_TEST('b' >> *_ >> 'r'); + TYPEOF_TEST('b' >> +_ >> "ar"); + TYPEOF_TEST('b' >> +_ >> 'r'); + TYPEOF_TEST('b' >> +_ >> "oo"); + TYPEOF_TEST(bos >> "foo"); + TYPEOF_TEST(bos >> 'b' >> *_ >> "ar"); + TYPEOF_TEST('b' >> +_ >> "ar" >> eos); + TYPEOF_TEST('b' >> +_ >> 'o' >> eos); + TYPEOF_TEST(bos >> (s1= !(set='-','+') >> +range('0','9') + >> !(s2= '.' >> *range('0','9'))) + >> (s3= (set='C','F')) >> eos); + TYPEOF_TEST( !(s1= as_xpr('+')|'-') >> (s2= +range('0','9') >> !as_xpr('.') >> *range('0','9') | + '.' >> +range('0','9')) >> !(s3= (set='e','E') >> !(s4= as_xpr('+')|'-') >> +range('0','9'))); + TYPEOF_TEST('f' | icase('g')); + TYPEOF_TEST(icase(+lower)); + TYPEOF_TEST(icase(+as_xpr('\x61'))); + TYPEOF_TEST(icase(+set['\x61'])); + TYPEOF_TEST(icase(+as_xpr('\x0061'))); + TYPEOF_TEST(icase(+set['\x0061'])); + TYPEOF_TEST('a' >> +(s1= 'b' | (s2= *(s3= 'c'))) >> 'd'); + TYPEOF_TEST('a' >> +(s1= 'b' | (s2= !(s3= 'c'))) >> 'd'); + TYPEOF_TEST(*as_xpr('a') >> *as_xpr('a') >> *as_xpr('a') >> *as_xpr('a') >> *as_xpr('a') >> 'b'); + TYPEOF_TEST(*set[range('a','z') | range('A','Z')]); +} + +/////////////////////////////////////////////////////////////////////////////// +// test_misc4 +// miscelaneous regular expressions +static void test_misc4() +{ + using namespace boost::xpressive; + TYPEOF_TEST('a' >> bos >> 'b'); + TYPEOF_TEST(as_xpr("a^b")); + TYPEOF_TEST('a' >> ~set[' '] >> 'b'); + TYPEOF_TEST('a' >> ~set['^'] >> 'b'); + TYPEOF_TEST('a' >> ~set['^'] >> 'b'); + TYPEOF_TEST('a' >> set['^'] >> 'b'); + TYPEOF_TEST(icase("foo" >> before("bar"))); + TYPEOF_TEST(icase("foo" >> ~before("bar"))); + TYPEOF_TEST(icase("foo" >> ~before("bar"))); + TYPEOF_TEST(icase(+(s1= keep(s2= "foo") >> "bar"))); + TYPEOF_TEST(+(s1= "bar" | (s2= "foo"))); + TYPEOF_TEST(+(s1= (s2= "bar") | "foo")); + TYPEOF_TEST(+(s1= "foo" | (s2= "bar"))); + TYPEOF_TEST(+(s1= (s2= "foo") | "bar")); + TYPEOF_TEST((s1= icase("FOO")) >> (s2= -*_) >> s1); + TYPEOF_TEST((s1= icase("FOO")) >> (s2= -*_) >> icase(s1)); + TYPEOF_TEST(+(s1= "foo" | icase(s1 >> 'O'))); + TYPEOF_TEST((bos >> set[range('A','Z') | range('a','m')])); + TYPEOF_TEST(('f' >> repeat<2,5>('o'))); + TYPEOF_TEST(('f' >> -repeat<2,5>('o'))); + TYPEOF_TEST(('f' >> repeat<2,5>('o') >> 'o')); + TYPEOF_TEST(('f' >> -repeat<2,5>('o') >> 'o')); + TYPEOF_TEST(bos >> '{' >> *_ >> '}' >> eos); + TYPEOF_TEST(+(set='+','-')); + TYPEOF_TEST(+(set='-','+')); +} + +/////////////////////////////////////////////////////////////////////////////// +// test_misc5 +// miscelaneous regular expressions +static void test_misc5() +{ + using namespace boost::xpressive; + TYPEOF_TEST(bos >> ('(' >> (s1= nil) | (s2= nil)) >> +_w >> (')' >> s1 | s2) >> eos); + TYPEOF_TEST(+~alpha); + TYPEOF_TEST(+set[alpha | ~alpha]); + TYPEOF_TEST(+~set[~alpha]); + TYPEOF_TEST(as_xpr("[[:alpha:]\\y]+")); + TYPEOF_TEST(+~set[~alnum | ~digit]); + TYPEOF_TEST(icase(bos >> repeat<4>(s1= 'a' >> !s1) >> eos)); + TYPEOF_TEST(as_xpr("foo") >> /*This is a comment[*/ "bar"); + TYPEOF_TEST(bos >> "foobar" >> eos); + TYPEOF_TEST(bos >> 'f' >> *as_xpr('o')); + TYPEOF_TEST(bos >> 'f' >> *as_xpr('\157')); + TYPEOF_TEST(bos >> ("foo" >> set[' '] >> "bar") >> eos /*This is a comment*/); +} + +/////////////////////////////////////////////////////////////////////////////// +// test_misc6 +// miscelaneous regular expressions +static void test_misc6() +{ + using namespace boost::xpressive; + TYPEOF_TEST(bos >> *(s1= optional('a')) >> eos); + TYPEOF_TEST(bos >> -*(s1= optional('a')) >> eos); + TYPEOF_TEST(bos >> repeat<2>(s1= optional('b')) >> "bc" >> eos); + TYPEOF_TEST(bos >> *(s1= optional('b')) >> 'd' >> eos); + TYPEOF_TEST(bos >> -repeat<2>(s1= optional('b')) >> "bc" >> eos); + TYPEOF_TEST(bos >> -*(s1= optional('b')) >> 'd' >> eos); + TYPEOF_TEST(bos >> repeat<2>(s1= -optional('b')) >> "bc" >> eos); + TYPEOF_TEST(bos >> *(s1= -optional('b')) >> 'd' >> eos); + TYPEOF_TEST(bos >> -repeat<2>(s1= -optional('b')) >> "bc" >> eos); + TYPEOF_TEST(bos >> -*(s1= -optional('b')) >> 'd' >> eos); + TYPEOF_TEST(bos >> *(s1= nil | nil | nil | 'b') >> "bc" >> eos); + TYPEOF_TEST(bos >> -*(s1= nil | nil | nil | 'b') >> "bc" >> eos); + TYPEOF_TEST(icase(+range('Z','a'))); + TYPEOF_TEST(+range('Z','a')); +} + +// These functions are defined in test_typeof2.cpp +void test_actions(); +void test_symbols(); +void test_assert(); + +using namespace boost::unit_test; + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test_typeof"); + test->add(BOOST_TEST_CASE(&test_misc1)); + test->add(BOOST_TEST_CASE(&test_misc2)); + test->add(BOOST_TEST_CASE(&test_misc3)); + test->add(BOOST_TEST_CASE(&test_misc4)); + test->add(BOOST_TEST_CASE(&test_misc5)); + test->add(BOOST_TEST_CASE(&test_misc6)); + test->add(BOOST_TEST_CASE(&test_actions)); + test->add(BOOST_TEST_CASE(&test_symbols)); + test->add(BOOST_TEST_CASE(&test_assert)); + return test; +} diff --git a/src/boost/libs/xpressive/test/test_typeof2.cpp b/src/boost/libs/xpressive/test/test_typeof2.cpp new file mode 100644 index 00000000..e94f11c2 --- /dev/null +++ b/src/boost/libs/xpressive/test/test_typeof2.cpp @@ -0,0 +1,178 @@ +/////////////////////////////////////////////////////////////////////////////// +// test_typeof2.cpp +// +// Copyright 2008 David Jenkins. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#define BOOST_TYPEOF_LIMIT_SIZE 200 +#define BOOST_TYPEOF_EMULATION 1 + +#include <string> +#include <map> +#include <list> +#include <stack> +#include <boost/version.hpp> +#include <boost/xpressive/xpressive_static.hpp> +#include <boost/xpressive/regex_actions.hpp> +#include <boost/xpressive/xpressive_typeof.hpp> +#include <boost/typeof/std/stack.hpp> +#include <boost/typeof/std/list.hpp> +#include <boost/test/unit_test.hpp> + + +// I couldn't find these registrations anywhere else, so I put them here +// They are necessary for this program to compile +#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP() +BOOST_TYPEOF_REGISTER_TEMPLATE(boost::mpl::int_, (int)) +BOOST_TYPEOF_REGISTER_TEMPLATE(boost::reference_wrapper, (typename)) + +// Here's the test for typeof registration, to be used on static regular expressions +#define TYPEOF_TEST(Expr) { BOOST_PROTO_AUTO(Dummy, Expr); } + +namespace xp = boost::xpressive; + +/////////////////////////////////////////////////////////////////////////////// +// test_actions +// regular expressions from test_actions.cpp +void test_actions() +{ + using namespace boost::xpressive; + // regexes from test_actions.cpp + std::string result; + TYPEOF_TEST((+_w)[ xp::ref(result) += _ ] >> *(' ' >> (+_w)[ xp::ref(result) += ',' + _ ])); + TYPEOF_TEST((+_w)[ xp::ref(result) += _ ] >> *(' ' >> (+_w)[ xp::ref(result) += ',' + _ ]) >> repeat<4>(_)); + std::list<int> result2; + TYPEOF_TEST((+_d)[ xp::ref(result2)->*push_back( as<int>(_) ) ] + >> *(' ' >> (+_d)[ xp::ref(result2)->*push_back( as<int>(_) ) ])); + std::map<std::string, int> result3; + TYPEOF_TEST(( (s1= +_w) >> "=>" >> (s2= +_d) )[ xp::ref(result3)[s1] = as<int>(s2) ]); + placeholder< std::map<std::string, int> > const _map5 = {{}}; + TYPEOF_TEST(( (s1= +_w) >> "=>" >> (s2= +_d) )[ _map5[s1] = as<int>(s2) ]); + + smatch what; + placeholder< std::map<std::string, int> > const _map6 = {{}}; + std::map<std::string, int> result6; + what.let(_map6 = result6); // bind the argument! + + local<int> left, right; + std::stack<int> stack_; + reference<std::stack<int> > stack(stack_); + cregex expression2, factor2, term2, group2; + TYPEOF_TEST( '(' >> by_ref(expression2) >> ')'); + TYPEOF_TEST( (+_d)[ push(stack, as<int>(_)) ] | group2); + TYPEOF_TEST(factor2 >> *( + ('*' >> factor2) + [ right = top(stack) + , pop(stack) + , left = top(stack) + , pop(stack) + , push(stack, left * right) + ] + )); + TYPEOF_TEST(term2 >> *( + ('+' >> term2) + [ right = top(stack) + , pop(stack) + , left = top(stack) + , pop(stack) + , push(stack, left + right) + ] + )); +} + + +#ifndef BOOST_XPRESSIVE_NO_WREGEX + struct City + { + std::wstring name; + char const* nickname; + int population; + }; + BOOST_TYPEOF_REGISTER_TYPE(City) +#endif + +/////////////////////////////////////////////////////////////////////////////// +// test_symbols +// regular expressions from test_symbols.cpp +void test_symbols() +{ + using namespace boost::xpressive; + std::string result; + std::map<std::string,std::string> map10; + TYPEOF_TEST((a1=map10)[ xp::ref(result) = a1 ] >> *(' ' >> (a1=map10)[ xp::ref(result) += ',' + a1 ])); + TYPEOF_TEST((a1=map10)[ xp::ref(result) = a1 ] + >> *((a1=map10)[ xp::ref(result) += ',', xp::ref(result) += a1 ])); + std::list<int> result12; + std::map<std::string,int> map12; + TYPEOF_TEST((a1=map12)[ xp::ref(result12)->*push_back( a1 ) ] + >> *(' ' >> (a1=map12)[ xp::ref(result12)->*push_back( a1 ) ])); + + placeholder< std::map<std::string, int> > const _map13 = {}; + BOOST_PROTO_AUTO(pair13, ( (a1=map10) >> "=>" >> (a2= map12) )[ _map13[a1] = a2 ]); + smatch what; + std::map<std::string, int> result13; + what.let(_map13 = result13); + TYPEOF_TEST(pair13 >> *(+_s >> pair13)); + + int result14 = 0; + std::map<std::string,int> map1a; + std::map<std::string,int> map2a; + std::map<std::string,int> map3a; + TYPEOF_TEST((a1=map1a)[ xp::ref(result14) += a1 ] + >> (a2=map2a)[ xp::ref(result) += a2 ] + >> (a3=map3a)[ xp::ref(result) += a3 ] + ); + { + TYPEOF_TEST(icase(a1= map10) [ xp::ref(result) = a1 ] + >> repeat<3>( (' ' >> icase(a1= map10) [ xp::ref(result) += ',', xp::ref(result) += a1 ]) ) + ); + TYPEOF_TEST(*((a1= map1a) | (a1= map2a) | 'e') [ xp::ref(result) += (a1 | "9") ]); + } +#ifndef BOOST_XPRESSIVE_NO_WREGEX + City result17a, result17b; + std::map<std::wstring, City> map17; + TYPEOF_TEST((a1= map17)[ xp::ref(result17a) = a1 ] >> +_s + >> (a1= map17)[ xp::ref(result17b) = a1 ]); +#else + // This test is empty +#endif + +} + +bool three_or_six(xp::csub_match const &sub) +{ + return sub.length() == 3 || sub.length() == 6; +} + +/////////////////////////////////////////////////////////////////////////////// +// test_assert +// regular expressions from test_assert.cpp +void test_assert() +{ + using namespace boost::xpressive; + std::string result; + TYPEOF_TEST((bow >> +_w >> eow)[ check(&three_or_six) ]); + TYPEOF_TEST((bow >> +_w >> eow)[ check(length(_)==3 || length(_)==6) ]); + int const days_per_month[] = + {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 31, 31}; + mark_tag month(1), day(2); + // Note: if you uncomment the lines below, + // the BOOST_TYPEOF_LIMIT_SIZE is exceeded + TYPEOF_TEST(( + // Month must be between 1 and 12 inclusive + (month= _d >> !_d) [ check(as<int>(_) >= 1 + && as<int>(_) <= 12) ] + //>> '/' + // // Day must be between 1 and 31 inclusive + //>> (day= _d >> !_d) [ check(as<int>(_) >= 1 + // && as<int>(_) <= 31) ] + //>> '/' + // // Only consider years between 1970 and 2038 + //>> (_d >> _d >> _d >> _d) [ check(as<int>(_) >= 1970 + // && as<int>(_) <= 2038) ] + ) + // Ensure the month actually has that many days. + [ check( ref(days_per_month)[as<int>(month)-1] >= as<int>(day) ) ]); +} + |