]>
Commit | Line | Data |
---|---|---|
399eeef9 TS |
1 | // { dg-options "-std=gnu++11" } |
2 | ||
3 | // | |
4 | // 2013-08-01 Tim Shen <timshen91@gmail.com> | |
5 | // | |
818ab71a | 6 | // Copyright (C) 2013-2016 Free Software Foundation, Inc. |
399eeef9 TS |
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> | |
6cb43087 TS |
28 | #include <testsuite_regex.h> |
29 | ||
30 | using namespace __gnu_test; | |
31 | using namespace std; | |
399eeef9 TS |
32 | |
33 | void | |
34 | test01() | |
35 | { | |
36 | bool test __attribute__((unused)) = true; | |
37 | ||
38 | { | |
39 | std::regex re("pre/[za-x]", std::regex::extended); | |
6cb43087 TS |
40 | VERIFY( regex_match_debug("pre/z", re) ); |
41 | VERIFY( regex_match_debug("pre/a", re) ); | |
42 | VERIFY( !regex_match_debug("pre/y", re) ); | |
399eeef9 TS |
43 | } |
44 | { | |
45 | std::regex re("pre/[[:uPPer:]]", std::regex::extended); | |
6cb43087 TS |
46 | VERIFY( regex_match_debug("pre/Z", re) ); |
47 | VERIFY( !regex_match_debug("pre/_", re) ); | |
48 | VERIFY( !regex_match_debug("pre/a", re) ); | |
49 | VERIFY( !regex_match_debug("pre/0", re) ); | |
399eeef9 TS |
50 | } |
51 | { | |
52 | std::regex re("pre/[[:lOWer:]]", std::regex::extended | std::regex::icase); | |
6cb43087 TS |
53 | VERIFY( regex_match_debug("pre/Z", re) ); |
54 | VERIFY( regex_match_debug("pre/a", re) ); | |
399eeef9 TS |
55 | } |
56 | { | |
57 | std::regex re("pre/[[:w:][.tilde.]]", std::regex::extended); | |
6cb43087 TS |
58 | VERIFY( regex_match_debug("pre/~", re) ); |
59 | VERIFY( regex_match_debug("pre/_", re) ); | |
60 | VERIFY( regex_match_debug("pre/a", re) ); | |
61 | VERIFY( regex_match_debug("pre/0", re) ); | |
399eeef9 | 62 | } |
756aa0c3 TS |
63 | { |
64 | std::regex re("pre/[[=a=]]", std::regex::extended); | |
6cb43087 TS |
65 | VERIFY( regex_match_debug("pre/a", re) ); |
66 | VERIFY( regex_match_debug("pre/A", re) ); | |
756aa0c3 | 67 | } |
399eeef9 TS |
68 | } |
69 | ||
79b576cc TS |
70 | void |
71 | test02() | |
72 | { | |
73 | bool test __attribute__((unused)) = true; | |
74 | ||
75 | try | |
76 | { | |
77 | std::regex re("[-----]", std::regex::extended); | |
78 | VERIFY(false); | |
79 | } | |
80 | catch (const std::regex_error& e) | |
81 | { | |
82 | VERIFY(e.code() == std::regex_constants::error_range); | |
83 | } | |
84 | std::regex re("[-----]", std::regex::ECMAScript); | |
f9ce3c16 TS |
85 | |
86 | VERIFY(!regex_match("b", regex("[-ac]", regex_constants::extended))); | |
87 | VERIFY(!regex_match("b", regex("[ac-]", regex_constants::extended))); | |
88 | VERIFY(regex_match("b", regex("[^-ac]", regex_constants::extended))); | |
89 | VERIFY(regex_match("b", regex("[^ac-]", regex_constants::extended))); | |
90 | VERIFY(regex_match("&", regex("[%--]", regex_constants::extended))); | |
91 | VERIFY(regex_match(".", regex("[--@]", regex_constants::extended))); | |
92 | try | |
93 | { | |
94 | regex("[a--@]", regex_constants::extended); | |
95 | VERIFY(false); | |
96 | } | |
97 | catch (const std::regex_error& e) | |
98 | { | |
99 | } | |
100 | VERIFY(regex_match("].", regex("[][.hyphen.]-0]*", regex_constants::extended))); | |
79b576cc TS |
101 | } |
102 | ||
103 | void | |
104 | test03() | |
105 | { | |
106 | bool test __attribute__((unused)) = true; | |
107 | ||
108 | try | |
109 | { | |
110 | std::regex re("[z-a]", std::regex::extended); | |
111 | VERIFY(false); | |
112 | } | |
113 | catch (const std::regex_error& e) | |
114 | { | |
115 | VERIFY(e.code() == std::regex_constants::error_range); | |
116 | } | |
117 | } | |
118 | ||
119 | void | |
120 | test04() | |
121 | { | |
122 | bool test __attribute__((unused)) = true; | |
123 | ||
124 | std::regex re("[-0-9a-z]"); | |
125 | VERIFY(regex_match_debug("-", re)); | |
126 | VERIFY(regex_match_debug("1", re)); | |
127 | VERIFY(regex_match_debug("w", re)); | |
128 | re.assign("[-0-9a-z]", regex_constants::basic); | |
129 | VERIFY(regex_match_debug("-", re)); | |
130 | VERIFY(regex_match_debug("1", re)); | |
131 | VERIFY(regex_match_debug("w", re)); | |
132 | } | |
133 | ||
f9ce3c16 TS |
134 | // libstdc++/67015 |
135 | void | |
136 | test05() | |
137 | { | |
138 | bool test __attribute__((unused)) = true; | |
139 | ||
140 | regex lanana_namespace("^[a-z0-9]+$", regex::extended); | |
141 | regex lsb_namespace("^_?([a-z0-9_.]+-, regex::extended)+[a-z0-9]+$"); | |
142 | regex debian_dpkg_conffile_cruft("dpkg-(old|dist|new|tmp, regex::extended)$"); | |
143 | regex debian_cron_namespace("^[a-z0-9][a-z0-9-]*$", regex::extended); | |
144 | VERIFY(regex_match("test", debian_cron_namespace)); | |
145 | VERIFY(!regex_match("-a", debian_cron_namespace)); | |
146 | VERIFY(regex_match("a-", debian_cron_namespace)); | |
147 | regex debian_cron_namespace_ok("^[a-z0-9][-a-z0-9]*$", regex::extended); | |
148 | VERIFY(regex_match("test", debian_cron_namespace_ok)); | |
149 | VERIFY(!regex_match("-a", debian_cron_namespace_ok)); | |
150 | VERIFY(regex_match("a-", debian_cron_namespace_ok)); | |
151 | } | |
152 | ||
153 | // libstdc++/67015 | |
154 | void | |
155 | test06() | |
156 | { | |
157 | bool test __attribute__((unused)) = true; | |
158 | ||
159 | regex lanana_namespace("^[a-z0-9]+$"); | |
160 | regex lsb_namespace("^_?([a-z0-9_.]+-)+[a-z0-9]+$"); | |
161 | regex debian_dpkg_conffile_cruft("dpkg-(old|dist|new|tmp)$"); | |
162 | regex debian_cron_namespace("^[a-z0-9][a-z0-9-]*$"); | |
163 | VERIFY(regex_match("test", debian_cron_namespace)); | |
164 | VERIFY(!regex_match("-a", debian_cron_namespace)); | |
165 | VERIFY(regex_match("a-", debian_cron_namespace)); | |
166 | regex debian_cron_namespace_ok("^[a-z0-9][-a-z0-9]*$"); | |
167 | VERIFY(regex_match("test", debian_cron_namespace_ok)); | |
168 | VERIFY(!regex_match("-a", debian_cron_namespace_ok)); | |
169 | VERIFY(regex_match("a-", debian_cron_namespace_ok)); | |
170 | } | |
171 | ||
399eeef9 TS |
172 | int |
173 | main() | |
174 | { | |
175 | test01(); | |
79b576cc TS |
176 | test02(); |
177 | test03(); | |
178 | test04(); | |
f9ce3c16 TS |
179 | test05(); |
180 | test06(); | |
181 | ||
399eeef9 TS |
182 | return 0; |
183 | } |