| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-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 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 CHECK(tree.FindLeastGreaterThan(val, &loc)); | 431 CHECK(tree.FindLeastGreaterThan(val, &loc)); |
| 432 CHECK_EQ(loc.key(), val); | 432 CHECK_EQ(loc.key(), val); |
| 433 break; | 433 break; |
| 434 } | 434 } |
| 435 } | 435 } |
| 436 } | 436 } |
| 437 } | 437 } |
| 438 } | 438 } |
| 439 | 439 |
| 440 | 440 |
| 441 static int CompareChars(const void* ap, const void* bp) { | |
| 442 uc16 a = *static_cast<const uc16*>(ap); | |
| 443 uc16 b = *static_cast<const uc16*>(bp); | |
| 444 if (a < b) | |
| 445 return -1; | |
| 446 else if (a > b) | |
| 447 return 1; | |
| 448 else | |
| 449 return 0; | |
| 450 } | |
| 451 | |
| 452 | |
| 453 TEST(DispatchTableConstruction) { | 441 TEST(DispatchTableConstruction) { |
| 454 // Initialize test data. | 442 // Initialize test data. |
| 455 static const int kLimit = 1000; | 443 static const int kLimit = 1000; |
| 456 static const int kRangeCount = 8; | 444 static const int kRangeCount = 8; |
| 457 static const int kRangeSize = 16; | 445 static const int kRangeSize = 16; |
| 458 uc16 ranges[kRangeCount][2 * kRangeSize]; | 446 uc16 ranges[kRangeCount][2 * kRangeSize]; |
| 459 for (int i = 0; i < kRangeCount; i++) { | 447 for (int i = 0; i < kRangeCount; i++) { |
| 460 uc16* range = ranges[i]; | 448 Vector<uc16> range(ranges[i], 2 * kRangeSize); |
| 461 for (int j = 0; j < 2 * kRangeSize; j++) { | 449 for (int j = 0; j < 2 * kRangeSize; j++) { |
| 462 range[j] = PseudoRandom(i + 25, j + 87) % kLimit; | 450 range[j] = PseudoRandom(i + 25, j + 87) % kLimit; |
| 463 } | 451 } |
| 464 qsort(range, 2 * kRangeSize, sizeof(uc16), CompareChars); | 452 range.Sort(); |
| 453 for (int j = 1; j < 2 * kRangeSize; j++) { |
| 454 CHECK(range[j-1] <= range[j]); |
| 455 } |
| 465 } | 456 } |
| 466 // Enter test data into dispatch table. | 457 // Enter test data into dispatch table. |
| 467 ZoneScope zone_scope(DELETE_ON_EXIT); | 458 ZoneScope zone_scope(DELETE_ON_EXIT); |
| 468 DispatchTable table; | 459 DispatchTable table; |
| 469 for (int i = 0; i < kRangeCount; i++) { | 460 for (int i = 0; i < kRangeCount; i++) { |
| 470 uc16* range = ranges[i]; | 461 uc16* range = ranges[i]; |
| 471 for (int j = 0; j < 2 * kRangeSize; j += 2) | 462 for (int j = 0; j < 2 * kRangeSize; j += 2) |
| 472 table.AddRange(CharacterRange(range[j], range[j + 1]), i); | 463 table.AddRange(CharacterRange(range[j], range[j + 1]), i); |
| 473 } | 464 } |
| 474 // Check that the table looks as we would expect | 465 // Check that the table looks as we would expect |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 Handle<String> f2 = | 660 Handle<String> f2 = |
| 670 Factory::NewStringFromAscii(CStrVector("barfoo")); | 661 Factory::NewStringFromAscii(CStrVector("barfoo")); |
| 671 CHECK(!Re2kInterpreter::Match(array, f2, captures, 0)); | 662 CHECK(!Re2kInterpreter::Match(array, f2, captures, 0)); |
| 672 CHECK_EQ(42, captures[0]); | 663 CHECK_EQ(42, captures[0]); |
| 673 } | 664 } |
| 674 | 665 |
| 675 | 666 |
| 676 TEST(AddInverseToTable) { | 667 TEST(AddInverseToTable) { |
| 677 static const int kLimit = 1000; | 668 static const int kLimit = 1000; |
| 678 static const int kRangeCount = 16; | 669 static const int kRangeCount = 16; |
| 679 ZoneScope zone_scope(DELETE_ON_EXIT); | 670 for (int t = 0; t < 10; t++) { |
| 680 ZoneList<CharacterRange>* range = new ZoneList<CharacterRange>(kRangeCount); | 671 ZoneScope zone_scope(DELETE_ON_EXIT); |
| 681 for (int i = 0; i < kRangeCount; i++) { | 672 ZoneList<CharacterRange>* ranges = |
| 682 int from = PseudoRandom(87, i + 25) % kLimit; | 673 new ZoneList<CharacterRange>(kRangeCount); |
| 683 int to = PseudoRandom(i + 87, 25) % (kLimit / 20); | 674 for (int i = 0; i < kRangeCount; i++) { |
| 684 if (to > kLimit) to = kLimit; | 675 int from = PseudoRandom(t + 87, i + 25) % kLimit; |
| 685 range->Add(CharacterRange(from, to)); | 676 int to = from + (PseudoRandom(i + 87, t + 25) % (kLimit / 20)); |
| 677 if (to > kLimit) to = kLimit; |
| 678 ranges->Add(CharacterRange(from, to)); |
| 679 } |
| 680 DispatchTable table; |
| 681 CharacterClassNode::AddInverseToTable(ranges, &table, 0); |
| 682 for (int i = 0; i < kLimit; i++) { |
| 683 bool is_on = false; |
| 684 for (int j = 0; !is_on && j < kRangeCount; j++) |
| 685 is_on = ranges->at(j).Contains(i); |
| 686 OutSet* set = table.Get(i); |
| 687 CHECK_EQ(is_on, set->Get(0) == false); |
| 688 } |
| 686 } | 689 } |
| 687 DispatchTable table; | |
| 688 // CharacterClassNode::AddInverseToTable(range, &table, 0); | |
| 689 } | 690 } |
| 690 | 691 |
| 691 | 692 |
| 692 TEST(Graph) { | 693 TEST(Graph) { |
| 693 Execute(".*?a", "", true); | 694 Execute(".*?[^a]|b", "", true); |
| 694 } | 695 } |
| OLD | NEW |