| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 | 50 |
| 51 using namespace v8::internal; | 51 using namespace v8::internal; |
| 52 | 52 |
| 53 | 53 |
| 54 static SmartPointer<const char> Parse(const char* input) { | 54 static SmartPointer<const char> Parse(const char* input) { |
| 55 v8::HandleScope scope; | 55 v8::HandleScope scope; |
| 56 ZoneScope zone_scope(DELETE_ON_EXIT); | 56 ZoneScope zone_scope(DELETE_ON_EXIT); |
| 57 FlatStringReader reader(CStrVector(input)); | 57 FlatStringReader reader(CStrVector(input)); |
| 58 RegExpParseResult result; | 58 RegExpParseResult result; |
| 59 CHECK(v8::internal::ParseRegExp(&reader, &result)); | 59 CHECK(v8::internal::ParseRegExp(&reader, false, &result)); |
| 60 CHECK(result.tree != NULL); | 60 CHECK(result.tree != NULL); |
| 61 CHECK(result.error.is_null()); | 61 CHECK(result.error.is_null()); |
| 62 SmartPointer<const char> output = result.tree->ToString(); | 62 SmartPointer<const char> output = result.tree->ToString(); |
| 63 return output; | 63 return output; |
| 64 } | 64 } |
| 65 | 65 |
| 66 static bool ParseEscapes(const char* input) { | 66 static bool ParseEscapes(const char* input) { |
| 67 v8::HandleScope scope; | 67 v8::HandleScope scope; |
| 68 unibrow::Utf8InputBuffer<> buffer(input, strlen(input)); | 68 unibrow::Utf8InputBuffer<> buffer(input, strlen(input)); |
| 69 ZoneScope zone_scope(DELETE_ON_EXIT); | 69 ZoneScope zone_scope(DELETE_ON_EXIT); |
| 70 FlatStringReader reader(CStrVector(input)); | 70 FlatStringReader reader(CStrVector(input)); |
| 71 RegExpParseResult result; | 71 RegExpParseResult result; |
| 72 CHECK(v8::internal::ParseRegExp(&reader, &result)); | 72 CHECK(v8::internal::ParseRegExp(&reader, false, &result)); |
| 73 CHECK(result.tree != NULL); | 73 CHECK(result.tree != NULL); |
| 74 CHECK(result.error.is_null()); | 74 CHECK(result.error.is_null()); |
| 75 return result.has_character_escapes; | 75 return result.has_character_escapes; |
| 76 } | 76 } |
| 77 | 77 |
| 78 | 78 |
| 79 #define CHECK_PARSE_EQ(input, expected) CHECK_EQ(expected, *Parse(input)) | 79 #define CHECK_PARSE_EQ(input, expected) CHECK_EQ(expected, *Parse(input)) |
| 80 #define CHECK_ESCAPES(input, has_escapes) CHECK_EQ(has_escapes, \ | 80 #define CHECK_ESCAPES(input, has_escapes) CHECK_EQ(has_escapes, \ |
| 81 ParseEscapes(input)); | 81 ParseEscapes(input)); |
| 82 | 82 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 CHECK_PARSE_EQ("{", "'{'"); | 250 CHECK_PARSE_EQ("{", "'{'"); |
| 251 CHECK_PARSE_EQ("a|", "(| 'a' %)"); | 251 CHECK_PARSE_EQ("a|", "(| 'a' %)"); |
| 252 } | 252 } |
| 253 | 253 |
| 254 static void ExpectError(const char* input, | 254 static void ExpectError(const char* input, |
| 255 const char* expected) { | 255 const char* expected) { |
| 256 v8::HandleScope scope; | 256 v8::HandleScope scope; |
| 257 ZoneScope zone_scope(DELETE_ON_EXIT); | 257 ZoneScope zone_scope(DELETE_ON_EXIT); |
| 258 FlatStringReader reader(CStrVector(input)); | 258 FlatStringReader reader(CStrVector(input)); |
| 259 RegExpParseResult result; | 259 RegExpParseResult result; |
| 260 CHECK_EQ(false, v8::internal::ParseRegExp(&reader, &result)); | 260 CHECK_EQ(false, v8::internal::ParseRegExp(&reader, false, &result)); |
| 261 CHECK(result.tree == NULL); | 261 CHECK(result.tree == NULL); |
| 262 CHECK(!result.error.is_null()); | 262 CHECK(!result.error.is_null()); |
| 263 SmartPointer<char> str = result.error->ToCString(ALLOW_NULLS); | 263 SmartPointer<char> str = result.error->ToCString(ALLOW_NULLS); |
| 264 CHECK_EQ(expected, *str); | 264 CHECK_EQ(expected, *str); |
| 265 } | 265 } |
| 266 | 266 |
| 267 | 267 |
| 268 TEST(Errors) { | 268 TEST(Errors) { |
| 269 V8::Initialize(NULL); | 269 V8::Initialize(NULL); |
| 270 const char* kEndBackslash = "\\ at end of pattern"; | 270 const char* kEndBackslash = "\\ at end of pattern"; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 TestCharacterClassEscapes('.', Dot); | 366 TestCharacterClassEscapes('.', Dot); |
| 367 TestCharacterClassEscapes('d', IsDigit); | 367 TestCharacterClassEscapes('d', IsDigit); |
| 368 TestCharacterClassEscapes('D', NotDigit); | 368 TestCharacterClassEscapes('D', NotDigit); |
| 369 TestCharacterClassEscapes('s', IsWhiteSpace); | 369 TestCharacterClassEscapes('s', IsWhiteSpace); |
| 370 TestCharacterClassEscapes('S', NotWhiteSpace); | 370 TestCharacterClassEscapes('S', NotWhiteSpace); |
| 371 TestCharacterClassEscapes('w', IsWord); | 371 TestCharacterClassEscapes('w', IsWord); |
| 372 TestCharacterClassEscapes('W', NotWord); | 372 TestCharacterClassEscapes('W', NotWord); |
| 373 } | 373 } |
| 374 | 374 |
| 375 | 375 |
| 376 static RegExpNode* Compile(const char* input) { | 376 static RegExpNode* Compile(const char* input, bool multiline) { |
| 377 FlatStringReader reader(CStrVector(input)); | 377 FlatStringReader reader(CStrVector(input)); |
| 378 RegExpParseResult result; | 378 RegExpParseResult result; |
| 379 if (!v8::internal::ParseRegExp(&reader, &result)) | 379 if (!v8::internal::ParseRegExp(&reader, multiline, &result)) |
| 380 return NULL; | 380 return NULL; |
| 381 RegExpNode* node = NULL; | 381 RegExpNode* node = NULL; |
| 382 RegExpEngine::Compile(&result, &node, false); | 382 RegExpEngine::Compile(&result, &node, false, multiline); |
| 383 return node; | 383 return node; |
| 384 } | 384 } |
| 385 | 385 |
| 386 | 386 |
| 387 static void Execute(const char* input, | 387 static void Execute(const char* input, |
| 388 const char* str, | 388 bool multiline, |
| 389 bool dot_output = false) { | 389 bool dot_output = false) { |
| 390 v8::HandleScope scope; | 390 v8::HandleScope scope; |
| 391 ZoneScope zone_scope(DELETE_ON_EXIT); | 391 ZoneScope zone_scope(DELETE_ON_EXIT); |
| 392 RegExpNode* node = Compile(input); | 392 RegExpNode* node = Compile(input, multiline); |
| 393 USE(node); | 393 USE(node); |
| 394 #ifdef DEBUG | 394 #ifdef DEBUG |
| 395 if (dot_output) { | 395 if (dot_output) { |
| 396 RegExpEngine::DotPrint(input, node); | 396 RegExpEngine::DotPrint(input, node); |
| 397 exit(0); | 397 exit(0); |
| 398 } | 398 } |
| 399 #endif // DEBUG | 399 #endif // DEBUG |
| 400 } | 400 } |
| 401 | 401 |
| 402 | 402 |
| 403 TEST(Execution) { | |
| 404 V8::Initialize(NULL); | |
| 405 Execute(".*?(?:a[bc]d|e[fg]h)", "xxxabbegh"); | |
| 406 Execute(".*?(?:a[bc]d|e[fg]h)", "xxxabbefh"); | |
| 407 Execute(".*?(?:a[bc]d|e[fg]h)", "xxxabbefd"); | |
| 408 } | |
| 409 | |
| 410 | |
| 411 class TestConfig { | 403 class TestConfig { |
| 412 public: | 404 public: |
| 413 typedef int Key; | 405 typedef int Key; |
| 414 typedef int Value; | 406 typedef int Value; |
| 415 static const int kNoKey; | 407 static const int kNoKey; |
| 416 static const int kNoValue; | 408 static const int kNoValue; |
| 417 static inline int Compare(int a, int b) { | 409 static inline int Compare(int a, int b) { |
| 418 if (a < b) | 410 if (a < b) |
| 419 return -1; | 411 return -1; |
| 420 else if (a > b) | 412 else if (a > b) |
| (...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1036 if (length > 1 || (c >= 128 && u < 128)) | 1028 if (length > 1 || (c >= 128 && u < 128)) |
| 1037 u = c; | 1029 u = c; |
| 1038 CHECK_EQ(u, canonicalize(c)); | 1030 CHECK_EQ(u, canonicalize(c)); |
| 1039 } | 1031 } |
| 1040 } | 1032 } |
| 1041 | 1033 |
| 1042 | 1034 |
| 1043 TEST(SimplePropagation) { | 1035 TEST(SimplePropagation) { |
| 1044 v8::HandleScope scope; | 1036 v8::HandleScope scope; |
| 1045 ZoneScope zone_scope(DELETE_ON_EXIT); | 1037 ZoneScope zone_scope(DELETE_ON_EXIT); |
| 1046 RegExpNode* node = Compile("(a|^b|c)"); | 1038 RegExpNode* node = Compile("(a|^b|c)", false); |
| 1047 CHECK(node->info()->determine_start); | 1039 CHECK(node->info()->determine_start); |
| 1048 } | 1040 } |
| 1049 | 1041 |
| 1050 | 1042 |
| 1051 static uc32 CanonRange(uc32 c) { | 1043 static uc32 CanonRange(uc32 c) { |
| 1052 unibrow::uchar canon[unibrow::CanonicalizationRange::kMaxWidth]; | 1044 unibrow::uchar canon[unibrow::CanonicalizationRange::kMaxWidth]; |
| 1053 int count = unibrow::CanonicalizationRange::Convert(c, '\0', canon, NULL); | 1045 int count = unibrow::CanonicalizationRange::Convert(c, '\0', canon, NULL); |
| 1054 if (count == 0) { | 1046 if (count == 0) { |
| 1055 return c; | 1047 return c; |
| 1056 } else { | 1048 } else { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1168 // Here we need to add [l-z] to complete the case independence of | 1160 // Here we need to add [l-z] to complete the case independence of |
| 1169 // [A-Za-z] but we expect [a-z] to be added since we always add a | 1161 // [A-Za-z] but we expect [a-z] to be added since we always add a |
| 1170 // whole block at a time. | 1162 // whole block at a time. |
| 1171 TestSimpleRangeCaseIndependence(CharacterRange('A', 'k'), | 1163 TestSimpleRangeCaseIndependence(CharacterRange('A', 'k'), |
| 1172 CharacterRange('a', 'z')); | 1164 CharacterRange('a', 'z')); |
| 1173 } | 1165 } |
| 1174 | 1166 |
| 1175 | 1167 |
| 1176 TEST(Graph) { | 1168 TEST(Graph) { |
| 1177 V8::Initialize(NULL); | 1169 V8::Initialize(NULL); |
| 1178 Execute("\\w+", "", true); | 1170 Execute("(?:^foo|^bar)$", false, true); |
| 1179 } | 1171 } |
| OLD | NEW |