1 /*
2 *
3 * Copyright (c) 2004
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 "test.hpp"
13 #include <iostream>
14 #include <iomanip>
15
16 #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)\
17 && !BOOST_WORKAROUND(__HP_aCC, BOOST_TESTED_AT(55500))\
18 && !(defined(__GNUC__) && (__GNUC__ < 3) && !(defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)))
19
20 template <class T1, class T2>
test_less(const T1 & t1,const T2 & t2)21 void test_less(const T1& t1, const T2& t2)
22 {
23 if(!(t1 < t2))
24 {
25 BOOST_REGEX_TEST_ERROR("Failed < comparison", char);
26 }
27 if(!(t1 <= t2))
28 {
29 BOOST_REGEX_TEST_ERROR("Failed <= comparison", char);
30 }
31 if(!(t1 != t2))
32 {
33 BOOST_REGEX_TEST_ERROR("Failed != comparison", char);
34 }
35 if(t1 == t2)
36 {
37 BOOST_REGEX_TEST_ERROR("Failed == comparison", char);
38 }
39 if(t1 >= t2)
40 {
41 BOOST_REGEX_TEST_ERROR("Failed >= comparison", char);
42 }
43 if(t1 > t2)
44 {
45 BOOST_REGEX_TEST_ERROR("Failed > comparison", char);
46 }
47 }
48
49 template <class T1, class T2>
test_greater(const T1 & t1,const T2 & t2)50 void test_greater(const T1& t1, const T2& t2)
51 {
52 if(t1 < t2)
53 {
54 BOOST_REGEX_TEST_ERROR("Failed < comparison", char);
55 }
56 if(t1 <= t2)
57 {
58 BOOST_REGEX_TEST_ERROR("Failed <= comparison", char);
59 }
60 if(!(t1 != t2))
61 {
62 BOOST_REGEX_TEST_ERROR("Failed != comparison", char);
63 }
64 if(t1 == t2)
65 {
66 BOOST_REGEX_TEST_ERROR("Failed == comparison", char);
67 }
68 if(!(t1 >= t2))
69 {
70 BOOST_REGEX_TEST_ERROR("Failed >= comparison", char);
71 }
72 if(!(t1 > t2))
73 {
74 BOOST_REGEX_TEST_ERROR("Failed > comparison", char);
75 }
76 }
77
78 template <class T1, class T2>
test_equal(const T1 & t1,const T2 & t2)79 void test_equal(const T1& t1, const T2& t2)
80 {
81 if(t1 < t2)
82 {
83 BOOST_REGEX_TEST_ERROR("Failed < comparison", char);
84 }
85 if(!(t1 <= t2))
86 {
87 BOOST_REGEX_TEST_ERROR("Failed <= comparison", char);
88 }
89 if(t1 != t2)
90 {
91 BOOST_REGEX_TEST_ERROR("Failed != comparison", char);
92 }
93 if(!(t1 == t2))
94 {
95 BOOST_REGEX_TEST_ERROR("Failed == comparison", char);
96 }
97 if(!(t1 >= t2))
98 {
99 BOOST_REGEX_TEST_ERROR("Failed >= comparison", char);
100 }
101 if(t1 > t2)
102 {
103 BOOST_REGEX_TEST_ERROR("Failed > comparison", char);
104 }
105 }
106
107 template <class T1, class T2, class T3>
test_plus(const T1 & t1,const T2 & t2,const T3 & t3)108 void test_plus(const T1& t1, const T2& t2, const T3& t3)
109 {
110 if(t1 + t2 != t3)
111 {
112 BOOST_REGEX_TEST_ERROR("Failed addition", char);
113 }
114 if(t3 != t1 + t2)
115 {
116 BOOST_REGEX_TEST_ERROR("Failed addition", char);
117 }
118 }
119
test_operators()120 void test_operators()
121 {
122 test_info<char>::set_typename("sub_match operators");
123
124 std::string s1("a");
125 std::string s2("b");
126 boost::sub_match<std::string::const_iterator> sub1, sub2;
127 sub1.first = s1.begin();
128 sub1.second = s1.end();
129 sub1.matched = true;
130 sub2.first = s2.begin();
131 sub2.second = s2.end();
132 sub2.matched = true;
133
134 test_less(sub1, sub2);
135 test_less(sub1, s2.c_str());
136 test_less(s1.c_str(), sub2);
137 test_less(sub1, *s2.c_str());
138 test_less(*s1.c_str(), sub2);
139 test_less(sub1, s2);
140 test_less(s1, sub2);
141 test_greater(sub2, sub1);
142 test_greater(sub2, s1.c_str());
143 test_greater(s2.c_str(), sub1);
144 test_greater(sub2, *s1.c_str());
145 test_greater(*s2.c_str(), sub1);
146 test_greater(sub2, s1);
147 test_greater(s2, sub1);
148 test_equal(sub1, sub1);
149 test_equal(sub1, s1.c_str());
150 test_equal(s1.c_str(), sub1);
151 test_equal(sub1, *s1.c_str());
152 test_equal(*s1.c_str(), sub1);
153 test_equal(sub1, s1);
154 test_equal(s1, sub1);
155 test_plus(sub2, sub1, "ba");
156 test_plus(sub2, s1.c_str(), "ba");
157 test_plus(s2.c_str(), sub1, "ba");
158 test_plus(sub2, *s1.c_str(), "ba");
159 test_plus(*s2.c_str(), sub1, "ba");
160 test_plus(sub2, s1, "ba");
161 test_plus(s2, sub1, "ba");
162 }
163
164 #else
165
166 #include <iostream>
167
test_operators()168 void test_operators()
169 {
170 std::cout <<
171 "\n<note>\n"
172 "This compiler version does not support the sub_match comparison operators\n"
173 "tests for these operators are not carried out\n"
174 "</note>\n";
175 }
176
177 #endif
178
179