| 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 | // <regex> |
| 10 | |
| 11 | // template <class charT> struct regex_traits; |
| 12 | |
| 13 | // bool isctype(charT c, char_class_type f) const; |
| 14 | |
| 15 | |
| 16 | #include <regex> |
| 17 | #include <cassert> |
| 18 | #include "test_macros.h" |
| 19 | |
| 20 | int main(int, char**) |
| 21 | { |
| 22 | { |
| 23 | std::regex_traits<char> t; |
| 24 | |
| 25 | std::string s("w" ); |
| 26 | assert( t.isctype('_', t.lookup_classname(s.begin(), s.end()))); |
| 27 | assert( t.isctype('a', t.lookup_classname(s.begin(), s.end()))); |
| 28 | assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end()))); |
| 29 | assert( t.isctype('5', t.lookup_classname(s.begin(), s.end()))); |
| 30 | assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end()))); |
| 31 | assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end()))); |
| 32 | assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end()))); |
| 33 | |
| 34 | s = "alnum" ; |
| 35 | assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end()))); |
| 36 | assert( t.isctype('a', t.lookup_classname(s.begin(), s.end()))); |
| 37 | assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end()))); |
| 38 | assert( t.isctype('5', t.lookup_classname(s.begin(), s.end()))); |
| 39 | assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end()))); |
| 40 | assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end()))); |
| 41 | assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end()))); |
| 42 | |
| 43 | s = "alpha" ; |
| 44 | assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end()))); |
| 45 | assert( t.isctype('a', t.lookup_classname(s.begin(), s.end()))); |
| 46 | assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end()))); |
| 47 | assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end()))); |
| 48 | assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end()))); |
| 49 | assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end()))); |
| 50 | assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end()))); |
| 51 | |
| 52 | s = "blank" ; |
| 53 | assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end()))); |
| 54 | assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end()))); |
| 55 | assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end()))); |
| 56 | assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end()))); |
| 57 | assert( t.isctype(' ', t.lookup_classname(s.begin(), s.end()))); |
| 58 | assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end()))); |
| 59 | assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end()))); |
| 60 | |
| 61 | s = "cntrl" ; |
| 62 | assert( t.isctype('\n', t.lookup_classname(s.begin(), s.end()))); |
| 63 | assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end()))); |
| 64 | assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end()))); |
| 65 | assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end()))); |
| 66 | assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end()))); |
| 67 | assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end()))); |
| 68 | assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end()))); |
| 69 | assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end()))); |
| 70 | |
| 71 | s = "digit" ; |
| 72 | assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end()))); |
| 73 | assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end()))); |
| 74 | assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end()))); |
| 75 | assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end()))); |
| 76 | assert( t.isctype('5', t.lookup_classname(s.begin(), s.end()))); |
| 77 | assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end()))); |
| 78 | assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end()))); |
| 79 | assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end()))); |
| 80 | |
| 81 | s = "graph" ; |
| 82 | assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end()))); |
| 83 | assert( t.isctype('_', t.lookup_classname(s.begin(), s.end()))); |
| 84 | assert( t.isctype('a', t.lookup_classname(s.begin(), s.end()))); |
| 85 | assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end()))); |
| 86 | assert( t.isctype('5', t.lookup_classname(s.begin(), s.end()))); |
| 87 | assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end()))); |
| 88 | assert( t.isctype('-', t.lookup_classname(s.begin(), s.end()))); |
| 89 | assert( t.isctype('@', t.lookup_classname(s.begin(), s.end()))); |
| 90 | |
| 91 | s = "lower" ; |
| 92 | assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end()))); |
| 93 | assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end()))); |
| 94 | assert( t.isctype('a', t.lookup_classname(s.begin(), s.end()))); |
| 95 | assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end()))); |
| 96 | assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end()))); |
| 97 | assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end()))); |
| 98 | assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end()))); |
| 99 | assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end()))); |
| 100 | |
| 101 | s = "print" ; |
| 102 | assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end()))); |
| 103 | assert( t.isctype('_', t.lookup_classname(s.begin(), s.end()))); |
| 104 | assert( t.isctype('a', t.lookup_classname(s.begin(), s.end()))); |
| 105 | assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end()))); |
| 106 | assert( t.isctype('5', t.lookup_classname(s.begin(), s.end()))); |
| 107 | assert( t.isctype(' ', t.lookup_classname(s.begin(), s.end()))); |
| 108 | assert( t.isctype('-', t.lookup_classname(s.begin(), s.end()))); |
| 109 | assert( t.isctype('@', t.lookup_classname(s.begin(), s.end()))); |
| 110 | |
| 111 | s = "punct" ; |
| 112 | assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end()))); |
| 113 | assert( t.isctype('_', t.lookup_classname(s.begin(), s.end()))); |
| 114 | assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end()))); |
| 115 | assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end()))); |
| 116 | assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end()))); |
| 117 | assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end()))); |
| 118 | assert( t.isctype('-', t.lookup_classname(s.begin(), s.end()))); |
| 119 | assert( t.isctype('@', t.lookup_classname(s.begin(), s.end()))); |
| 120 | |
| 121 | s = "space" ; |
| 122 | assert( t.isctype('\n', t.lookup_classname(s.begin(), s.end()))); |
| 123 | assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end()))); |
| 124 | assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end()))); |
| 125 | assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end()))); |
| 126 | assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end()))); |
| 127 | assert( t.isctype(' ', t.lookup_classname(s.begin(), s.end()))); |
| 128 | assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end()))); |
| 129 | assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end()))); |
| 130 | |
| 131 | s = "upper" ; |
| 132 | assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end()))); |
| 133 | assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end()))); |
| 134 | assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end()))); |
| 135 | assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end()))); |
| 136 | assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end()))); |
| 137 | assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end()))); |
| 138 | assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end()))); |
| 139 | assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end()))); |
| 140 | |
| 141 | s = "xdigit" ; |
| 142 | assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end()))); |
| 143 | assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end()))); |
| 144 | assert( t.isctype('a', t.lookup_classname(s.begin(), s.end()))); |
| 145 | assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end()))); |
| 146 | assert( t.isctype('5', t.lookup_classname(s.begin(), s.end()))); |
| 147 | assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end()))); |
| 148 | assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end()))); |
| 149 | assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end()))); |
| 150 | } |
| 151 | |
| 152 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 153 | { |
| 154 | std::regex_traits<wchar_t> t; |
| 155 | |
| 156 | std::wstring s(L"w" ); |
| 157 | assert( t.isctype(L'_', t.lookup_classname(s.begin(), s.end()))); |
| 158 | assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end()))); |
| 159 | assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end()))); |
| 160 | assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end()))); |
| 161 | assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end()))); |
| 162 | assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end()))); |
| 163 | assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end()))); |
| 164 | |
| 165 | s = L"alnum" ; |
| 166 | assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end()))); |
| 167 | assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end()))); |
| 168 | assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end()))); |
| 169 | assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end()))); |
| 170 | assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end()))); |
| 171 | assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end()))); |
| 172 | assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end()))); |
| 173 | |
| 174 | s = L"alpha" ; |
| 175 | assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end()))); |
| 176 | assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end()))); |
| 177 | assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end()))); |
| 178 | assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end()))); |
| 179 | assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end()))); |
| 180 | assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end()))); |
| 181 | assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end()))); |
| 182 | |
| 183 | s = L"blank" ; |
| 184 | assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end()))); |
| 185 | assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end()))); |
| 186 | assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end()))); |
| 187 | assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end()))); |
| 188 | assert( t.isctype(L' ', t.lookup_classname(s.begin(), s.end()))); |
| 189 | assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end()))); |
| 190 | assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end()))); |
| 191 | |
| 192 | s = L"cntrl" ; |
| 193 | assert( t.isctype(L'\n', t.lookup_classname(s.begin(), s.end()))); |
| 194 | assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end()))); |
| 195 | assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end()))); |
| 196 | assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end()))); |
| 197 | assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end()))); |
| 198 | assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end()))); |
| 199 | assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end()))); |
| 200 | assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end()))); |
| 201 | |
| 202 | s = L"digit" ; |
| 203 | assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end()))); |
| 204 | assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end()))); |
| 205 | assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end()))); |
| 206 | assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end()))); |
| 207 | assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end()))); |
| 208 | assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end()))); |
| 209 | assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end()))); |
| 210 | assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end()))); |
| 211 | |
| 212 | s = L"graph" ; |
| 213 | assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end()))); |
| 214 | assert( t.isctype(L'_', t.lookup_classname(s.begin(), s.end()))); |
| 215 | assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end()))); |
| 216 | assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end()))); |
| 217 | assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end()))); |
| 218 | assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end()))); |
| 219 | assert( t.isctype(L'-', t.lookup_classname(s.begin(), s.end()))); |
| 220 | assert( t.isctype(L'@', t.lookup_classname(s.begin(), s.end()))); |
| 221 | |
| 222 | s = L"lower" ; |
| 223 | assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end()))); |
| 224 | assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end()))); |
| 225 | assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end()))); |
| 226 | assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end()))); |
| 227 | assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end()))); |
| 228 | assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end()))); |
| 229 | assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end()))); |
| 230 | assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end()))); |
| 231 | |
| 232 | s = L"print" ; |
| 233 | assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end()))); |
| 234 | assert( t.isctype(L'_', t.lookup_classname(s.begin(), s.end()))); |
| 235 | assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end()))); |
| 236 | assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end()))); |
| 237 | assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end()))); |
| 238 | assert( t.isctype(L' ', t.lookup_classname(s.begin(), s.end()))); |
| 239 | assert( t.isctype(L'-', t.lookup_classname(s.begin(), s.end()))); |
| 240 | assert( t.isctype(L'@', t.lookup_classname(s.begin(), s.end()))); |
| 241 | |
| 242 | s = L"punct" ; |
| 243 | assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end()))); |
| 244 | assert( t.isctype(L'_', t.lookup_classname(s.begin(), s.end()))); |
| 245 | assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end()))); |
| 246 | assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end()))); |
| 247 | assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end()))); |
| 248 | assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end()))); |
| 249 | assert( t.isctype(L'-', t.lookup_classname(s.begin(), s.end()))); |
| 250 | assert( t.isctype(L'@', t.lookup_classname(s.begin(), s.end()))); |
| 251 | |
| 252 | s = L"space" ; |
| 253 | assert( t.isctype(L'\n', t.lookup_classname(s.begin(), s.end()))); |
| 254 | assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end()))); |
| 255 | assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end()))); |
| 256 | assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end()))); |
| 257 | assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end()))); |
| 258 | assert( t.isctype(L' ', t.lookup_classname(s.begin(), s.end()))); |
| 259 | assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end()))); |
| 260 | assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end()))); |
| 261 | |
| 262 | s = L"upper" ; |
| 263 | assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end()))); |
| 264 | assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end()))); |
| 265 | assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end()))); |
| 266 | assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end()))); |
| 267 | assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end()))); |
| 268 | assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end()))); |
| 269 | assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end()))); |
| 270 | assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end()))); |
| 271 | |
| 272 | s = L"xdigit" ; |
| 273 | assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end()))); |
| 274 | assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end()))); |
| 275 | assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end()))); |
| 276 | assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end()))); |
| 277 | assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end()))); |
| 278 | assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end()))); |
| 279 | assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end()))); |
| 280 | assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end()))); |
| 281 | } |
| 282 | #endif // TEST_HAS_NO_WIDE_CHARACTERS |
| 283 | |
| 284 | return 0; |
| 285 | } |
| 286 | |