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