• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <regex>
11 
12 // template <class BidirectionalIterator> class sub_match;
13 
14 // template <class BiIter>
15 //     bool
16 //     operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
17 //
18 // template <class BiIter>
19 //     bool
20 //     operator!=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
21 //
22 // template <class BiIter>
23 //     bool
24 //     operator<(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
25 //
26 // template <class BiIter>
27 //     bool
28 //     operator<=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
29 //
30 // template <class BiIter>
31 //     bool
32 //     operator>=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
33 //
34 // template <class BiIter>
35 //     bool
36 //     operator>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
37 //
38 // template <class BiIter, class ST, class SA>
39 //     bool
40 //     operator==(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
41 //                const sub_match<BiIter>& rhs);
42 //
43 // template <class BiIter, class ST, class SA>
44 //     bool
45 //     operator!=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
46 //                const sub_match<BiIter>& rhs);
47 //
48 // template <class BiIter, class ST, class SA>
49 //     bool
50 //     operator<(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
51 //               const sub_match<BiIter>& rhs);
52 //
53 // template <class BiIter, class ST, class SA>
54 //     bool
55 //     operator>(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
56 //               const sub_match<BiIter>& rhs);
57 //
58 // template <class BiIter, class ST, class SA>
59 //     bool operator>=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
60 //                     const sub_match<BiIter>& rhs);
61 //
62 // template <class BiIter, class ST, class SA>
63 //     bool
64 //     operator<=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
65 //                const sub_match<BiIter>& rhs);
66 //
67 // template <class BiIter, class ST, class SA>
68 //     bool
69 //     operator==(const sub_match<BiIter>& lhs,
70 //                const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
71 //
72 // template <class BiIter, class ST, class SA>
73 //     bool
74 //     operator!=(const sub_match<BiIter>& lhs,
75 //                const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
76 //
77 // template <class BiIter, class ST, class SA>
78 //     bool
79 //     operator<(const sub_match<BiIter>& lhs,
80 //               const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
81 //
82 // template <class BiIter, class ST, class SA>
83 //     bool operator>(const sub_match<BiIter>& lhs,
84 //                    const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
85 //
86 // template <class BiIter, class ST, class SA>
87 //     bool
88 //     operator>=(const sub_match<BiIter>& lhs,
89 //                const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
90 //
91 // template <class BiIter, class ST, class SA>
92 //     bool
93 //     operator<=(const sub_match<BiIter>& lhs,
94 //                const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
95 //
96 // template <class BiIter>
97 //     bool
98 //     operator==(typename iterator_traits<BiIter>::value_type const* lhs,
99 //                const sub_match<BiIter>& rhs);
100 //
101 // template <class BiIter>
102 //     bool
103 //     operator!=(typename iterator_traits<BiIter>::value_type const* lhs,
104 //                const sub_match<BiIter>& rhs);
105 //
106 // template <class BiIter>
107 //     bool
108 //     operator<(typename iterator_traits<BiIter>::value_type const* lhs,
109 //               const sub_match<BiIter>& rhs);
110 //
111 // template <class BiIter>
112 //     bool
113 //     operator>(typename iterator_traits<BiIter>::value_type const* lhs,
114 //               const sub_match<BiIter>& rhs);
115 //
116 // template <class BiIter>
117 //     bool
118 //     operator>=(typename iterator_traits<BiIter>::value_type const* lhs,
119 //                const sub_match<BiIter>& rhs);
120 //
121 // template <class BiIter>
122 //     bool
123 //     operator<=(typename iterator_traits<BiIter>::value_type const* lhs,
124 //                const sub_match<BiIter>& rhs);
125 //
126 // template <class BiIter>
127 //     bool
128 //     operator==(const sub_match<BiIter>& lhs,
129 //                typename iterator_traits<BiIter>::value_type const* rhs);
130 //
131 // template <class BiIter>
132 //     bool
133 //     operator!=(const sub_match<BiIter>& lhs,
134 //                typename iterator_traits<BiIter>::value_type const* rhs);
135 //
136 // template <class BiIter>
137 //     bool
138 //     operator<(const sub_match<BiIter>& lhs,
139 //               typename iterator_traits<BiIter>::value_type const* rhs);
140 //
141 // template <class BiIter>
142 //     bool
143 //     operator>(const sub_match<BiIter>& lhs,
144 //               typename iterator_traits<BiIter>::value_type const* rhs);
145 //
146 // template <class BiIter>
147 //     bool
148 //     operator>=(const sub_match<BiIter>& lhs,
149 //                typename iterator_traits<BiIter>::value_type const* rhs);
150 //
151 // template <class BiIter>
152 //     bool
153 //     operator<=(const sub_match<BiIter>& lhs,
154 //                typename iterator_traits<BiIter>::value_type const* rhs);
155 //
156 // template <class BiIter>
157 //     bool
158 //     operator==(typename iterator_traits<BiIter>::value_type const& lhs,
159 //                const sub_match<BiIter>& rhs);
160 //
161 // template <class BiIter>
162 //     bool
163 //     operator!=(typename iterator_traits<BiIter>::value_type const& lhs,
164 //                const sub_match<BiIter>& rhs);
165 //
166 // template <class BiIter>
167 //     bool
168 //     operator<(typename iterator_traits<BiIter>::value_type const& lhs,
169 //               const sub_match<BiIter>& rhs);
170 //
171 // template <class BiIter>
172 //     bool
173 //     operator>(typename iterator_traits<BiIter>::value_type const& lhs,
174 //               const sub_match<BiIter>& rhs);
175 //
176 // template <class BiIter>
177 //     bool
178 //     operator>=(typename iterator_traits<BiIter>::value_type const& lhs,
179 //                const sub_match<BiIter>& rhs);
180 //
181 // template <class BiIter>
182 //     bool
183 //     operator<=(typename iterator_traits<BiIter>::value_type const& lhs,
184 //                const sub_match<BiIter>& rhs);
185 //
186 // template <class BiIter>
187 //     bool
188 //     operator==(const sub_match<BiIter>& lhs,
189 //                typename iterator_traits<BiIter>::value_type const& rhs);
190 //
191 // template <class BiIter>
192 //     bool
193 //     operator!=(const sub_match<BiIter>& lhs,
194 //                typename iterator_traits<BiIter>::value_type const& rhs);
195 //
196 // template <class BiIter>
197 //     bool
198 //     operator<(const sub_match<BiIter>& lhs,
199 //               typename iterator_traits<BiIter>::value_type const& rhs);
200 //
201 // template <class BiIter>
202 //     bool
203 //     operator>(const sub_match<BiIter>& lhs,
204 //               typename iterator_traits<BiIter>::value_type const& rhs);
205 //
206 // template <class BiIter>
207 //     bool
208 //     operator>=(const sub_match<BiIter>& lhs,
209 //                typename iterator_traits<BiIter>::value_type const& rhs);
210 //
211 // template <class BiIter>
212 //     bool
213 //     operator<=(const sub_match<BiIter>& lhs,
214 //                typename iterator_traits<BiIter>::value_type const& rhs);
215 
216 #include <regex>
217 #include <cassert>
218 #include "test_macros.h"
219 
220 template <class CharT>
221 void
test(const std::basic_string<CharT> & x,const std::basic_string<CharT> & y,bool doCStrTests=true)222 test(const std::basic_string<CharT>& x, const std::basic_string<CharT>& y, bool doCStrTests = true)
223 {
224     typedef std::basic_string<CharT> string;
225     typedef std::sub_match<typename string::const_iterator> sub_match;
226     sub_match sm1;
227     sm1.first = x.begin();
228     sm1.second = x.end();
229     sm1.matched = true;
230     sub_match sm2;
231     sm2.first = y.begin();
232     sm2.second = y.end();
233     sm2.matched = true;
234     assert((sm1 == sm2) == (x == y));
235     assert((sm1 != sm2) == (x != y));
236     assert((sm1 < sm2) == (x < y));
237     assert((sm1 > sm2) == (x > y));
238     assert((sm1 <= sm2) == (x <= y));
239     assert((sm1 >= sm2) == (x >= y));
240     assert((x == sm2) == (x == y));
241     assert((x != sm2) == (x != y));
242     assert((x < sm2) == (x < y));
243     assert((x > sm2) == (x > y));
244     assert((x <= sm2) == (x <= y));
245     assert((x >= sm2) == (x >= y));
246     assert((sm1 == y) == (x == y));
247     assert((sm1 != y) == (x != y));
248     assert((sm1 < y) == (x < y));
249     assert((sm1 > y) == (x > y));
250     assert((sm1 <= y) == (x <= y));
251     assert((sm1 >= y) == (x >= y));
252     if (doCStrTests) {
253         assert((x.c_str() == sm2) == (x == y));
254         assert((x.c_str() != sm2) == (x != y));
255         assert((x.c_str() < sm2) == (x < y));
256         assert((x.c_str() > sm2) == (x > y));
257         assert((x.c_str() <= sm2) == (x <= y));
258         assert((x.c_str() >= sm2) == (x >= y));
259         assert((sm1 == y.c_str()) == (x == y));
260         assert((sm1 != y.c_str()) == (x != y));
261         assert((sm1 < y.c_str()) == (x < y));
262         assert((sm1 > y.c_str()) == (x > y));
263         assert((sm1 <= y.c_str()) == (x <= y));
264         assert((sm1 >= y.c_str()) == (x >= y));
265         }
266     assert((x[0] == sm2) == (string(1, x[0]) == y));
267     assert((x[0] != sm2) == (string(1, x[0]) != y));
268     assert((x[0] < sm2) == (string(1, x[0]) < y));
269     assert((x[0] > sm2) == (string(1, x[0]) > y));
270     assert((x[0] <= sm2) == (string(1, x[0]) <= y));
271     assert((x[0] >= sm2) == (string(1, x[0]) >= y));
272     assert((sm1 == y[0]) == (x == string(1, y[0])));
273     assert((sm1 != y[0]) == (x != string(1, y[0])));
274     assert((sm1 < y[0]) == (x < string(1, y[0])));
275     assert((sm1 > y[0]) == (x > string(1, y[0])));
276     assert((sm1 <= y[0]) == (x <= string(1, y[0])));
277     assert((sm1 >= y[0]) == (x >= string(1, y[0])));
278 }
279 
main()280 int main()
281 {
282     test(std::string("123"), std::string("123"));
283     test(std::string("1234"), std::string("123"));
284     test(std::wstring(L"123"), std::wstring(L"123"));
285     test(std::wstring(L"1234"), std::wstring(L"123"));
286     test(std::string("123\000" "56", 6), std::string("123\000" "56", 6), false);
287     test(std::wstring(L"123\000" L"56", 6), std::wstring(L"123\000" L"56", 6), false);
288 }
289