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
10// XFAIL: FROZEN-CXX03-HEADERS-FIXME
11
12// <regex>
13
14// template <class BidirectionalIterator, class Allocator, class charT, class traits>
15// bool
16// regex_match(BidirectionalIterator first, BidirectionalIterator last,
17// match_results<BidirectionalIterator, Allocator>& m,
18// const basic_regex<charT, traits>& e,
19// regex_constants::match_flag_type flags = regex_constants::match_default);
20
21#include <regex>
22#include <cassert>
23#include "test_macros.h"
24#include "test_iterators.h"
25
26int main(int, char**)
27{
28 {
29 std::cmatch m;
30 const char s[] = "a";
31 assert(std::regex_match(s, m, std::regex("a")));
32 assert(m.size() == 1);
33 assert(!m.empty());
34 assert(!m.prefix().matched);
35 assert(m.prefix().first == s);
36 assert(m.prefix().second == m[0].first);
37 assert(!m.suffix().matched);
38 assert(m.suffix().first == m[0].second);
39 assert(m.suffix().second == s+1);
40 assert(m.length(0) == 1);
41 assert(m.position(0) == 0);
42 assert(m.str(0) == "a");
43 }
44 {
45 std::cmatch m;
46 const char s[] = "ab";
47 assert(std::regex_match(s, m, std::regex("ab")));
48 assert(m.size() == 1);
49 assert(!m.prefix().matched);
50 assert(m.prefix().first == s);
51 assert(m.prefix().second == m[0].first);
52 assert(!m.suffix().matched);
53 assert(m.suffix().first == m[0].second);
54 assert(m.suffix().second == s+2);
55 assert(m.length(0) == 2);
56 assert(m.position(0) == 0);
57 assert(m.str(0) == "ab");
58 }
59 {
60 std::cmatch m;
61 const char s[] = "ab";
62 assert(!std::regex_match(s, m, std::regex("ba")));
63 assert(m.size() == 0);
64 assert(m.empty());
65 }
66 {
67 std::cmatch m;
68 const char s[] = "aab";
69 assert(!std::regex_match(s, m, std::regex("ab")));
70 assert(m.size() == 0);
71 }
72 {
73 std::cmatch m;
74 const char s[] = "aab";
75 assert(!std::regex_match(s, m, std::regex("ab"),
76 std::regex_constants::match_continuous));
77 assert(m.size() == 0);
78 }
79 {
80 std::cmatch m;
81 const char s[] = "abcd";
82 assert(!std::regex_match(s, m, std::regex("bc")));
83 assert(m.size() == 0);
84 }
85 {
86 std::cmatch m;
87 const char s[] = "abbc";
88 assert(std::regex_match(s, m, std::regex("ab*c")));
89 assert(m.size() == 1);
90 assert(!m.prefix().matched);
91 assert(m.prefix().first == s);
92 assert(m.prefix().second == m[0].first);
93 assert(!m.suffix().matched);
94 assert(m.suffix().first == m[0].second);
95 assert(m.suffix().second == s+4);
96 assert(m.length(0) == 4);
97 assert(m.position(0) == 0);
98 assert(m.str(0) == s);
99 }
100 {
101 std::cmatch m;
102 const char s[] = "ababc";
103 assert(std::regex_match(s, m, std::regex("(ab)*c")));
104 assert(m.size() == 2);
105 assert(!m.prefix().matched);
106 assert(m.prefix().first == s);
107 assert(m.prefix().second == m[0].first);
108 assert(!m.suffix().matched);
109 assert(m.suffix().first == m[0].second);
110 assert(m.suffix().second == s+5);
111 assert(m.length(0) == 5);
112 assert(m.position(0) == 0);
113 assert(m.str(0) == s);
114 assert(m.length(1) == 2);
115 assert(m.position(1) == 2);
116 assert(m.str(1) == "ab");
117 }
118 {
119 std::cmatch m;
120 const char s[] = "abcdefghijk";
121 assert(!std::regex_match(s, m, std::regex("cd((e)fg)hi")));
122 assert(m.size() == 0);
123 }
124 {
125 std::cmatch m;
126 const char s[] = "abc";
127 assert(std::regex_match(s, m, std::regex("^abc")));
128 assert(m.size() == 1);
129 assert(!m.prefix().matched);
130 assert(m.prefix().first == s);
131 assert(m.prefix().second == m[0].first);
132 assert(!m.suffix().matched);
133 assert(m.suffix().first == m[0].second);
134 assert(m.suffix().second == s+3);
135 assert(m.length(0) == 3);
136 assert(m.position(0) == 0);
137 assert(m.str(0) == s);
138 }
139 {
140 std::cmatch m;
141 const char s[] = "abcd";
142 assert(!std::regex_match(s, m, std::regex("^abc")));
143 assert(m.size() == 0);
144 }
145 {
146 std::cmatch m;
147 const char s[] = "aabc";
148 assert(!std::regex_match(s, m, std::regex("^abc")));
149 assert(m.size() == 0);
150 }
151 {
152 std::cmatch m;
153 const char s[] = "abc";
154 assert(std::regex_match(s, m, std::regex("abc$")));
155 assert(m.size() == 1);
156 assert(!m.prefix().matched);
157 assert(m.prefix().first == s);
158 assert(m.prefix().second == m[0].first);
159 assert(!m.suffix().matched);
160 assert(m.suffix().first == m[0].second);
161 assert(m.suffix().second == s+3);
162 assert(m.length(0) == 3);
163 assert(m.position(0) == 0);
164 assert(m.str(0) == s);
165 }
166 {
167 std::cmatch m;
168 const char s[] = "efabc";
169 assert(!std::regex_match(s, m, std::regex("abc$")));
170 assert(m.size() == 0);
171 }
172 {
173 std::cmatch m;
174 const char s[] = "efabcg";
175 assert(!std::regex_match(s, m, std::regex("abc$")));
176 assert(m.size() == 0);
177 }
178 {
179 std::cmatch m;
180 const char s[] = "abc";
181 assert(std::regex_match(s, m, std::regex("a.c")));
182 assert(m.size() == 1);
183 assert(!m.prefix().matched);
184 assert(m.prefix().first == s);
185 assert(m.prefix().second == m[0].first);
186 assert(!m.suffix().matched);
187 assert(m.suffix().first == m[0].second);
188 assert(m.suffix().second == s+3);
189 assert(m.length(0) == 3);
190 assert(m.position(0) == 0);
191 assert(m.str(0) == s);
192 }
193 {
194 std::cmatch m;
195 const char s[] = "acc";
196 assert(std::regex_match(s, m, std::regex("a.c")));
197 assert(m.size() == 1);
198 assert(!m.prefix().matched);
199 assert(m.prefix().first == s);
200 assert(m.prefix().second == m[0].first);
201 assert(!m.suffix().matched);
202 assert(m.suffix().first == m[0].second);
203 assert(m.suffix().second == s+3);
204 assert(m.length(0) == 3);
205 assert(m.position(0) == 0);
206 assert(m.str(0) == s);
207 }
208 {
209 std::cmatch m;
210 const char s[] = "acc";
211 assert(std::regex_match(s, m, std::regex("a.c")));
212 assert(m.size() == 1);
213 assert(!m.prefix().matched);
214 assert(m.prefix().first == s);
215 assert(m.prefix().second == m[0].first);
216 assert(!m.suffix().matched);
217 assert(m.suffix().first == m[0].second);
218 assert(m.suffix().second == s+3);
219 assert(m.length(0) == 3);
220 assert(m.position(0) == 0);
221 assert(m.str(0) == s);
222 }
223 {
224 std::cmatch m;
225 const char s[] = "abcdef";
226 assert(std::regex_match(s, m, std::regex("(.*).*")));
227 assert(m.size() == 2);
228 assert(!m.prefix().matched);
229 assert(m.prefix().first == s);
230 assert(m.prefix().second == m[0].first);
231 assert(!m.suffix().matched);
232 assert(m.suffix().first == m[0].second);
233 assert(m.suffix().second == s+6);
234 assert(m.length(0) == 6);
235 assert(m.position(0) == 0);
236 assert(m.str(0) == s);
237 assert(m.length(1) == 6);
238 assert(m.position(1) == 0);
239 assert(m.str(1) == s);
240 }
241 {
242 std::cmatch m;
243 const char s[] = "bc";
244 assert(!std::regex_match(s, m, std::regex("(a*)*")));
245 assert(m.size() == 0);
246 }
247 {
248 std::cmatch m;
249 const char s[] = "abbc";
250 assert(!std::regex_match(s, m, std::regex("ab{3,5}c")));
251 assert(m.size() == 0);
252 }
253 {
254 std::cmatch m;
255 const char s[] = "abbbc";
256 assert(std::regex_match(s, m, std::regex("ab{3,5}c")));
257 assert(m.size() == 1);
258 assert(!m.prefix().matched);
259 assert(m.prefix().first == s);
260 assert(m.prefix().second == m[0].first);
261 assert(!m.suffix().matched);
262 assert(m.suffix().first == m[0].second);
263 assert(m.suffix().second == m[0].second);
264 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<char>::length(s));
265 assert(m.position(0) == 0);
266 assert(m.str(0) == s);
267 }
268 {
269 std::cmatch m;
270 const char s[] = "abbbbc";
271 assert(std::regex_match(s, m, std::regex("ab{3,5}c")));
272 assert(m.size() == 1);
273 assert(!m.prefix().matched);
274 assert(m.prefix().first == s);
275 assert(m.prefix().second == m[0].first);
276 assert(!m.suffix().matched);
277 assert(m.suffix().first == m[0].second);
278 assert(m.suffix().second == m[0].second);
279 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<char>::length(s));
280 assert(m.position(0) == 0);
281 assert(m.str(0) == s);
282 }
283 {
284 std::cmatch m;
285 const char s[] = "abbbbbc";
286 assert(std::regex_match(s, m, std::regex("ab{3,5}c")));
287 assert(m.size() == 1);
288 assert(!m.prefix().matched);
289 assert(m.prefix().first == s);
290 assert(m.prefix().second == m[0].first);
291 assert(!m.suffix().matched);
292 assert(m.suffix().first == m[0].second);
293 assert(m.suffix().second == m[0].second);
294 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<char>::length(s));
295 assert(m.position(0) == 0);
296 assert(m.str(0) == s);
297 }
298 {
299 std::cmatch m;
300 const char s[] = "adefc";
301 assert(!std::regex_match(s, m, std::regex("ab{3,5}c")));
302 assert(m.size() == 0);
303 }
304 {
305 std::cmatch m;
306 const char s[] = "abbbbbbc";
307 assert(!std::regex_match(s, m, std::regex("ab{3,5}c")));
308 assert(m.size() == 0);
309 }
310 {
311 std::cmatch m;
312 const char s[] = "adec";
313 assert(!std::regex_match(s, m, std::regex("a.{3,5}c")));
314 assert(m.size() == 0);
315 }
316 {
317 std::cmatch m;
318 const char s[] = "adefc";
319 assert(std::regex_match(s, m, std::regex("a.{3,5}c")));
320 assert(m.size() == 1);
321 assert(!m.prefix().matched);
322 assert(m.prefix().first == s);
323 assert(m.prefix().second == m[0].first);
324 assert(!m.suffix().matched);
325 assert(m.suffix().first == m[0].second);
326 assert(m.suffix().second == m[0].second);
327 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<char>::length(s));
328 assert(m.position(0) == 0);
329 assert(m.str(0) == s);
330 }
331 {
332 std::cmatch m;
333 const char s[] = "adefgc";
334 assert(std::regex_match(s, m, std::regex("a.{3,5}c")));
335 assert(m.size() == 1);
336 assert(!m.prefix().matched);
337 assert(m.prefix().first == s);
338 assert(m.prefix().second == m[0].first);
339 assert(!m.suffix().matched);
340 assert(m.suffix().first == m[0].second);
341 assert(m.suffix().second == m[0].second);
342 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<char>::length(s));
343 assert(m.position(0) == 0);
344 assert(m.str(0) == s);
345 }
346 {
347 std::cmatch m;
348 const char s[] = "adefghc";
349 assert(std::regex_match(s, m, std::regex("a.{3,5}c")));
350 assert(m.size() == 1);
351 assert(!m.prefix().matched);
352 assert(m.prefix().first == s);
353 assert(m.prefix().second == m[0].first);
354 assert(!m.suffix().matched);
355 assert(m.suffix().first == m[0].second);
356 assert(m.suffix().second == m[0].second);
357 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<char>::length(s));
358 assert(m.position(0) == 0);
359 assert(m.str(0) == s);
360 }
361 {
362 std::cmatch m;
363 const char s[] = "adefghic";
364 assert(!std::regex_match(s, m, std::regex("a.{3,5}c")));
365 assert(m.size() == 0);
366 }
367 {
368 std::cmatch m;
369 // http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2273
370 const char s[] = "tournament";
371 assert(std::regex_match(s, m, std::regex("tour|to|tournament")));
372 assert(m.size() == 1);
373 assert(!m.prefix().matched);
374 assert(m.prefix().first == s);
375 assert(m.prefix().second == m[0].first);
376 assert(!m.suffix().matched);
377 assert(m.suffix().first == m[0].second);
378 assert(m.suffix().second == m[0].second);
379 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<char>::length(s));
380 assert(m.position(0) == 0);
381 assert(m.str(0) == s);
382 }
383 {
384 std::cmatch m;
385 // http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2273
386 const char s[] = "tournamenttotour";
387 assert(
388 std::regex_match(s, m, std::regex("(tour|to|tournament)+",
389 std::regex_constants::nosubs)));
390 assert(m.size() == 1);
391 assert(!m.prefix().matched);
392 assert(m.prefix().first == s);
393 assert(m.prefix().second == m[0].first);
394 assert(!m.suffix().matched);
395 assert(m.suffix().first == m[0].second);
396 assert(m.suffix().second == m[0].second);
397 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<char>::length(s));
398 assert(m.position(0) == 0);
399 assert(m.str(0) == s);
400 }
401 {
402 std::cmatch m;
403 const char s[] = "ttotour";
404 assert(std::regex_match(s, m, std::regex("(tour|to|t)+")));
405 assert(m.size() == 2);
406 assert(!m.prefix().matched);
407 assert(m.prefix().first == s);
408 assert(m.prefix().second == m[0].first);
409 assert(!m.suffix().matched);
410 assert(m.suffix().first == m[0].second);
411 assert(m.suffix().second == m[0].second);
412 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<char>::length(s));
413 assert(m.position(0) == 0);
414 assert(m.str(0) == s);
415 assert(m.length(1) == 4);
416 assert(m.position(1) == 3);
417 assert(m.str(1) == "tour");
418 }
419 {
420 std::cmatch m;
421 const char s[] = "-ab,ab-";
422 assert(!std::regex_match(s, m, std::regex("-(.*),\1-")));
423 assert(m.size() == 0);
424 }
425 {
426 std::cmatch m;
427 const char s[] = "-ab,ab-";
428 assert(std::regex_match(s, m, std::regex("-.*,.*-")));
429 assert(m.size() == 1);
430 assert(!m.prefix().matched);
431 assert(m.prefix().first == s);
432 assert(m.prefix().second == m[0].first);
433 assert(!m.suffix().matched);
434 assert(m.suffix().first == m[0].second);
435 assert(m.suffix().second == m[0].second);
436 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<char>::length(s));
437 assert(m.position(0) == 0);
438 assert(m.str(0) == s);
439 }
440 {
441 std::cmatch m;
442 const char s[] = "a";
443 assert(std::regex_match(s, m, std::regex("^[a]$")));
444 assert(m.size() == 1);
445 assert(!m.prefix().matched);
446 assert(m.prefix().first == s);
447 assert(m.prefix().second == m[0].first);
448 assert(!m.suffix().matched);
449 assert(m.suffix().first == m[0].second);
450 assert(m.suffix().second == m[0].second);
451 assert(m.length(0) == 1);
452 assert(m.position(0) == 0);
453 assert(m.str(0) == "a");
454 }
455 {
456 std::cmatch m;
457 const char s[] = "a";
458 assert(std::regex_match(s, m, std::regex("^[ab]$")));
459 assert(m.size() == 1);
460 assert(!m.prefix().matched);
461 assert(m.prefix().first == s);
462 assert(m.prefix().second == m[0].first);
463 assert(!m.suffix().matched);
464 assert(m.suffix().first == m[0].second);
465 assert(m.suffix().second == m[0].second);
466 assert(m.length(0) == 1);
467 assert(m.position(0) == 0);
468 assert(m.str(0) == "a");
469 }
470 {
471 std::cmatch m;
472 const char s[] = "c";
473 assert(std::regex_match(s, m, std::regex("^[a-f]$")));
474 assert(m.size() == 1);
475 assert(!m.prefix().matched);
476 assert(m.prefix().first == s);
477 assert(m.prefix().second == m[0].first);
478 assert(!m.suffix().matched);
479 assert(m.suffix().first == m[0].second);
480 assert(m.suffix().second == m[0].second);
481 assert(m.length(0) == 1);
482 assert(m.position(0) == 0);
483 assert(m.str(0) == s);
484 }
485 {
486 std::cmatch m;
487 const char s[] = "g";
488 assert(!std::regex_match(s, m, std::regex("^[a-f]$")));
489 assert(m.size() == 0);
490 }
491 {
492 std::cmatch m;
493 const char s[] = "Iraqi";
494 assert(!std::regex_match(s, m, std::regex("q[^u]")));
495 assert(m.size() == 0);
496 }
497 {
498 std::cmatch m;
499 const char s[] = "Iraq";
500 assert(!std::regex_match(s, m, std::regex("q[^u]")));
501 assert(m.size() == 0);
502 }
503 {
504 std::cmatch m;
505 const char s[] = "AmB";
506 assert(std::regex_match(s, m, std::regex("A[[:lower:]]B")));
507 assert(m.size() == 1);
508 assert(!m.prefix().matched);
509 assert(m.prefix().first == s);
510 assert(m.prefix().second == m[0].first);
511 assert(!m.suffix().matched);
512 assert(m.suffix().first == m[0].second);
513 assert(m.suffix().second == m[0].second);
514 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<char>::length(s));
515 assert(m.position(0) == 0);
516 assert(m.str(0) == s);
517 }
518 {
519 std::cmatch m;
520 const char s[] = "AMB";
521 assert(!std::regex_match(s, m, std::regex("A[[:lower:]]B")));
522 assert(m.size() == 0);
523 }
524 {
525 std::cmatch m;
526 const char s[] = "AMB";
527 assert(std::regex_match(s, m, std::regex("A[^[:lower:]]B")));
528 assert(m.size() == 1);
529 assert(!m.prefix().matched);
530 assert(m.prefix().first == s);
531 assert(m.prefix().second == m[0].first);
532 assert(!m.suffix().matched);
533 assert(m.suffix().first == m[0].second);
534 assert(m.suffix().second == m[0].second);
535 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<char>::length(s));
536 assert(m.position(0) == 0);
537 assert(m.str(0) == s);
538 }
539 {
540 std::cmatch m;
541 const char s[] = "AmB";
542 assert(!std::regex_match(s, m, std::regex("A[^[:lower:]]B")));
543 assert(m.size() == 0);
544 }
545 {
546 std::cmatch m;
547 const char s[] = "A5B";
548 assert(!std::regex_match(s, m, std::regex("A[^[:lower:]0-9]B")));
549 assert(m.size() == 0);
550 }
551 {
552 std::cmatch m;
553 const char s[] = "A?B";
554 assert(std::regex_match(s, m, std::regex("A[^[:lower:]0-9]B")));
555 assert(m.size() == 1);
556 assert(!m.prefix().matched);
557 assert(m.prefix().first == s);
558 assert(m.prefix().second == m[0].first);
559 assert(!m.suffix().matched);
560 assert(m.suffix().first == m[0].second);
561 assert(m.suffix().second == m[0].second);
562 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<char>::length(s));
563 assert(m.position(0) == 0);
564 assert(m.str(0) == s);
565 }
566 {
567 std::cmatch m;
568 const char s[] = "-";
569 assert(std::regex_match(s, m, std::regex("[a[.hyphen.]z]")));
570 assert(m.size() == 1);
571 assert(!m.prefix().matched);
572 assert(m.prefix().first == s);
573 assert(m.prefix().second == m[0].first);
574 assert(!m.suffix().matched);
575 assert(m.suffix().first == m[0].second);
576 assert(m.suffix().second == m[0].second);
577 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<char>::length(s));
578 assert(m.position(0) == 0);
579 assert(m.str(0) == s);
580 }
581 {
582 std::cmatch m;
583 const char s[] = "z";
584 assert(std::regex_match(s, m, std::regex("[a[.hyphen.]z]")));
585 assert(m.size() == 1);
586 assert(!m.prefix().matched);
587 assert(m.prefix().first == s);
588 assert(m.prefix().second == m[0].first);
589 assert(!m.suffix().matched);
590 assert(m.suffix().first == m[0].second);
591 assert(m.suffix().second == m[0].second);
592 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<char>::length(s));
593 assert(m.position(0) == 0);
594 assert(m.str(0) == s);
595 }
596 {
597 std::cmatch m;
598 const char s[] = "m";
599 assert(!std::regex_match(s, m, std::regex("[a[.hyphen.]z]")));
600 assert(m.size() == 0);
601 }
602 {
603 std::cmatch m;
604 const char s[] = "foobar";
605 assert(std::regex_match(s, m, std::regex("[^\\0]*")));
606 assert(m.size() == 1);
607 }
608 {
609 std::cmatch m;
610 const char s[] = "foo\0bar";
611 assert(std::regex_match(s, s+7, m, std::regex("[abfor\\0]*")));
612 assert(m.size() == 1);
613 }
614 {
615 std::cmatch m;
616 const char s[] = "01a45cef9";
617 assert(!std::regex_match(s, m, std::regex("[ace1-9]*")));
618 assert(m.size() == 0);
619 }
620 {
621 std::cmatch m;
622 const char s[] = "01a45cef9";
623 assert(!std::regex_match(s, m, std::regex("[ace1-9]+")));
624 assert(m.size() == 0);
625 }
626 {
627 const char r[] = "^[-+]?[0-9]+[CF]$";
628 std::ptrdiff_t sr = std::char_traits<char>::length(s: r);
629 typedef forward_iterator<const char*> FI;
630 typedef bidirectional_iterator<const char*> BI;
631 std::regex regex(FI(r), FI(r+sr));
632 std::match_results<BI> m;
633 const char s[] = "-40C";
634 std::ptrdiff_t ss = std::char_traits<char>::length(s: s);
635 assert(std::regex_match(BI(s), BI(s+ss), m, regex));
636 assert(m.size() == 1);
637 assert(!m.prefix().matched);
638 assert(m.prefix().first == BI(s));
639 assert(m.prefix().second == m[0].first);
640 assert(!m.suffix().matched);
641 assert(m.suffix().first == m[0].second);
642 assert(m.suffix().second == m[0].second);
643 assert(m.length(0) == 4);
644 assert(m.position(0) == 0);
645 assert(m.str(0) == s);
646 }
647 {
648 std::cmatch m;
649 const char s[] = "Jeff Jeffs ";
650 assert(!std::regex_match(s, m, std::regex("Jeff(?=s\\b)")));
651 assert(m.size() == 0);
652 }
653 {
654 std::cmatch m;
655 const char s[] = "Jeffs Jeff";
656 assert(!std::regex_match(s, m, std::regex("Jeff(?!s\\b)")));
657 assert(m.size() == 0);
658 }
659 {
660 std::cmatch m;
661 const char s[] = "5%k";
662 assert(std::regex_match(s, m, std::regex("\\d[\\W]k")));
663 assert(m.size() == 1);
664 assert(!m.prefix().matched);
665 assert(m.prefix().first == s);
666 assert(m.prefix().second == m[0].first);
667 assert(!m.suffix().matched);
668 assert(m.suffix().first == m[0].second);
669 assert(m.suffix().second == s + std::char_traits<char>::length(s));
670 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<char>::length(s));
671 assert(m.position(0) == 0);
672 assert(m.str(0) == s);
673 }
674 {
675 std::cmatch m;
676 const char s[] = "$_se";
677 assert(std::regex_match(s, m, std::regex("\\$\\_se")));
678 assert(m.size() == 1);
679 assert(!m.prefix().matched);
680 assert(m.prefix().first == s);
681 assert(m.prefix().second == m[0].first);
682 assert(!m.suffix().matched);
683 assert(m.suffix().first == m[0].second);
684 assert(m.suffix().second == s + std::char_traits<char>::length(s));
685 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
686 assert(m.position(0) == 0);
687 assert(m.str(0) == s);
688 }
689
690#ifndef TEST_HAS_NO_WIDE_CHARACTERS
691 {
692 std::wcmatch m;
693 const wchar_t s[] = L"a";
694 assert(std::regex_match(s, m, std::wregex(L"a")));
695 assert(m.size() == 1);
696 assert(!m.empty());
697 assert(!m.prefix().matched);
698 assert(m.prefix().first == s);
699 assert(m.prefix().second == m[0].first);
700 assert(!m.suffix().matched);
701 assert(m.suffix().first == m[0].second);
702 assert(m.suffix().second == s+1);
703 assert(m.length(0) == 1);
704 assert(m.position(0) == 0);
705 assert(m.str(0) == L"a");
706 }
707 {
708 std::wcmatch m;
709 const wchar_t s[] = L"ab";
710 assert(std::regex_match(s, m, std::wregex(L"ab")));
711 assert(m.size() == 1);
712 assert(!m.prefix().matched);
713 assert(m.prefix().first == s);
714 assert(m.prefix().second == m[0].first);
715 assert(!m.suffix().matched);
716 assert(m.suffix().first == m[0].second);
717 assert(m.suffix().second == s+2);
718 assert(m.length(0) == 2);
719 assert(m.position(0) == 0);
720 assert(m.str(0) == L"ab");
721 }
722 {
723 std::wcmatch m;
724 const wchar_t s[] = L"ab";
725 assert(!std::regex_match(s, m, std::wregex(L"ba")));
726 assert(m.size() == 0);
727 assert(m.empty());
728 }
729 {
730 std::wcmatch m;
731 const wchar_t s[] = L"aab";
732 assert(!std::regex_match(s, m, std::wregex(L"ab")));
733 assert(m.size() == 0);
734 }
735 {
736 std::wcmatch m;
737 const wchar_t s[] = L"aab";
738 assert(!std::regex_match(s, m, std::wregex(L"ab"),
739 std::regex_constants::match_continuous));
740 assert(m.size() == 0);
741 }
742 {
743 std::wcmatch m;
744 const wchar_t s[] = L"abcd";
745 assert(!std::regex_match(s, m, std::wregex(L"bc")));
746 assert(m.size() == 0);
747 }
748 {
749 std::wcmatch m;
750 const wchar_t s[] = L"abbc";
751 assert(std::regex_match(s, m, std::wregex(L"ab*c")));
752 assert(m.size() == 1);
753 assert(!m.prefix().matched);
754 assert(m.prefix().first == s);
755 assert(m.prefix().second == m[0].first);
756 assert(!m.suffix().matched);
757 assert(m.suffix().first == m[0].second);
758 assert(m.suffix().second == s+4);
759 assert(m.length(0) == 4);
760 assert(m.position(0) == 0);
761 assert(m.str(0) == s);
762 }
763 {
764 std::wcmatch m;
765 const wchar_t s[] = L"ababc";
766 assert(std::regex_match(s, m, std::wregex(L"(ab)*c")));
767 assert(m.size() == 2);
768 assert(!m.prefix().matched);
769 assert(m.prefix().first == s);
770 assert(m.prefix().second == m[0].first);
771 assert(!m.suffix().matched);
772 assert(m.suffix().first == m[0].second);
773 assert(m.suffix().second == s+5);
774 assert(m.length(0) == 5);
775 assert(m.position(0) == 0);
776 assert(m.str(0) == s);
777 assert(m.length(1) == 2);
778 assert(m.position(1) == 2);
779 assert(m.str(1) == L"ab");
780 }
781 {
782 std::wcmatch m;
783 const wchar_t s[] = L"abcdefghijk";
784 assert(!std::regex_match(s, m, std::wregex(L"cd((e)fg)hi")));
785 assert(m.size() == 0);
786 }
787 {
788 std::wcmatch m;
789 const wchar_t s[] = L"abc";
790 assert(std::regex_match(s, m, std::wregex(L"^abc")));
791 assert(m.size() == 1);
792 assert(!m.prefix().matched);
793 assert(m.prefix().first == s);
794 assert(m.prefix().second == m[0].first);
795 assert(!m.suffix().matched);
796 assert(m.suffix().first == m[0].second);
797 assert(m.suffix().second == s+3);
798 assert(m.length(0) == 3);
799 assert(m.position(0) == 0);
800 assert(m.str(0) == s);
801 }
802 {
803 std::wcmatch m;
804 const wchar_t s[] = L"abcd";
805 assert(!std::regex_match(s, m, std::wregex(L"^abc")));
806 assert(m.size() == 0);
807 }
808 {
809 std::wcmatch m;
810 const wchar_t s[] = L"aabc";
811 assert(!std::regex_match(s, m, std::wregex(L"^abc")));
812 assert(m.size() == 0);
813 }
814 {
815 std::wcmatch m;
816 const wchar_t s[] = L"abc";
817 assert(std::regex_match(s, m, std::wregex(L"abc$")));
818 assert(m.size() == 1);
819 assert(!m.prefix().matched);
820 assert(m.prefix().first == s);
821 assert(m.prefix().second == m[0].first);
822 assert(!m.suffix().matched);
823 assert(m.suffix().first == m[0].second);
824 assert(m.suffix().second == s+3);
825 assert(m.length(0) == 3);
826 assert(m.position(0) == 0);
827 assert(m.str(0) == s);
828 }
829 {
830 std::wcmatch m;
831 const wchar_t s[] = L"efabc";
832 assert(!std::regex_match(s, m, std::wregex(L"abc$")));
833 assert(m.size() == 0);
834 }
835 {
836 std::wcmatch m;
837 const wchar_t s[] = L"efabcg";
838 assert(!std::regex_match(s, m, std::wregex(L"abc$")));
839 assert(m.size() == 0);
840 }
841 {
842 std::wcmatch m;
843 const wchar_t s[] = L"abc";
844 assert(std::regex_match(s, m, std::wregex(L"a.c")));
845 assert(m.size() == 1);
846 assert(!m.prefix().matched);
847 assert(m.prefix().first == s);
848 assert(m.prefix().second == m[0].first);
849 assert(!m.suffix().matched);
850 assert(m.suffix().first == m[0].second);
851 assert(m.suffix().second == s+3);
852 assert(m.length(0) == 3);
853 assert(m.position(0) == 0);
854 assert(m.str(0) == s);
855 }
856 {
857 std::wcmatch m;
858 const wchar_t s[] = L"acc";
859 assert(std::regex_match(s, m, std::wregex(L"a.c")));
860 assert(m.size() == 1);
861 assert(!m.prefix().matched);
862 assert(m.prefix().first == s);
863 assert(m.prefix().second == m[0].first);
864 assert(!m.suffix().matched);
865 assert(m.suffix().first == m[0].second);
866 assert(m.suffix().second == s+3);
867 assert(m.length(0) == 3);
868 assert(m.position(0) == 0);
869 assert(m.str(0) == s);
870 }
871 {
872 std::wcmatch m;
873 const wchar_t s[] = L"acc";
874 assert(std::regex_match(s, m, std::wregex(L"a.c")));
875 assert(m.size() == 1);
876 assert(!m.prefix().matched);
877 assert(m.prefix().first == s);
878 assert(m.prefix().second == m[0].first);
879 assert(!m.suffix().matched);
880 assert(m.suffix().first == m[0].second);
881 assert(m.suffix().second == s+3);
882 assert(m.length(0) == 3);
883 assert(m.position(0) == 0);
884 assert(m.str(0) == s);
885 }
886 {
887 std::wcmatch m;
888 const wchar_t s[] = L"abcdef";
889 assert(std::regex_match(s, m, std::wregex(L"(.*).*")));
890 assert(m.size() == 2);
891 assert(!m.prefix().matched);
892 assert(m.prefix().first == s);
893 assert(m.prefix().second == m[0].first);
894 assert(!m.suffix().matched);
895 assert(m.suffix().first == m[0].second);
896 assert(m.suffix().second == s+6);
897 assert(m.length(0) == 6);
898 assert(m.position(0) == 0);
899 assert(m.str(0) == s);
900 assert(m.length(1) == 6);
901 assert(m.position(1) == 0);
902 assert(m.str(1) == s);
903 }
904 {
905 std::wcmatch m;
906 const wchar_t s[] = L"bc";
907 assert(!std::regex_match(s, m, std::wregex(L"(a*)*")));
908 assert(m.size() == 0);
909 }
910 {
911 std::wcmatch m;
912 const wchar_t s[] = L"abbc";
913 assert(!std::regex_match(s, m, std::wregex(L"ab{3,5}c")));
914 assert(m.size() == 0);
915 }
916 {
917 std::wcmatch m;
918 const wchar_t s[] = L"abbbc";
919 assert(std::regex_match(s, m, std::wregex(L"ab{3,5}c")));
920 assert(m.size() == 1);
921 assert(!m.prefix().matched);
922 assert(m.prefix().first == s);
923 assert(m.prefix().second == m[0].first);
924 assert(!m.suffix().matched);
925 assert(m.suffix().first == m[0].second);
926 assert(m.suffix().second == m[0].second);
927 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
928 assert(m.position(0) == 0);
929 assert(m.str(0) == s);
930 }
931 {
932 std::wcmatch m;
933 const wchar_t s[] = L"abbbbc";
934 assert(std::regex_match(s, m, std::wregex(L"ab{3,5}c")));
935 assert(m.size() == 1);
936 assert(!m.prefix().matched);
937 assert(m.prefix().first == s);
938 assert(m.prefix().second == m[0].first);
939 assert(!m.suffix().matched);
940 assert(m.suffix().first == m[0].second);
941 assert(m.suffix().second == m[0].second);
942 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
943 assert(m.position(0) == 0);
944 assert(m.str(0) == s);
945 }
946 {
947 std::wcmatch m;
948 const wchar_t s[] = L"abbbbbc";
949 assert(std::regex_match(s, m, std::wregex(L"ab{3,5}c")));
950 assert(m.size() == 1);
951 assert(!m.prefix().matched);
952 assert(m.prefix().first == s);
953 assert(m.prefix().second == m[0].first);
954 assert(!m.suffix().matched);
955 assert(m.suffix().first == m[0].second);
956 assert(m.suffix().second == m[0].second);
957 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
958 assert(m.position(0) == 0);
959 assert(m.str(0) == s);
960 }
961 {
962 std::wcmatch m;
963 const wchar_t s[] = L"adefc";
964 assert(!std::regex_match(s, m, std::wregex(L"ab{3,5}c")));
965 assert(m.size() == 0);
966 }
967 {
968 std::wcmatch m;
969 const wchar_t s[] = L"abbbbbbc";
970 assert(!std::regex_match(s, m, std::wregex(L"ab{3,5}c")));
971 assert(m.size() == 0);
972 }
973 {
974 std::wcmatch m;
975 const wchar_t s[] = L"adec";
976 assert(!std::regex_match(s, m, std::wregex(L"a.{3,5}c")));
977 assert(m.size() == 0);
978 }
979 {
980 std::wcmatch m;
981 const wchar_t s[] = L"adefc";
982 assert(std::regex_match(s, m, std::wregex(L"a.{3,5}c")));
983 assert(m.size() == 1);
984 assert(!m.prefix().matched);
985 assert(m.prefix().first == s);
986 assert(m.prefix().second == m[0].first);
987 assert(!m.suffix().matched);
988 assert(m.suffix().first == m[0].second);
989 assert(m.suffix().second == m[0].second);
990 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
991 assert(m.position(0) == 0);
992 assert(m.str(0) == s);
993 }
994 {
995 std::wcmatch m;
996 const wchar_t s[] = L"adefgc";
997 assert(std::regex_match(s, m, std::wregex(L"a.{3,5}c")));
998 assert(m.size() == 1);
999 assert(!m.prefix().matched);
1000 assert(m.prefix().first == s);
1001 assert(m.prefix().second == m[0].first);
1002 assert(!m.suffix().matched);
1003 assert(m.suffix().first == m[0].second);
1004 assert(m.suffix().second == m[0].second);
1005 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
1006 assert(m.position(0) == 0);
1007 assert(m.str(0) == s);
1008 }
1009 {
1010 std::wcmatch m;
1011 const wchar_t s[] = L"adefghc";
1012 assert(std::regex_match(s, m, std::wregex(L"a.{3,5}c")));
1013 assert(m.size() == 1);
1014 assert(!m.prefix().matched);
1015 assert(m.prefix().first == s);
1016 assert(m.prefix().second == m[0].first);
1017 assert(!m.suffix().matched);
1018 assert(m.suffix().first == m[0].second);
1019 assert(m.suffix().second == m[0].second);
1020 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
1021 assert(m.position(0) == 0);
1022 assert(m.str(0) == s);
1023 }
1024 {
1025 std::wcmatch m;
1026 const wchar_t s[] = L"adefghic";
1027 assert(!std::regex_match(s, m, std::wregex(L"a.{3,5}c")));
1028 assert(m.size() == 0);
1029 }
1030 {
1031 std::wcmatch m;
1032 // http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2273
1033 const wchar_t s[] = L"tournament";
1034 assert(std::regex_match(s, m, std::wregex(L"tour|to|tournament")));
1035 assert(m.size() == 1);
1036 assert(!m.prefix().matched);
1037 assert(m.prefix().first == s);
1038 assert(m.prefix().second == m[0].first);
1039 assert(!m.suffix().matched);
1040 assert(m.suffix().first == m[0].second);
1041 assert(m.suffix().second == m[0].second);
1042 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
1043 assert(m.position(0) == 0);
1044 assert(m.str(0) == s);
1045 }
1046 {
1047 std::wcmatch m;
1048 // http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2273
1049 const wchar_t s[] = L"tournamenttotour";
1050 assert(
1051 std::regex_match(s, m, std::wregex(L"(tour|to|tournament)+",
1052 std::regex_constants::nosubs)));
1053 assert(m.size() == 1);
1054 assert(!m.prefix().matched);
1055 assert(m.prefix().first == s);
1056 assert(m.prefix().second == m[0].first);
1057 assert(!m.suffix().matched);
1058 assert(m.suffix().first == m[0].second);
1059 assert(m.suffix().second == m[0].second);
1060 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
1061 assert(m.position(0) == 0);
1062 assert(m.str(0) == s);
1063 }
1064 {
1065 std::wcmatch m;
1066 const wchar_t s[] = L"ttotour";
1067 assert(std::regex_match(s, m, std::wregex(L"(tour|to|t)+")));
1068 assert(m.size() == 2);
1069 assert(!m.prefix().matched);
1070 assert(m.prefix().first == s);
1071 assert(m.prefix().second == m[0].first);
1072 assert(!m.suffix().matched);
1073 assert(m.suffix().first == m[0].second);
1074 assert(m.suffix().second == m[0].second);
1075 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
1076 assert(m.position(0) == 0);
1077 assert(m.str(0) == s);
1078 assert(m.length(1) == 4);
1079 assert(m.position(1) == 3);
1080 assert(m.str(1) == L"tour");
1081 }
1082 {
1083 std::wcmatch m;
1084 const wchar_t s[] = L"-ab,ab-";
1085 assert(!std::regex_match(s, m, std::wregex(L"-(.*),\1-")));
1086 assert(m.size() == 0);
1087 }
1088 {
1089 std::wcmatch m;
1090 const wchar_t s[] = L"-ab,ab-";
1091 assert(std::regex_match(s, m, std::wregex(L"-.*,.*-")));
1092 assert(m.size() == 1);
1093 assert(!m.prefix().matched);
1094 assert(m.prefix().first == s);
1095 assert(m.prefix().second == m[0].first);
1096 assert(!m.suffix().matched);
1097 assert(m.suffix().first == m[0].second);
1098 assert(m.suffix().second == m[0].second);
1099 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
1100 assert(m.position(0) == 0);
1101 assert(m.str(0) == s);
1102 }
1103 {
1104 std::wcmatch m;
1105 const wchar_t s[] = L"a";
1106 assert(std::regex_match(s, m, std::wregex(L"^[a]$")));
1107 assert(m.size() == 1);
1108 assert(!m.prefix().matched);
1109 assert(m.prefix().first == s);
1110 assert(m.prefix().second == m[0].first);
1111 assert(!m.suffix().matched);
1112 assert(m.suffix().first == m[0].second);
1113 assert(m.suffix().second == m[0].second);
1114 assert(m.length(0) == 1);
1115 assert(m.position(0) == 0);
1116 assert(m.str(0) == L"a");
1117 }
1118 {
1119 std::wcmatch m;
1120 const wchar_t s[] = L"a";
1121 assert(std::regex_match(s, m, std::wregex(L"^[ab]$")));
1122 assert(m.size() == 1);
1123 assert(!m.prefix().matched);
1124 assert(m.prefix().first == s);
1125 assert(m.prefix().second == m[0].first);
1126 assert(!m.suffix().matched);
1127 assert(m.suffix().first == m[0].second);
1128 assert(m.suffix().second == m[0].second);
1129 assert(m.length(0) == 1);
1130 assert(m.position(0) == 0);
1131 assert(m.str(0) == L"a");
1132 }
1133 {
1134 std::wcmatch m;
1135 const wchar_t s[] = L"c";
1136 assert(std::regex_match(s, m, std::wregex(L"^[a-f]$")));
1137 assert(m.size() == 1);
1138 assert(!m.prefix().matched);
1139 assert(m.prefix().first == s);
1140 assert(m.prefix().second == m[0].first);
1141 assert(!m.suffix().matched);
1142 assert(m.suffix().first == m[0].second);
1143 assert(m.suffix().second == m[0].second);
1144 assert(m.length(0) == 1);
1145 assert(m.position(0) == 0);
1146 assert(m.str(0) == s);
1147 }
1148 {
1149 std::wcmatch m;
1150 const wchar_t s[] = L"g";
1151 assert(!std::regex_match(s, m, std::wregex(L"^[a-f]$")));
1152 assert(m.size() == 0);
1153 }
1154 {
1155 std::wcmatch m;
1156 const wchar_t s[] = L"Iraqi";
1157 assert(!std::regex_match(s, m, std::wregex(L"q[^u]")));
1158 assert(m.size() == 0);
1159 }
1160 {
1161 std::wcmatch m;
1162 const wchar_t s[] = L"Iraq";
1163 assert(!std::regex_match(s, m, std::wregex(L"q[^u]")));
1164 assert(m.size() == 0);
1165 }
1166 {
1167 std::wcmatch m;
1168 const wchar_t s[] = L"AmB";
1169 assert(std::regex_match(s, m, std::wregex(L"A[[:lower:]]B")));
1170 assert(m.size() == 1);
1171 assert(!m.prefix().matched);
1172 assert(m.prefix().first == s);
1173 assert(m.prefix().second == m[0].first);
1174 assert(!m.suffix().matched);
1175 assert(m.suffix().first == m[0].second);
1176 assert(m.suffix().second == m[0].second);
1177 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
1178 assert(m.position(0) == 0);
1179 assert(m.str(0) == s);
1180 }
1181 {
1182 std::wcmatch m;
1183 const wchar_t s[] = L"AMB";
1184 assert(!std::regex_match(s, m, std::wregex(L"A[[:lower:]]B")));
1185 assert(m.size() == 0);
1186 }
1187 {
1188 std::wcmatch m;
1189 const wchar_t s[] = L"AMB";
1190 assert(std::regex_match(s, m, std::wregex(L"A[^[:lower:]]B")));
1191 assert(m.size() == 1);
1192 assert(!m.prefix().matched);
1193 assert(m.prefix().first == s);
1194 assert(m.prefix().second == m[0].first);
1195 assert(!m.suffix().matched);
1196 assert(m.suffix().first == m[0].second);
1197 assert(m.suffix().second == m[0].second);
1198 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
1199 assert(m.position(0) == 0);
1200 assert(m.str(0) == s);
1201 }
1202 {
1203 std::wcmatch m;
1204 const wchar_t s[] = L"AmB";
1205 assert(!std::regex_match(s, m, std::wregex(L"A[^[:lower:]]B")));
1206 assert(m.size() == 0);
1207 }
1208 {
1209 std::wcmatch m;
1210 const wchar_t s[] = L"A5B";
1211 assert(!std::regex_match(s, m, std::wregex(L"A[^[:lower:]0-9]B")));
1212 assert(m.size() == 0);
1213 }
1214 {
1215 std::wcmatch m;
1216 const wchar_t s[] = L"A?B";
1217 assert(std::regex_match(s, m, std::wregex(L"A[^[:lower:]0-9]B")));
1218 assert(m.size() == 1);
1219 assert(!m.prefix().matched);
1220 assert(m.prefix().first == s);
1221 assert(m.prefix().second == m[0].first);
1222 assert(!m.suffix().matched);
1223 assert(m.suffix().first == m[0].second);
1224 assert(m.suffix().second == m[0].second);
1225 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
1226 assert(m.position(0) == 0);
1227 assert(m.str(0) == s);
1228 }
1229 {
1230 std::wcmatch m;
1231 const wchar_t s[] = L"-";
1232 assert(std::regex_match(s, m, std::wregex(L"[a[.hyphen.]z]")));
1233 assert(m.size() == 1);
1234 assert(!m.prefix().matched);
1235 assert(m.prefix().first == s);
1236 assert(m.prefix().second == m[0].first);
1237 assert(!m.suffix().matched);
1238 assert(m.suffix().first == m[0].second);
1239 assert(m.suffix().second == m[0].second);
1240 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
1241 assert(m.position(0) == 0);
1242 assert(m.str(0) == s);
1243 }
1244 {
1245 std::wcmatch m;
1246 const wchar_t s[] = L"z";
1247 assert(std::regex_match(s, m, std::wregex(L"[a[.hyphen.]z]")));
1248 assert(m.size() == 1);
1249 assert(!m.prefix().matched);
1250 assert(m.prefix().first == s);
1251 assert(m.prefix().second == m[0].first);
1252 assert(!m.suffix().matched);
1253 assert(m.suffix().first == m[0].second);
1254 assert(m.suffix().second == m[0].second);
1255 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
1256 assert(m.position(0) == 0);
1257 assert(m.str(0) == s);
1258 }
1259 {
1260 std::wcmatch m;
1261 const wchar_t s[] = L"m";
1262 assert(!std::regex_match(s, m, std::wregex(L"[a[.hyphen.]z]")));
1263 assert(m.size() == 0);
1264 }
1265 {
1266 std::wcmatch m;
1267 const wchar_t s[] = L"01a45cef9";
1268 assert(!std::regex_match(s, m, std::wregex(L"[ace1-9]*")));
1269 assert(m.size() == 0);
1270 }
1271 {
1272 std::wcmatch m;
1273 const wchar_t s[] = L"01a45cef9";
1274 assert(!std::regex_match(s, m, std::wregex(L"[ace1-9]+")));
1275 assert(m.size() == 0);
1276 }
1277 {
1278 const wchar_t r[] = L"^[-+]?[0-9]+[CF]$";
1279 std::ptrdiff_t sr = std::char_traits<wchar_t>::length(s: r);
1280 typedef forward_iterator<const wchar_t*> FI;
1281 typedef bidirectional_iterator<const wchar_t*> BI;
1282 std::wregex regex(FI(r), FI(r+sr));
1283 std::match_results<BI> m;
1284 const wchar_t s[] = L"-40C";
1285 std::ptrdiff_t ss = std::char_traits<wchar_t>::length(s: s);
1286 assert(std::regex_match(BI(s), BI(s+ss), m, regex));
1287 assert(m.size() == 1);
1288 assert(!m.prefix().matched);
1289 assert(m.prefix().first == BI(s));
1290 assert(m.prefix().second == m[0].first);
1291 assert(!m.suffix().matched);
1292 assert(m.suffix().first == m[0].second);
1293 assert(m.suffix().second == m[0].second);
1294 assert(m.length(0) == 4);
1295 assert(m.position(0) == 0);
1296 assert(m.str(0) == s);
1297 }
1298 {
1299 std::wcmatch m;
1300 const wchar_t s[] = L"Jeff Jeffs ";
1301 assert(!std::regex_match(s, m, std::wregex(L"Jeff(?=s\\b)")));
1302 assert(m.size() == 0);
1303 }
1304 {
1305 std::wcmatch m;
1306 const wchar_t s[] = L"Jeffs Jeff";
1307 assert(!std::regex_match(s, m, std::wregex(L"Jeff(?!s\\b)")));
1308 assert(m.size() == 0);
1309 }
1310 {
1311 std::wcmatch m;
1312 const wchar_t s[] = L"5%k";
1313 assert(std::regex_match(s, m, std::wregex(L"\\d[\\W]k")));
1314 assert(m.size() == 1);
1315 assert(!m.prefix().matched);
1316 assert(m.prefix().first == s);
1317 assert(m.prefix().second == m[0].first);
1318 assert(!m.suffix().matched);
1319 assert(m.suffix().first == m[0].second);
1320 assert(m.suffix().second == s + std::char_traits<wchar_t>::length(s));
1321 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
1322 assert(m.position(0) == 0);
1323 assert(m.str(0) == s);
1324 }
1325 {
1326 std::wcmatch m;
1327 const wchar_t s[] = L"$_se";
1328 assert(std::regex_match(s, m, std::wregex(L"\\$\\_se")));
1329 assert(m.size() == 1);
1330 assert(!m.prefix().matched);
1331 assert(m.prefix().first == s);
1332 assert(m.prefix().second == m[0].first);
1333 assert(!m.suffix().matched);
1334 assert(m.suffix().first == m[0].second);
1335 assert(m.suffix().second == s + std::char_traits<wchar_t>::length(s));
1336 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
1337 assert(m.position(0) == 0);
1338 assert(m.str(0) == s);
1339 }
1340#endif // TEST_HAS_NO_WIDE_CHARACTERS
1341
1342 return 0;
1343}
1344

source code of libcxx/test/std/re/re.alg/re.alg.match/ecma.pass.cpp