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