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