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 // XFAIL: LIBCXX-WINDOWS-FIXME
10 
11 // <regex>
12 
13 // template <class charT> struct regex_traits;
14 
15 // bool isctype(charT c, char_class_type f) const;
16 
17 
18 #include <regex>
19 #include <cassert>
20 #include "test_macros.h"
21 
main(int,char **)22 int main(int, char**)
23 {
24     {
25         std::regex_traits<char> t;
26 
27         std::string s("w");
28         assert( t.isctype('_', t.lookup_classname(s.begin(), s.end())));
29         assert( t.isctype('a', t.lookup_classname(s.begin(), s.end())));
30         assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
31         assert( t.isctype('5', t.lookup_classname(s.begin(), s.end())));
32         assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
33         assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
34         assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
35 
36         s = "alnum";
37         assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
38         assert( t.isctype('a', t.lookup_classname(s.begin(), s.end())));
39         assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
40         assert( t.isctype('5', t.lookup_classname(s.begin(), s.end())));
41         assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
42         assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
43         assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
44 
45         s = "alpha";
46         assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
47         assert( t.isctype('a', t.lookup_classname(s.begin(), s.end())));
48         assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
49         assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end())));
50         assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
51         assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
52         assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
53 
54         s = "blank";
55         assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
56         assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end())));
57         assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
58         assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end())));
59         assert( t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
60         assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
61         assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
62 
63         s = "cntrl";
64         assert( t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
65         assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
66         assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end())));
67         assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
68         assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end())));
69         assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
70         assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
71         assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
72 
73         s = "digit";
74         assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
75         assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
76         assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end())));
77         assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
78         assert( t.isctype('5', t.lookup_classname(s.begin(), s.end())));
79         assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
80         assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
81         assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
82 
83         s = "graph";
84         assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
85         assert( t.isctype('_', t.lookup_classname(s.begin(), s.end())));
86         assert( t.isctype('a', t.lookup_classname(s.begin(), s.end())));
87         assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
88         assert( t.isctype('5', t.lookup_classname(s.begin(), s.end())));
89         assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
90         assert( t.isctype('-', t.lookup_classname(s.begin(), s.end())));
91         assert( t.isctype('@', t.lookup_classname(s.begin(), s.end())));
92 
93         s = "lower";
94         assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
95         assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
96         assert( t.isctype('a', t.lookup_classname(s.begin(), s.end())));
97         assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
98         assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end())));
99         assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
100         assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
101         assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
102 
103         s = "print";
104         assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
105         assert( t.isctype('_', t.lookup_classname(s.begin(), s.end())));
106         assert( t.isctype('a', t.lookup_classname(s.begin(), s.end())));
107         assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
108         assert( t.isctype('5', t.lookup_classname(s.begin(), s.end())));
109         assert( t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
110         assert( t.isctype('-', t.lookup_classname(s.begin(), s.end())));
111         assert( t.isctype('@', t.lookup_classname(s.begin(), s.end())));
112 
113         s = "punct";
114         assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
115         assert( t.isctype('_', t.lookup_classname(s.begin(), s.end())));
116         assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end())));
117         assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
118         assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end())));
119         assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
120         assert( t.isctype('-', t.lookup_classname(s.begin(), s.end())));
121         assert( t.isctype('@', t.lookup_classname(s.begin(), s.end())));
122 
123         s = "space";
124         assert( t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
125         assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
126         assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end())));
127         assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
128         assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end())));
129         assert( t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
130         assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
131         assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
132 
133         s = "upper";
134         assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
135         assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
136         assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end())));
137         assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
138         assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end())));
139         assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
140         assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
141         assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
142 
143         s = "xdigit";
144         assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
145         assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
146         assert( t.isctype('a', t.lookup_classname(s.begin(), s.end())));
147         assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
148         assert( t.isctype('5', t.lookup_classname(s.begin(), s.end())));
149         assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
150         assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
151         assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
152     }
153     {
154         std::regex_traits<wchar_t> t;
155 
156         std::wstring s(L"w");
157         assert( t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
158         assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
159         assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
160         assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
161         assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
162         assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
163         assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
164 
165         s = L"alnum";
166         assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
167         assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
168         assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
169         assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
170         assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
171         assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
172         assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
173 
174         s = L"alpha";
175         assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
176         assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
177         assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
178         assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
179         assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
180         assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
181         assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
182 
183         s = L"blank";
184         assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
185         assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
186         assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
187         assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
188         assert( t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
189         assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
190         assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
191 
192         s = L"cntrl";
193         assert( t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
194         assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
195         assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
196         assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
197         assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
198         assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
199         assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
200         assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
201 
202         s = L"digit";
203         assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
204         assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
205         assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
206         assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
207         assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
208         assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
209         assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
210         assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
211 
212         s = L"graph";
213         assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
214         assert( t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
215         assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
216         assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
217         assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
218         assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
219         assert( t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
220         assert( t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
221 
222         s = L"lower";
223         assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
224         assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
225         assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
226         assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
227         assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
228         assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
229         assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
230         assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
231 
232         s = L"print";
233         assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
234         assert( t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
235         assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
236         assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
237         assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
238         assert( t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
239         assert( t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
240         assert( t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
241 
242         s = L"punct";
243         assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
244         assert( t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
245         assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
246         assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
247         assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
248         assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
249         assert( t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
250         assert( t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
251 
252         s = L"space";
253         assert( t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
254         assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
255         assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
256         assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
257         assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
258         assert( t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
259         assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
260         assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
261 
262         s = L"upper";
263         assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
264         assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
265         assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
266         assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
267         assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
268         assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
269         assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
270         assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
271 
272         s = L"xdigit";
273         assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
274         assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
275         assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
276         assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
277         assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
278         assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
279         assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
280         assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
281     }
282 
283   return 0;
284 }
285