| OLD | NEW |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 unibrow::Utf8InputBuffer<> buffer(input, strlen(input)); | 69 unibrow::Utf8InputBuffer<> buffer(input, strlen(input)); |
| 70 ZoneScope zone_scope(DELETE_ON_EXIT); | 70 ZoneScope zone_scope(DELETE_ON_EXIT); |
| 71 FlatStringReader reader(CStrVector(input)); | 71 FlatStringReader reader(CStrVector(input)); |
| 72 RegExpCompileData result; | 72 RegExpCompileData result; |
| 73 CHECK(v8::internal::ParseRegExp(&reader, false, &result)); | 73 CHECK(v8::internal::ParseRegExp(&reader, false, &result)); |
| 74 CHECK(result.tree != NULL); | 74 CHECK(result.tree != NULL); |
| 75 CHECK(result.error.is_null()); | 75 CHECK(result.error.is_null()); |
| 76 return result.simple; | 76 return result.simple; |
| 77 } | 77 } |
| 78 | 78 |
| 79 struct MinMaxPair { |
| 80 int min_match; |
| 81 int max_match; |
| 82 }; |
| 83 |
| 84 static MinMaxPair CheckMinMaxMatch(const char* input) { |
| 85 V8::Initialize(NULL); |
| 86 v8::HandleScope scope; |
| 87 unibrow::Utf8InputBuffer<> buffer(input, strlen(input)); |
| 88 ZoneScope zone_scope(DELETE_ON_EXIT); |
| 89 FlatStringReader reader(CStrVector(input)); |
| 90 RegExpCompileData result; |
| 91 CHECK(v8::internal::ParseRegExp(&reader, false, &result)); |
| 92 CHECK(result.tree != NULL); |
| 93 CHECK(result.error.is_null()); |
| 94 int min_match = result.tree->min_match(); |
| 95 int max_match = result.tree->max_match(); |
| 96 MinMaxPair pair = { min_match, max_match }; |
| 97 return pair; |
| 98 } |
| 99 |
| 100 |
| 79 | 101 |
| 80 #define CHECK_PARSE_EQ(input, expected) CHECK_EQ(expected, *Parse(input)) | 102 #define CHECK_PARSE_EQ(input, expected) CHECK_EQ(expected, *Parse(input)) |
| 81 #define CHECK_SIMPLE(input, simple) CHECK_EQ(simple, CheckSimple(input)); | 103 #define CHECK_SIMPLE(input, simple) CHECK_EQ(simple, CheckSimple(input)); |
| 104 #define CHECK_MIN_MAX(input, min, max) \ |
| 105 { MinMaxPair min_max = CheckMinMaxMatch(input); \ |
| 106 CHECK_EQ(min, min_max.min_match); \ |
| 107 CHECK_EQ(max, min_max.max_match); \ |
| 108 } |
| 82 | 109 |
| 83 TEST(Parser) { | 110 TEST(Parser) { |
| 84 V8::Initialize(NULL); | 111 V8::Initialize(NULL); |
| 85 CHECK_PARSE_EQ("abc", "'abc'"); | 112 CHECK_PARSE_EQ("abc", "'abc'"); |
| 86 CHECK_PARSE_EQ("", "%"); | 113 CHECK_PARSE_EQ("", "%"); |
| 87 CHECK_PARSE_EQ("abc|def", "(| 'abc' 'def')"); | 114 CHECK_PARSE_EQ("abc|def", "(| 'abc' 'def')"); |
| 88 CHECK_PARSE_EQ("abc|def|ghi", "(| 'abc' 'def' 'ghi')"); | 115 CHECK_PARSE_EQ("abc|def|ghi", "(| 'abc' 'def' 'ghi')"); |
| 89 CHECK_PARSE_EQ("^xxx$", "(: @^i 'xxx' @$i)"); | 116 CHECK_PARSE_EQ("^xxx$", "(: @^i 'xxx' @$i)"); |
| 90 CHECK_PARSE_EQ("ab\\b\\d\\bcd", "(: 'ab' @b [0-9] @b 'cd')"); | 117 CHECK_PARSE_EQ("ab\\b\\d\\bcd", "(: 'ab' @b [0-9] @b 'cd')"); |
| 91 CHECK_PARSE_EQ("\\w|\\d", "(| [0-9 A-Z _ a-z] [0-9])"); | 118 CHECK_PARSE_EQ("\\w|\\d", "(| [0-9 A-Z _ a-z] [0-9])"); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 CHECK_PARSE_EQ("a{12,", "'a{12,'"); | 271 CHECK_PARSE_EQ("a{12,", "'a{12,'"); |
| 245 CHECK_PARSE_EQ("a{12,3b", "'a{12,3b'"); | 272 CHECK_PARSE_EQ("a{12,3b", "'a{12,3b'"); |
| 246 CHECK_PARSE_EQ("{}", "'{}'"); | 273 CHECK_PARSE_EQ("{}", "'{}'"); |
| 247 CHECK_PARSE_EQ("{,}", "'{,}'"); | 274 CHECK_PARSE_EQ("{,}", "'{,}'"); |
| 248 CHECK_PARSE_EQ("{", "'{'"); | 275 CHECK_PARSE_EQ("{", "'{'"); |
| 249 CHECK_PARSE_EQ("{z}", "'{z}'"); | 276 CHECK_PARSE_EQ("{z}", "'{z}'"); |
| 250 CHECK_PARSE_EQ("{1z}", "'{1z}'"); | 277 CHECK_PARSE_EQ("{1z}", "'{1z}'"); |
| 251 CHECK_PARSE_EQ("{12z}", "'{12z}'"); | 278 CHECK_PARSE_EQ("{12z}", "'{12z}'"); |
| 252 CHECK_PARSE_EQ("{12,", "'{12,'"); | 279 CHECK_PARSE_EQ("{12,", "'{12,'"); |
| 253 CHECK_PARSE_EQ("{12,3b", "'{12,3b'"); | 280 CHECK_PARSE_EQ("{12,3b", "'{12,3b'"); |
| 281 |
| 282 CHECK_MIN_MAX("a", 1, 1); |
| 283 CHECK_MIN_MAX("abc", 3, 3); |
| 284 CHECK_MIN_MAX("a[bc]d", 3, 3); |
| 285 CHECK_MIN_MAX("a|bc", 1, 2); |
| 286 CHECK_MIN_MAX("ab|c", 1, 2); |
| 287 CHECK_MIN_MAX("a||bc", 0, 2); |
| 288 CHECK_MIN_MAX("|", 0, 0); |
| 289 CHECK_MIN_MAX("(?:ab)", 2, 2); |
| 290 CHECK_MIN_MAX("(?:ab|cde)", 2, 3); |
| 291 CHECK_MIN_MAX("(?:ab)|cde", 2, 3); |
| 292 CHECK_MIN_MAX("(ab)", 2, 2); |
| 293 CHECK_MIN_MAX("(ab|cde)", 2, 3); |
| 294 CHECK_MIN_MAX("(ab)\\1", 4, 4); |
| 295 CHECK_MIN_MAX("(ab|cde)\\1", 4, 6); |
| 296 CHECK_MIN_MAX("(?:ab)?", 0, 2); |
| 297 CHECK_MIN_MAX("(?:ab)*", 0, RegExpTree::kInfinity); |
| 298 CHECK_MIN_MAX("(?:ab)+", 2, RegExpTree::kInfinity); |
| 299 CHECK_MIN_MAX("a?", 0, 1); |
| 300 CHECK_MIN_MAX("a*", 0, RegExpTree::kInfinity); |
| 301 CHECK_MIN_MAX("a+", 1, RegExpTree::kInfinity); |
| 302 CHECK_MIN_MAX("a??", 0, 1); |
| 303 CHECK_MIN_MAX("a*?", 0, RegExpTree::kInfinity); |
| 304 CHECK_MIN_MAX("a+?", 1, RegExpTree::kInfinity); |
| 305 CHECK_MIN_MAX("(?:a?)?", 0, 1); |
| 306 CHECK_MIN_MAX("(?:a*)?", 0, RegExpTree::kInfinity); |
| 307 CHECK_MIN_MAX("(?:a+)?", 0, RegExpTree::kInfinity); |
| 308 CHECK_MIN_MAX("(?:a?)+", 0, RegExpTree::kInfinity); |
| 309 CHECK_MIN_MAX("(?:a*)+", 0, RegExpTree::kInfinity); |
| 310 CHECK_MIN_MAX("(?:a+)+", 1, RegExpTree::kInfinity); |
| 311 CHECK_MIN_MAX("(?:a?)*", 0, RegExpTree::kInfinity); |
| 312 CHECK_MIN_MAX("(?:a*)*", 0, RegExpTree::kInfinity); |
| 313 CHECK_MIN_MAX("(?:a+)*", 0, RegExpTree::kInfinity); |
| 314 CHECK_MIN_MAX("a{0}", 0, 0); |
| 315 CHECK_MIN_MAX("(?:a+){0}", 0, 0); |
| 316 CHECK_MIN_MAX("(?:a+){0,0}", 0, 0); |
| 317 CHECK_MIN_MAX("a*b", 1, RegExpTree::kInfinity); |
| 318 CHECK_MIN_MAX("a+b", 2, RegExpTree::kInfinity); |
| 319 CHECK_MIN_MAX("a*b|c", 1, RegExpTree::kInfinity); |
| 320 CHECK_MIN_MAX("a+b|c", 1, RegExpTree::kInfinity); |
| 321 CHECK_MIN_MAX("(?:a{5,1000000}){3,1000000}", 15, RegExpTree::kInfinity); |
| 322 CHECK_MIN_MAX("(?:ab){4,7}", 8, 14); |
| 323 CHECK_MIN_MAX("a\\bc", 2, 2); |
| 324 CHECK_MIN_MAX("a\\Bc", 2, 2); |
| 325 CHECK_MIN_MAX("a\\sc", 3, 3); |
| 326 CHECK_MIN_MAX("a\\Sc", 3, 3); |
| 327 CHECK_MIN_MAX("a(?=b)c", 2, 2); |
| 328 CHECK_MIN_MAX("a(?=bbb|bb)c", 2, 2); |
| 329 CHECK_MIN_MAX("a(?!bbb|bb)c", 2, 2); |
| 254 } | 330 } |
| 255 | 331 |
| 256 TEST(ParserRegression) { | 332 TEST(ParserRegression) { |
| 257 CHECK_PARSE_EQ("[A-Z$-][x]", "(! [A-Z $ -] [x])"); | 333 CHECK_PARSE_EQ("[A-Z$-][x]", "(! [A-Z $ -] [x])"); |
| 258 CHECK_PARSE_EQ("a{3,4*}", "(: 'a{3,' (# 0 - g '4') '}')"); | 334 CHECK_PARSE_EQ("a{3,4*}", "(: 'a{3,' (# 0 - g '4') '}')"); |
| 259 CHECK_PARSE_EQ("{", "'{'"); | 335 CHECK_PARSE_EQ("{", "'{'"); |
| 260 CHECK_PARSE_EQ("a|", "(| 'a' %)"); | 336 CHECK_PARSE_EQ("a|", "(| 'a' %)"); |
| 261 } | 337 } |
| 262 | 338 |
| 263 static void ExpectError(const char* input, | 339 static void ExpectError(const char* input, |
| (...skipping 1121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1385 CHECK(!InClass(i, excluded)); | 1461 CHECK(!InClass(i, excluded)); |
| 1386 } | 1462 } |
| 1387 } | 1463 } |
| 1388 } | 1464 } |
| 1389 | 1465 |
| 1390 | 1466 |
| 1391 TEST(Graph) { | 1467 TEST(Graph) { |
| 1392 V8::Initialize(NULL); | 1468 V8::Initialize(NULL); |
| 1393 Execute("\\bboy\\b", false, true, true); | 1469 Execute("\\bboy\\b", false, true, true); |
| 1394 } | 1470 } |
| OLD | NEW |