]>
Commit | Line | Data |
---|---|---|
be58e01d | 1 | // { dg-do run { target c++11 } } |
680e52bb | 2 | |
3 | // | |
4 | // 2013-08-01 Tim Shen <timshen91@gmail.com> | |
5 | // | |
fbd26352 | 6 | // Copyright (C) 2013-2019 Free Software Foundation, Inc. |
680e52bb | 7 | // |
8 | // This file is part of the GNU ISO C++ Library. This library is free | |
9 | // software; you can redistribute it and/or modify it under the | |
10 | // terms of the GNU General Public License as published by the | |
11 | // Free Software Foundation; either version 3, or (at your option) | |
12 | // any later version. | |
13 | // | |
14 | // This library is distributed in the hope that it will be useful, | |
15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | // GNU General Public License for more details. | |
18 | // | |
19 | // You should have received a copy of the GNU General Public License along | |
20 | // with this library; see the file COPYING3. If not see | |
21 | // <http://www.gnu.org/licenses/>. | |
22 | ||
23 | // 28.11.2 regex_match | |
24 | // Tests Extended bracket expression against a C-string. | |
25 | ||
26 | #include <regex> | |
27 | #include <testsuite_hooks.h> | |
96f22277 | 28 | #include <testsuite_regex.h> |
29 | ||
30 | using namespace __gnu_test; | |
31 | using namespace std; | |
680e52bb | 32 | |
33 | void | |
34 | test01() | |
35 | { | |
680e52bb | 36 | { |
37 | std::regex re("pre/[za-x]", std::regex::extended); | |
96f22277 | 38 | VERIFY( regex_match_debug("pre/z", re) ); |
39 | VERIFY( regex_match_debug("pre/a", re) ); | |
40 | VERIFY( !regex_match_debug("pre/y", re) ); | |
680e52bb | 41 | } |
42 | { | |
43 | std::regex re("pre/[[:uPPer:]]", std::regex::extended); | |
96f22277 | 44 | VERIFY( regex_match_debug("pre/Z", re) ); |
45 | VERIFY( !regex_match_debug("pre/_", re) ); | |
46 | VERIFY( !regex_match_debug("pre/a", re) ); | |
47 | VERIFY( !regex_match_debug("pre/0", re) ); | |
680e52bb | 48 | } |
49 | { | |
50 | std::regex re("pre/[[:lOWer:]]", std::regex::extended | std::regex::icase); | |
96f22277 | 51 | VERIFY( regex_match_debug("pre/Z", re) ); |
52 | VERIFY( regex_match_debug("pre/a", re) ); | |
680e52bb | 53 | } |
54 | { | |
55 | std::regex re("pre/[[:w:][.tilde.]]", std::regex::extended); | |
96f22277 | 56 | VERIFY( regex_match_debug("pre/~", re) ); |
57 | VERIFY( regex_match_debug("pre/_", re) ); | |
58 | VERIFY( regex_match_debug("pre/a", re) ); | |
59 | VERIFY( regex_match_debug("pre/0", re) ); | |
680e52bb | 60 | } |
45ae37cf | 61 | { |
62 | std::regex re("pre/[[=a=]]", std::regex::extended); | |
96f22277 | 63 | VERIFY( regex_match_debug("pre/a", re) ); |
64 | VERIFY( regex_match_debug("pre/A", re) ); | |
45ae37cf | 65 | } |
680e52bb | 66 | } |
67 | ||
3167598c | 68 | void |
69 | test02() | |
70 | { | |
3167598c | 71 | try |
72 | { | |
73 | std::regex re("[-----]", std::regex::extended); | |
74 | VERIFY(false); | |
75 | } | |
76 | catch (const std::regex_error& e) | |
77 | { | |
78 | VERIFY(e.code() == std::regex_constants::error_range); | |
79 | } | |
80 | std::regex re("[-----]", std::regex::ECMAScript); | |
940cb7d3 | 81 | |
82 | VERIFY(!regex_match("b", regex("[-ac]", regex_constants::extended))); | |
83 | VERIFY(!regex_match("b", regex("[ac-]", regex_constants::extended))); | |
84 | VERIFY(regex_match("b", regex("[^-ac]", regex_constants::extended))); | |
85 | VERIFY(regex_match("b", regex("[^ac-]", regex_constants::extended))); | |
86 | VERIFY(regex_match("&", regex("[%--]", regex_constants::extended))); | |
87 | VERIFY(regex_match(".", regex("[--@]", regex_constants::extended))); | |
88 | try | |
89 | { | |
90 | regex("[a--@]", regex_constants::extended); | |
91 | VERIFY(false); | |
92 | } | |
93 | catch (const std::regex_error& e) | |
94 | { | |
95 | } | |
96 | VERIFY(regex_match("].", regex("[][.hyphen.]-0]*", regex_constants::extended))); | |
3167598c | 97 | } |
98 | ||
99 | void | |
100 | test03() | |
101 | { | |
3167598c | 102 | try |
103 | { | |
104 | std::regex re("[z-a]", std::regex::extended); | |
105 | VERIFY(false); | |
106 | } | |
107 | catch (const std::regex_error& e) | |
108 | { | |
109 | VERIFY(e.code() == std::regex_constants::error_range); | |
110 | } | |
111 | } | |
112 | ||
113 | void | |
114 | test04() | |
115 | { | |
3167598c | 116 | std::regex re("[-0-9a-z]"); |
117 | VERIFY(regex_match_debug("-", re)); | |
118 | VERIFY(regex_match_debug("1", re)); | |
119 | VERIFY(regex_match_debug("w", re)); | |
120 | re.assign("[-0-9a-z]", regex_constants::basic); | |
121 | VERIFY(regex_match_debug("-", re)); | |
122 | VERIFY(regex_match_debug("1", re)); | |
123 | VERIFY(regex_match_debug("w", re)); | |
124 | } | |
125 | ||
940cb7d3 | 126 | // libstdc++/67015 |
127 | void | |
128 | test05() | |
129 | { | |
940cb7d3 | 130 | regex lanana_namespace("^[a-z0-9]+$", regex::extended); |
131 | regex lsb_namespace("^_?([a-z0-9_.]+-, regex::extended)+[a-z0-9]+$"); | |
132 | regex debian_dpkg_conffile_cruft("dpkg-(old|dist|new|tmp, regex::extended)$"); | |
133 | regex debian_cron_namespace("^[a-z0-9][a-z0-9-]*$", regex::extended); | |
134 | VERIFY(regex_match("test", debian_cron_namespace)); | |
135 | VERIFY(!regex_match("-a", debian_cron_namespace)); | |
136 | VERIFY(regex_match("a-", debian_cron_namespace)); | |
137 | regex debian_cron_namespace_ok("^[a-z0-9][-a-z0-9]*$", regex::extended); | |
138 | VERIFY(regex_match("test", debian_cron_namespace_ok)); | |
139 | VERIFY(!regex_match("-a", debian_cron_namespace_ok)); | |
140 | VERIFY(regex_match("a-", debian_cron_namespace_ok)); | |
141 | } | |
142 | ||
143 | // libstdc++/67015 | |
144 | void | |
145 | test06() | |
146 | { | |
940cb7d3 | 147 | regex lanana_namespace("^[a-z0-9]+$"); |
148 | regex lsb_namespace("^_?([a-z0-9_.]+-)+[a-z0-9]+$"); | |
149 | regex debian_dpkg_conffile_cruft("dpkg-(old|dist|new|tmp)$"); | |
150 | regex debian_cron_namespace("^[a-z0-9][a-z0-9-]*$"); | |
151 | VERIFY(regex_match("test", debian_cron_namespace)); | |
152 | VERIFY(!regex_match("-a", debian_cron_namespace)); | |
153 | VERIFY(regex_match("a-", debian_cron_namespace)); | |
154 | regex debian_cron_namespace_ok("^[a-z0-9][-a-z0-9]*$"); | |
155 | VERIFY(regex_match("test", debian_cron_namespace_ok)); | |
156 | VERIFY(!regex_match("-a", debian_cron_namespace_ok)); | |
157 | VERIFY(regex_match("a-", debian_cron_namespace_ok)); | |
158 | } | |
159 | ||
680e52bb | 160 | int |
161 | main() | |
162 | { | |
163 | test01(); | |
3167598c | 164 | test02(); |
165 | test03(); | |
166 | test04(); | |
940cb7d3 | 167 | test05(); |
168 | test06(); | |
169 | ||
680e52bb | 170 | return 0; |
171 | } |