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