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 // NetBSD does not support LC_COLLATE at the moment
11 // XFAIL: netbsd
12 
13 // REQUIRES: locale.cs_CZ.ISO8859-2
14 
15 // <regex>
16 
17 // template <class charT> struct regex_traits;
18 
19 // template <class ForwardIterator>
20 //   string_type
21 //   lookup_collatename(ForwardIterator first, ForwardIterator last) const;
22 
23 // TODO: investigation needed
24 // XFAIL: linux-gnu
25 
26 #include <regex>
27 #include <iterator>
28 #include <cassert>
29 
30 #include "test_macros.h"
31 #include "test_iterators.h"
32 #include "platform_support.h" // locale name macros
33 
34 template <class char_type>
35 void
test(const char_type * A,const std::basic_string<char_type> & expected)36 test(const char_type* A, const std::basic_string<char_type>& expected)
37 {
38     std::regex_traits<char_type> t;
39     typedef forward_iterator<const char_type*> F;
40     assert(t.lookup_collatename(F(A), F(A + t.length(A))) == expected);
41 }
42 
main()43 int main()
44 {
45     test("NUL", std::string("\x00", 1));
46     test("alert", std::string("\x07"));
47     test("backspace", std::string("\x08"));
48     test("tab", std::string("\x09"));
49     test("carriage-return", std::string("\x0D"));
50     test("newline", std::string("\x0A"));
51     test("vertical-tab", std::string("\x0B"));
52     test("form-feed", std::string("\x0C"));
53     test("space", std::string(" "));
54     test("exclamation-mark", std::string("!"));
55     test("quotation-mark", std::string("\""));
56     test("number-sign", std::string("#"));
57     test("dollar-sign", std::string("$"));
58     test("percent-sign", std::string("%"));
59     test("ampersand", std::string("&"));
60     test("apostrophe", std::string("\'"));
61     test("left-parenthesis", std::string("("));
62     test("right-parenthesis", std::string(")"));
63     test("asterisk", std::string("*"));
64     test("plus-sign", std::string("+"));
65     test("comma", std::string(","));
66     test("hyphen-minus", std::string("-"));
67     test("hyphen", std::string("-"));
68     test("full-stop", std::string("."));
69     test("period", std::string("."));
70     test("slash", std::string("/"));
71     test("solidus", std::string("/"));
72     test("zero", std::string("0"));
73     test("one", std::string("1"));
74     test("two", std::string("2"));
75     test("three", std::string("3"));
76     test("four", std::string("4"));
77     test("five", std::string("5"));
78     test("six", std::string("6"));
79     test("seven", std::string("7"));
80     test("eight", std::string("8"));
81     test("nine", std::string("9"));
82     test("colon", std::string(":"));
83     test("semicolon", std::string(";"));
84     test("less-than-sign", std::string("<"));
85     test("equals-sign", std::string("="));
86     test("greater-than-sign", std::string(">"));
87     test("question-mark", std::string("?"));
88     test("commercial-at", std::string("@"));
89     for (char c = 'A'; c <= 'Z'; ++c)
90     {
91         const char a[2] = {c};
92         test(a, std::string(a));
93     }
94     test("left-square-bracket", std::string("["));
95     test("backslash", std::string("\\"));
96     test("reverse-solidus", std::string("\\"));
97     test("right-square-bracket", std::string("]"));
98     test("circumflex-accent", std::string("^"));
99     test("circumflex", std::string("^"));
100     test("low-line", std::string("_"));
101     test("underscore", std::string("_"));
102     test("grave-accent", std::string("`"));
103     for (char c = 'a'; c <= 'z'; ++c)
104     {
105         const char a[2] = {c};
106         test(a, std::string(a));
107     }
108     test("left-brace", std::string("{"));
109     test("left-curly-bracket", std::string("{"));
110     test("vertical-line", std::string("|"));
111     test("right-brace", std::string("}"));
112     test("right-curly-bracket", std::string("}"));
113     test("tilde", std::string("~"));
114 
115     test("tild", std::string(""));
116     test("ch", std::string(""));
117     std::locale::global(std::locale(LOCALE_cs_CZ_ISO8859_2));
118     test("ch", std::string("ch"));
119     std::locale::global(std::locale("C"));
120 
121     test(L"NUL", std::wstring(L"\x00", 1));
122     test(L"alert", std::wstring(L"\x07"));
123     test(L"backspace", std::wstring(L"\x08"));
124     test(L"tab", std::wstring(L"\x09"));
125     test(L"carriage-return", std::wstring(L"\x0D"));
126     test(L"newline", std::wstring(L"\x0A"));
127     test(L"vertical-tab", std::wstring(L"\x0B"));
128     test(L"form-feed", std::wstring(L"\x0C"));
129     test(L"space", std::wstring(L" "));
130     test(L"exclamation-mark", std::wstring(L"!"));
131     test(L"quotation-mark", std::wstring(L"\""));
132     test(L"number-sign", std::wstring(L"#"));
133     test(L"dollar-sign", std::wstring(L"$"));
134     test(L"percent-sign", std::wstring(L"%"));
135     test(L"ampersand", std::wstring(L"&"));
136     test(L"apostrophe", std::wstring(L"\'"));
137     test(L"left-parenthesis", std::wstring(L"("));
138     test(L"right-parenthesis", std::wstring(L")"));
139     test(L"asterisk", std::wstring(L"*"));
140     test(L"plus-sign", std::wstring(L"+"));
141     test(L"comma", std::wstring(L","));
142     test(L"hyphen-minus", std::wstring(L"-"));
143     test(L"hyphen", std::wstring(L"-"));
144     test(L"full-stop", std::wstring(L"."));
145     test(L"period", std::wstring(L"."));
146     test(L"slash", std::wstring(L"/"));
147     test(L"solidus", std::wstring(L"/"));
148     test(L"zero", std::wstring(L"0"));
149     test(L"one", std::wstring(L"1"));
150     test(L"two", std::wstring(L"2"));
151     test(L"three", std::wstring(L"3"));
152     test(L"four", std::wstring(L"4"));
153     test(L"five", std::wstring(L"5"));
154     test(L"six", std::wstring(L"6"));
155     test(L"seven", std::wstring(L"7"));
156     test(L"eight", std::wstring(L"8"));
157     test(L"nine", std::wstring(L"9"));
158     test(L"colon", std::wstring(L":"));
159     test(L"semicolon", std::wstring(L";"));
160     test(L"less-than-sign", std::wstring(L"<"));
161     test(L"equals-sign", std::wstring(L"="));
162     test(L"greater-than-sign", std::wstring(L">"));
163     test(L"question-mark", std::wstring(L"?"));
164     test(L"commercial-at", std::wstring(L"@"));
165     for (wchar_t c = L'A'; c <= L'Z'; ++c)
166     {
167         const wchar_t a[2] = {c};
168         test(a, std::wstring(a));
169     }
170     test(L"left-square-bracket", std::wstring(L"["));
171     test(L"backslash", std::wstring(L"\\"));
172     test(L"reverse-solidus", std::wstring(L"\\"));
173     test(L"right-square-bracket", std::wstring(L"]"));
174     test(L"circumflex-accent", std::wstring(L"^"));
175     test(L"circumflex", std::wstring(L"^"));
176     test(L"low-line", std::wstring(L"_"));
177     test(L"underscore", std::wstring(L"_"));
178     test(L"grave-accent", std::wstring(L"`"));
179     for (wchar_t c = L'a'; c <= L'z'; ++c)
180     {
181         const wchar_t a[2] = {c};
182         test(a, std::wstring(a));
183     }
184     test(L"left-brace", std::wstring(L"{"));
185     test(L"left-curly-bracket", std::wstring(L"{"));
186     test(L"vertical-line", std::wstring(L"|"));
187     test(L"right-brace", std::wstring(L"}"));
188     test(L"right-curly-bracket", std::wstring(L"}"));
189     test(L"tilde", std::wstring(L"~"));
190 
191     test(L"tild", std::wstring(L""));
192     test(L"ch", std::wstring(L""));
193     std::locale::global(std::locale(LOCALE_cs_CZ_ISO8859_2));
194     test(L"ch", std::wstring(L"ch"));
195     std::locale::global(std::locale("C"));
196 }
197