| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 static bool IsDigit(uc16 c) { | 442 static bool IsDigit(uc16 c) { |
| 443 return ('0' <= c && c <= '9'); | 443 return ('0' <= c && c <= '9'); |
| 444 } | 444 } |
| 445 | 445 |
| 446 | 446 |
| 447 static bool NotDigit(uc16 c) { | 447 static bool NotDigit(uc16 c) { |
| 448 return !IsDigit(c); | 448 return !IsDigit(c); |
| 449 } | 449 } |
| 450 | 450 |
| 451 | 451 |
| 452 static bool IsWhiteSpace(uc16 c) { | 452 static bool IsWhiteSpaceOrLineTerminator(uc16 c) { |
| 453 switch (c) { | 453 // According to ECMA 5.1, 15.10.2.12 the CharacterClassEscape \s includes |
| 454 case 0x09: | 454 // WhiteSpace (7.2) and LineTerminator (7.3) values. |
| 455 case 0x0A: | 455 return v8::internal::WhiteSpaceOrLineTerminator::Is(c); |
| 456 case 0x0B: | |
| 457 case 0x0C: | |
| 458 case 0x0d: | |
| 459 case 0x20: | |
| 460 case 0xA0: | |
| 461 case 0x2028: | |
| 462 case 0x2029: | |
| 463 case 0xFEFF: | |
| 464 return true; | |
| 465 default: | |
| 466 return unibrow::Space::Is(c); | |
| 467 } | |
| 468 } | 456 } |
| 469 | 457 |
| 470 | 458 |
| 471 static bool NotWhiteSpace(uc16 c) { | 459 static bool NotWhiteSpaceNorLineTermiantor(uc16 c) { |
| 472 return !IsWhiteSpace(c); | 460 return !IsWhiteSpaceOrLineTerminator(c); |
| 473 } | 461 } |
| 474 | 462 |
| 475 | 463 |
| 476 static bool NotWord(uc16 c) { | 464 static bool NotWord(uc16 c) { |
| 477 return !IsRegExpWord(c); | 465 return !IsRegExpWord(c); |
| 478 } | 466 } |
| 479 | 467 |
| 480 | 468 |
| 481 static void TestCharacterClassEscapes(uc16 c, bool (pred)(uc16 c)) { | 469 static void TestCharacterClassEscapes(uc16 c, bool (pred)(uc16 c)) { |
| 482 Zone zone(CcTest::i_isolate()); | 470 Zone zone(CcTest::i_isolate()); |
| 483 ZoneList<CharacterRange>* ranges = | 471 ZoneList<CharacterRange>* ranges = |
| 484 new(&zone) ZoneList<CharacterRange>(2, &zone); | 472 new(&zone) ZoneList<CharacterRange>(2, &zone); |
| 485 CharacterRange::AddClassEscape(c, ranges, &zone); | 473 CharacterRange::AddClassEscape(c, ranges, &zone); |
| 486 for (unsigned i = 0; i < (1 << 16); i++) { | 474 for (unsigned i = 0; i < (1 << 16); i++) { |
| 487 bool in_class = false; | 475 bool in_class = false; |
| 488 for (int j = 0; !in_class && j < ranges->length(); j++) { | 476 for (int j = 0; !in_class && j < ranges->length(); j++) { |
| 489 CharacterRange& range = ranges->at(j); | 477 CharacterRange& range = ranges->at(j); |
| 490 in_class = (range.from() <= i && i <= range.to()); | 478 in_class = (range.from() <= i && i <= range.to()); |
| 491 } | 479 } |
| 492 CHECK_EQ(pred(i), in_class); | 480 CHECK_EQ(pred(i), in_class); |
| 493 } | 481 } |
| 494 } | 482 } |
| 495 | 483 |
| 496 | 484 |
| 497 TEST(CharacterClassEscapes) { | 485 TEST(CharacterClassEscapes) { |
| 498 v8::internal::V8::Initialize(NULL); | 486 v8::internal::V8::Initialize(NULL); |
| 499 TestCharacterClassEscapes('.', IsRegExpNewline); | 487 TestCharacterClassEscapes('.', IsRegExpNewline); |
| 500 TestCharacterClassEscapes('d', IsDigit); | 488 TestCharacterClassEscapes('d', IsDigit); |
| 501 TestCharacterClassEscapes('D', NotDigit); | 489 TestCharacterClassEscapes('D', NotDigit); |
| 502 TestCharacterClassEscapes('s', IsWhiteSpace); | 490 TestCharacterClassEscapes('s', IsWhiteSpaceOrLineTerminator); |
| 503 TestCharacterClassEscapes('S', NotWhiteSpace); | 491 TestCharacterClassEscapes('S', NotWhiteSpaceNorLineTermiantor); |
| 504 TestCharacterClassEscapes('w', IsRegExpWord); | 492 TestCharacterClassEscapes('w', IsRegExpWord); |
| 505 TestCharacterClassEscapes('W', NotWord); | 493 TestCharacterClassEscapes('W', NotWord); |
| 506 } | 494 } |
| 507 | 495 |
| 508 | 496 |
| 509 static RegExpNode* Compile(const char* input, | 497 static RegExpNode* Compile(const char* input, |
| 510 bool multiline, | 498 bool multiline, |
| 511 bool is_ascii, | 499 bool is_ascii, |
| 512 Zone* zone) { | 500 Zone* zone) { |
| 513 V8::Initialize(NULL); | 501 V8::Initialize(NULL); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 537 bool multiline, | 525 bool multiline, |
| 538 bool is_ascii, | 526 bool is_ascii, |
| 539 bool dot_output = false) { | 527 bool dot_output = false) { |
| 540 v8::HandleScope scope(CcTest::isolate()); | 528 v8::HandleScope scope(CcTest::isolate()); |
| 541 Zone zone(CcTest::i_isolate()); | 529 Zone zone(CcTest::i_isolate()); |
| 542 RegExpNode* node = Compile(input, multiline, is_ascii, &zone); | 530 RegExpNode* node = Compile(input, multiline, is_ascii, &zone); |
| 543 USE(node); | 531 USE(node); |
| 544 #ifdef DEBUG | 532 #ifdef DEBUG |
| 545 if (dot_output) { | 533 if (dot_output) { |
| 546 RegExpEngine::DotPrint(input, node, false); | 534 RegExpEngine::DotPrint(input, node, false); |
| 547 exit(0); | |
| 548 } | 535 } |
| 549 #endif // DEBUG | 536 #endif // DEBUG |
| 550 } | 537 } |
| 551 | 538 |
| 552 | 539 |
| 553 class TestConfig { | 540 class TestConfig { |
| 554 public: | 541 public: |
| 555 typedef int Key; | 542 typedef int Key; |
| 556 typedef int Value; | 543 typedef int Value; |
| 557 static const int kNoKey; | 544 static const int kNoKey; |
| (...skipping 1258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1816 ZoneList<CharacterRange> first_only(4, &zone); | 1803 ZoneList<CharacterRange> first_only(4, &zone); |
| 1817 ZoneList<CharacterRange> second_only(4, &zone); | 1804 ZoneList<CharacterRange> second_only(4, &zone); |
| 1818 ZoneList<CharacterRange> both(4, &zone); | 1805 ZoneList<CharacterRange> both(4, &zone); |
| 1819 } | 1806 } |
| 1820 | 1807 |
| 1821 | 1808 |
| 1822 TEST(Graph) { | 1809 TEST(Graph) { |
| 1823 V8::Initialize(NULL); | 1810 V8::Initialize(NULL); |
| 1824 Execute("\\b\\w+\\b", false, true, true); | 1811 Execute("\\b\\w+\\b", false, true, true); |
| 1825 } | 1812 } |
| OLD | NEW |