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