1 /*
2  *
3  * Copyright (c) 2009
4  * John Maddock
5  *
6  * Use, modification and distribution are subject to the
7  * Boost Software License, Version 1.0. (See accompanying file
8  * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9  *
10  */
11 
12 #include <boost/regex.hpp>
13 #include <boost/test/test_tools.hpp>
14 
15 #ifdef BOOST_INTEL
16 #pragma warning(disable:1418 981 983 383)
17 #endif
18 
19 template <class charT>
test_named_subexpressions(charT)20 void test_named_subexpressions(charT)
21 {
22    //
23    // Really this is just a test that the overloaded access functions work correctly:
24    //
25    static const charT e[] =
26    {
27       '(', '?', '\'', 'o', 'n', 'e', '\'', 'a', '+', ')', '(', '?', '<', 't', 'w', 'o', '>', 'b', '+', ')', '\0'
28    };
29    static const charT t[] =
30    {
31       'm', 'm', 'a', 'a', 'a', 'b', 'b', 'n', 'n', '\0'
32    };
33    static const charT one[] =
34    {
35       'o', 'n', 'e', '\0'
36    };
37    static const charT two[] =
38    {
39       't', 'w', 'o', '\0'
40    };
41    static const std::basic_string<charT> s_one(one);
42    static const std::basic_string<charT> s_two(two);
43    static const charT result1[] = { 'a', 'a', 'a', '\0' };
44    static const charT result2[] = { 'b', 'b', '\0' };
45    static const std::basic_string<charT> s_result1(result1);
46    static const std::basic_string<charT> s_result2(result2);
47 
48    static const char* c_one = "one";
49    static const char* c_two = "two";
50    static const std::string cs_one(c_one);
51    static const std::string cs_two(c_two);
52 
53    boost::basic_regex<charT> expression(e);
54    boost::match_results<const charT*> what;
55    if(regex_search(t, what, expression))
56    {
57       BOOST_CHECK(what.length(1) == 3);
58       BOOST_CHECK(what.length(one) == 3);
59       BOOST_CHECK(what.length(s_one) == 3);
60       BOOST_CHECK(what.length(c_one) == 3);
61       BOOST_CHECK(what.length(cs_one) == 3);
62       BOOST_CHECK(what.position(1) == 2);
63       BOOST_CHECK(what.position(one) == 2);
64       BOOST_CHECK(what.position(s_one) == 2);
65       BOOST_CHECK(what.position(c_one) == 2);
66       BOOST_CHECK(what.position(cs_one) == 2);
67       BOOST_CHECK(what.str(1) == s_result1);
68       BOOST_CHECK(what.str(one) == s_result1);
69       BOOST_CHECK(what.str(s_one) == s_result1);
70       BOOST_CHECK(what.str(c_one) == s_result1);
71       BOOST_CHECK(what.str(cs_one) == s_result1);
72       BOOST_CHECK(what[1] == s_result1);
73       BOOST_CHECK(what[one] == s_result1);
74       BOOST_CHECK(what[s_one] == s_result1);
75       BOOST_CHECK(what[c_one] == s_result1);
76       BOOST_CHECK(what[cs_one] == s_result1);
77 
78       BOOST_CHECK(what.length(2) == 2);
79       BOOST_CHECK(what.length(two) == 2);
80       BOOST_CHECK(what.length(s_two) == 2);
81       BOOST_CHECK(what.length(c_two) == 2);
82       BOOST_CHECK(what.length(cs_two) == 2);
83       BOOST_CHECK(what.position(2) == 5);
84       BOOST_CHECK(what.position(two) == 5);
85       BOOST_CHECK(what.position(s_two) == 5);
86       BOOST_CHECK(what.position(c_two) == 5);
87       BOOST_CHECK(what.position(cs_two) == 5);
88       BOOST_CHECK(what.str(2) == s_result2);
89       BOOST_CHECK(what.str(two) == s_result2);
90       BOOST_CHECK(what.str(s_two) == s_result2);
91       BOOST_CHECK(what.str(c_two) == s_result2);
92       BOOST_CHECK(what.str(cs_two) == s_result2);
93       BOOST_CHECK(what[2] == s_result2);
94       BOOST_CHECK(what[two] == s_result2);
95       BOOST_CHECK(what[s_two] == s_result2);
96       BOOST_CHECK(what[c_two] == s_result2);
97       BOOST_CHECK(what[cs_two] == s_result2);
98    }
99    else
100    {
101       BOOST_ERROR("Expected match not found");
102    }
103 }
104 
test_main(int,char * [])105 int test_main( int , char* [] )
106 {
107    test_named_subexpressions(char(0));
108    test_named_subexpressions(wchar_t(0));
109    return 0;
110 }
111 
112 #include <boost/test/included/test_exec_monitor.hpp>
113