1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // <regex>
10 
11 // template <class BidirectionalIterator> class sub_match;
12 
13 // template <class BiIter>
14 //     bool
15 //     operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
16 //
17 // template <class BiIter>
18 //     bool
19 //     operator!=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
20 //
21 // template <class BiIter>
22 //     bool
23 //     operator<(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
24 //
25 // template <class BiIter>
26 //     bool
27 //     operator<=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
28 //
29 // template <class BiIter>
30 //     bool
31 //     operator>=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
32 //
33 // template <class BiIter>
34 //     bool
35 //     operator>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
36 //
37 // template <class BiIter, class ST, class SA>
38 //     bool
39 //     operator==(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
40 //                const sub_match<BiIter>& rhs);
41 //
42 // template <class BiIter, class ST, class SA>
43 //     bool
44 //     operator!=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
45 //                const sub_match<BiIter>& rhs);
46 //
47 // template <class BiIter, class ST, class SA>
48 //     bool
49 //     operator<(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
50 //               const sub_match<BiIter>& rhs);
51 //
52 // template <class BiIter, class ST, class SA>
53 //     bool
54 //     operator>(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
55 //               const sub_match<BiIter>& rhs);
56 //
57 // template <class BiIter, class ST, class SA>
58 //     bool operator>=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
59 //                     const sub_match<BiIter>& rhs);
60 //
61 // template <class BiIter, class ST, class SA>
62 //     bool
63 //     operator<=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
64 //                const sub_match<BiIter>& rhs);
65 //
66 // template <class BiIter, class ST, class SA>
67 //     bool
68 //     operator==(const sub_match<BiIter>& lhs,
69 //                const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
70 //
71 // template <class BiIter, class ST, class SA>
72 //     bool
73 //     operator!=(const sub_match<BiIter>& lhs,
74 //                const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
75 //
76 // template <class BiIter, class ST, class SA>
77 //     bool
78 //     operator<(const sub_match<BiIter>& lhs,
79 //               const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
80 //
81 // template <class BiIter, class ST, class SA>
82 //     bool operator>(const sub_match<BiIter>& lhs,
83 //                    const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
84 //
85 // template <class BiIter, class ST, class SA>
86 //     bool
87 //     operator>=(const sub_match<BiIter>& lhs,
88 //                const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
89 //
90 // template <class BiIter, class ST, class SA>
91 //     bool
92 //     operator<=(const sub_match<BiIter>& lhs,
93 //                const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
94 //
95 // template <class BiIter>
96 //     bool
97 //     operator==(typename iterator_traits<BiIter>::value_type const* lhs,
98 //                const sub_match<BiIter>& rhs);
99 //
100 // template <class BiIter>
101 //     bool
102 //     operator!=(typename iterator_traits<BiIter>::value_type const* lhs,
103 //                const sub_match<BiIter>& rhs);
104 //
105 // template <class BiIter>
106 //     bool
107 //     operator<(typename iterator_traits<BiIter>::value_type const* lhs,
108 //               const sub_match<BiIter>& rhs);
109 //
110 // template <class BiIter>
111 //     bool
112 //     operator>(typename iterator_traits<BiIter>::value_type const* lhs,
113 //               const sub_match<BiIter>& rhs);
114 //
115 // template <class BiIter>
116 //     bool
117 //     operator>=(typename iterator_traits<BiIter>::value_type const* lhs,
118 //                const sub_match<BiIter>& rhs);
119 //
120 // template <class BiIter>
121 //     bool
122 //     operator<=(typename iterator_traits<BiIter>::value_type const* lhs,
123 //                const sub_match<BiIter>& rhs);
124 //
125 // template <class BiIter>
126 //     bool
127 //     operator==(const sub_match<BiIter>& lhs,
128 //                typename iterator_traits<BiIter>::value_type const* rhs);
129 //
130 // template <class BiIter>
131 //     bool
132 //     operator!=(const sub_match<BiIter>& lhs,
133 //                typename iterator_traits<BiIter>::value_type const* rhs);
134 //
135 // template <class BiIter>
136 //     bool
137 //     operator<(const sub_match<BiIter>& lhs,
138 //               typename iterator_traits<BiIter>::value_type const* rhs);
139 //
140 // template <class BiIter>
141 //     bool
142 //     operator>(const sub_match<BiIter>& lhs,
143 //               typename iterator_traits<BiIter>::value_type const* rhs);
144 //
145 // template <class BiIter>
146 //     bool
147 //     operator>=(const sub_match<BiIter>& lhs,
148 //                typename iterator_traits<BiIter>::value_type const* rhs);
149 //
150 // template <class BiIter>
151 //     bool
152 //     operator<=(const sub_match<BiIter>& lhs,
153 //                typename iterator_traits<BiIter>::value_type const* rhs);
154 //
155 // template <class BiIter>
156 //     bool
157 //     operator==(typename iterator_traits<BiIter>::value_type const& lhs,
158 //                const sub_match<BiIter>& rhs);
159 //
160 // template <class BiIter>
161 //     bool
162 //     operator!=(typename iterator_traits<BiIter>::value_type const& lhs,
163 //                const sub_match<BiIter>& rhs);
164 //
165 // template <class BiIter>
166 //     bool
167 //     operator<(typename iterator_traits<BiIter>::value_type const& lhs,
168 //               const sub_match<BiIter>& rhs);
169 //
170 // template <class BiIter>
171 //     bool
172 //     operator>(typename iterator_traits<BiIter>::value_type const& lhs,
173 //               const sub_match<BiIter>& rhs);
174 //
175 // template <class BiIter>
176 //     bool
177 //     operator>=(typename iterator_traits<BiIter>::value_type const& lhs,
178 //                const sub_match<BiIter>& rhs);
179 //
180 // template <class BiIter>
181 //     bool
182 //     operator<=(typename iterator_traits<BiIter>::value_type const& lhs,
183 //                const sub_match<BiIter>& rhs);
184 //
185 // template <class BiIter>
186 //     bool
187 //     operator==(const sub_match<BiIter>& lhs,
188 //                typename iterator_traits<BiIter>::value_type const& rhs);
189 //
190 // template <class BiIter>
191 //     bool
192 //     operator!=(const sub_match<BiIter>& lhs,
193 //                typename iterator_traits<BiIter>::value_type const& rhs);
194 //
195 // template <class BiIter>
196 //     bool
197 //     operator<(const sub_match<BiIter>& lhs,
198 //               typename iterator_traits<BiIter>::value_type const& rhs);
199 //
200 // template <class BiIter>
201 //     bool
202 //     operator>(const sub_match<BiIter>& lhs,
203 //               typename iterator_traits<BiIter>::value_type const& rhs);
204 //
205 // template <class BiIter>
206 //     bool
207 //     operator>=(const sub_match<BiIter>& lhs,
208 //                typename iterator_traits<BiIter>::value_type const& rhs);
209 //
210 // template <class BiIter>
211 //     bool
212 //     operator<=(const sub_match<BiIter>& lhs,
213 //                typename iterator_traits<BiIter>::value_type const& rhs);
214 
215 #include <regex>
216 #include <cassert>
217 #include "test_macros.h"
218 
219 template <class CharT>
220 void
test(const std::basic_string<CharT> & x,const std::basic_string<CharT> & y,bool doCStrTests=true)221 test(const std::basic_string<CharT>& x, const std::basic_string<CharT>& y, bool doCStrTests = true)
222 {
223     typedef std::basic_string<CharT> string;
224     typedef std::sub_match<typename string::const_iterator> sub_match;
225     sub_match sm1;
226     sm1.first = x.begin();
227     sm1.second = x.end();
228     sm1.matched = true;
229     sub_match sm2;
230     sm2.first = y.begin();
231     sm2.second = y.end();
232     sm2.matched = true;
233     assert((sm1 == sm2) == (x == y));
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((x == 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((sm1 == y) == (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     if (doCStrTests) {
252         assert((x.c_str() == sm2) == (x == y));
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((sm1 == y.c_str()) == (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         }
265     assert((x[0] == sm2) == (string(1, x[0]) == y));
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((sm1 == y[0]) == (x == string(1, y[0])));
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 }
278 
main(int,char **)279 int main(int, char**)
280 {
281     test(std::string("123"), std::string("123"));
282     test(std::string("1234"), std::string("123"));
283     test(std::string("123\000" "56", 6), std::string("123\000" "56", 6), false);
284 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
285     test(std::wstring(L"123"), std::wstring(L"123"));
286     test(std::wstring(L"1234"), std::wstring(L"123"));
287     test(std::wstring(L"123\000" L"56", 6), std::wstring(L"123\000" L"56", 6), false);
288 #endif
289 
290   return 0;
291 }
292