lookup_classname.pass.cpp
9.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <regex>
// template <class charT> struct regex_traits;
// template <class ForwardIterator>
// char_class_type
// lookup_classname(ForwardIterator first, ForwardIterator last,
// bool icase = false) const;
#include <regex>
#include <cassert>
#include "test_macros.h"
#include "test_iterators.h"
template <class char_type>
void
test(const char_type* A,
typename std::regex_traits<char_type>::char_class_type expected,
bool icase = false)
{
typedef typename std::regex_traits<char_type>::char_class_type char_class_type;
std::regex_traits<char_type> t;
typedef forward_iterator<const char_type*> F;
char_class_type result = t.lookup_classname(F(A), F(A + t.length(A)), icase);
assert(result == expected);
}
template <class char_type>
void
test_w(const char_type* A,
typename std::regex_traits<char_type>::char_class_type expected,
bool icase = false)
{
typedef typename std::regex_traits<char_type>::char_class_type char_class_type;
std::regex_traits<char_type> t;
typedef forward_iterator<const char_type*> F;
char_class_type result = t.lookup_classname(F(A), F(A + t.length(A)), icase);
assert((result & expected) == expected);
LIBCPP_ASSERT((expected | std::regex_traits<char_type>::__regex_word) == result);
const bool matches_underscore = t.isctype('_', result);
if (result != expected)
assert(matches_underscore && "expected to match underscore");
else
assert(!matches_underscore && "should not match underscore");
}
int main(int, char**)
{
// if __regex_word is not distinct from all the classes, bad things happen
// See https://bugs.llvm.org/show_bug.cgi?id=26476 for an example.
LIBCPP_ASSERT((std::ctype_base::space & std::regex_traits<char>::__regex_word) == 0);
LIBCPP_ASSERT((std::ctype_base::print & std::regex_traits<char>::__regex_word) == 0);
LIBCPP_ASSERT((std::ctype_base::cntrl & std::regex_traits<char>::__regex_word) == 0);
LIBCPP_ASSERT((std::ctype_base::upper & std::regex_traits<char>::__regex_word) == 0);
LIBCPP_ASSERT((std::ctype_base::lower & std::regex_traits<char>::__regex_word) == 0);
LIBCPP_ASSERT((std::ctype_base::alpha & std::regex_traits<char>::__regex_word) == 0);
LIBCPP_ASSERT((std::ctype_base::digit & std::regex_traits<char>::__regex_word) == 0);
LIBCPP_ASSERT((std::ctype_base::punct & std::regex_traits<char>::__regex_word) == 0);
LIBCPP_ASSERT((std::ctype_base::xdigit & std::regex_traits<char>::__regex_word) == 0);
LIBCPP_ASSERT((std::ctype_base::blank & std::regex_traits<char>::__regex_word) == 0);
test("d", std::ctype_base::digit);
test("D", std::ctype_base::digit);
test("d", std::ctype_base::digit, true);
test("D", std::ctype_base::digit, true);
test_w("w", std::ctype_base::alnum
| std::ctype_base::upper | std::ctype_base::lower);
test_w("W", std::ctype_base::alnum
| std::ctype_base::upper | std::ctype_base::lower);
test_w("w", std::ctype_base::alnum
| std::ctype_base::upper | std::ctype_base::lower, true);
test_w("W", std::ctype_base::alnum
| std::ctype_base::upper | std::ctype_base::lower, true);
test("s", std::ctype_base::space);
test("S", std::ctype_base::space);
test("s", std::ctype_base::space, true);
test("S", std::ctype_base::space, true);
test("alnum", std::ctype_base::alnum);
test("AlNum", std::ctype_base::alnum);
test("alnum", std::ctype_base::alnum, true);
test("AlNum", std::ctype_base::alnum, true);
test("alpha", std::ctype_base::alpha);
test("Alpha", std::ctype_base::alpha);
test("alpha", std::ctype_base::alpha, true);
test("Alpha", std::ctype_base::alpha, true);
test("blank", std::ctype_base::blank);
test("Blank", std::ctype_base::blank);
test("blank", std::ctype_base::blank, true);
test("Blank", std::ctype_base::blank, true);
test("cntrl", std::ctype_base::cntrl);
test("Cntrl", std::ctype_base::cntrl);
test("cntrl", std::ctype_base::cntrl, true);
test("Cntrl", std::ctype_base::cntrl, true);
test("digit", std::ctype_base::digit);
test("Digit", std::ctype_base::digit);
test("digit", std::ctype_base::digit, true);
test("Digit", std::ctype_base::digit, true);
test("digit", std::ctype_base::digit);
test("DIGIT", std::ctype_base::digit);
test("digit", std::ctype_base::digit, true);
test("Digit", std::ctype_base::digit, true);
test("graph", std::ctype_base::graph);
test("GRAPH", std::ctype_base::graph);
test("graph", std::ctype_base::graph, true);
test("Graph", std::ctype_base::graph, true);
test("lower", std::ctype_base::lower);
test("LOWER", std::ctype_base::lower);
test("lower", std::ctype_base::lower | std::ctype_base::alpha, true);
test("Lower", std::ctype_base::lower | std::ctype_base::alpha, true);
test("print", std::ctype_base::print);
test("PRINT", std::ctype_base::print);
test("print", std::ctype_base::print, true);
test("Print", std::ctype_base::print, true);
test("punct", std::ctype_base::punct);
test("PUNCT", std::ctype_base::punct);
test("punct", std::ctype_base::punct, true);
test("Punct", std::ctype_base::punct, true);
test("space", std::ctype_base::space);
test("SPACE", std::ctype_base::space);
test("space", std::ctype_base::space, true);
test("Space", std::ctype_base::space, true);
test("upper", std::ctype_base::upper);
test("UPPER", std::ctype_base::upper);
test("upper", std::ctype_base::upper | std::ctype_base::alpha, true);
test("Upper", std::ctype_base::upper | std::ctype_base::alpha, true);
test("xdigit", std::ctype_base::xdigit);
test("XDIGIT", std::ctype_base::xdigit);
test("xdigit", std::ctype_base::xdigit, true);
test("Xdigit", std::ctype_base::xdigit, true);
test("dig", std::ctype_base::mask());
test("", std::ctype_base::mask());
test("digits", std::ctype_base::mask());
test(L"d", std::ctype_base::digit);
test(L"D", std::ctype_base::digit);
test(L"d", std::ctype_base::digit, true);
test(L"D", std::ctype_base::digit, true);
test_w(L"w", std::ctype_base::alnum
| std::ctype_base::upper | std::ctype_base::lower);
test_w(L"W", std::ctype_base::alnum
| std::ctype_base::upper | std::ctype_base::lower);
test_w(L"w", std::ctype_base::alnum
| std::ctype_base::upper | std::ctype_base::lower, true);
test_w(L"W", std::ctype_base::alnum
| std::ctype_base::upper | std::ctype_base::lower, true);
test(L"s", std::ctype_base::space);
test(L"S", std::ctype_base::space);
test(L"s", std::ctype_base::space, true);
test(L"S", std::ctype_base::space, true);
test(L"alnum", std::ctype_base::alnum);
test(L"AlNum", std::ctype_base::alnum);
test(L"alnum", std::ctype_base::alnum, true);
test(L"AlNum", std::ctype_base::alnum, true);
test(L"alpha", std::ctype_base::alpha);
test(L"Alpha", std::ctype_base::alpha);
test(L"alpha", std::ctype_base::alpha, true);
test(L"Alpha", std::ctype_base::alpha, true);
test(L"blank", std::ctype_base::blank);
test(L"Blank", std::ctype_base::blank);
test(L"blank", std::ctype_base::blank, true);
test(L"Blank", std::ctype_base::blank, true);
test(L"cntrl", std::ctype_base::cntrl);
test(L"Cntrl", std::ctype_base::cntrl);
test(L"cntrl", std::ctype_base::cntrl, true);
test(L"Cntrl", std::ctype_base::cntrl, true);
test(L"digit", std::ctype_base::digit);
test(L"Digit", std::ctype_base::digit);
test(L"digit", std::ctype_base::digit, true);
test(L"Digit", std::ctype_base::digit, true);
test(L"digit", std::ctype_base::digit);
test(L"DIGIT", std::ctype_base::digit);
test(L"digit", std::ctype_base::digit, true);
test(L"Digit", std::ctype_base::digit, true);
test(L"graph", std::ctype_base::graph);
test(L"GRAPH", std::ctype_base::graph);
test(L"graph", std::ctype_base::graph, true);
test(L"Graph", std::ctype_base::graph, true);
test(L"lower", std::ctype_base::lower);
test(L"LOWER", std::ctype_base::lower);
test(L"lower", std::ctype_base::lower | std::ctype_base::alpha, true);
test(L"Lower", std::ctype_base::lower | std::ctype_base::alpha, true);
test(L"print", std::ctype_base::print);
test(L"PRINT", std::ctype_base::print);
test(L"print", std::ctype_base::print, true);
test(L"Print", std::ctype_base::print, true);
test(L"punct", std::ctype_base::punct);
test(L"PUNCT", std::ctype_base::punct);
test(L"punct", std::ctype_base::punct, true);
test(L"Punct", std::ctype_base::punct, true);
test(L"space", std::ctype_base::space);
test(L"SPACE", std::ctype_base::space);
test(L"space", std::ctype_base::space, true);
test(L"Space", std::ctype_base::space, true);
test(L"upper", std::ctype_base::upper);
test(L"UPPER", std::ctype_base::upper);
test(L"upper", std::ctype_base::upper | std::ctype_base::alpha, true);
test(L"Upper", std::ctype_base::upper | std::ctype_base::alpha, true);
test(L"xdigit", std::ctype_base::xdigit);
test(L"XDIGIT", std::ctype_base::xdigit);
test(L"xdigit", std::ctype_base::xdigit, true);
test(L"Xdigit", std::ctype_base::xdigit, true);
test(L"dig", std::ctype_base::mask());
test(L"", std::ctype_base::mask());
test(L"digits", std::ctype_base::mask());
return 0;
}