Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: test/cctest/test-regexp.cc

Issue 583153002: Reland 24052 - Require V8 to be explicitly initialized before an Isolate is created (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-random-number-generator.cc ('k') | test/cctest/test-serialize.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 #include "src/x87/macro-assembler-x87.h" 78 #include "src/x87/macro-assembler-x87.h"
79 #include "src/x87/regexp-macro-assembler-x87.h" 79 #include "src/x87/regexp-macro-assembler-x87.h"
80 #endif 80 #endif
81 #endif // V8_INTERPRETED_REGEXP 81 #endif // V8_INTERPRETED_REGEXP
82 #include "test/cctest/cctest.h" 82 #include "test/cctest/cctest.h"
83 83
84 using namespace v8::internal; 84 using namespace v8::internal;
85 85
86 86
87 static bool CheckParse(const char* input) { 87 static bool CheckParse(const char* input) {
88 V8::Initialize(NULL);
89 v8::HandleScope scope(CcTest::isolate()); 88 v8::HandleScope scope(CcTest::isolate());
90 Zone zone(CcTest::i_isolate()); 89 Zone zone(CcTest::i_isolate());
91 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); 90 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input));
92 RegExpCompileData result; 91 RegExpCompileData result;
93 return v8::internal::RegExpParser::ParseRegExp( 92 return v8::internal::RegExpParser::ParseRegExp(
94 &reader, false, &result, &zone); 93 &reader, false, &result, &zone);
95 } 94 }
96 95
97 96
98 static void CheckParseEq(const char* input, const char* expected) { 97 static void CheckParseEq(const char* input, const char* expected) {
99 V8::Initialize(NULL);
100 v8::HandleScope scope(CcTest::isolate()); 98 v8::HandleScope scope(CcTest::isolate());
101 Zone zone(CcTest::i_isolate()); 99 Zone zone(CcTest::i_isolate());
102 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); 100 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input));
103 RegExpCompileData result; 101 RegExpCompileData result;
104 CHECK(v8::internal::RegExpParser::ParseRegExp( 102 CHECK(v8::internal::RegExpParser::ParseRegExp(
105 &reader, false, &result, &zone)); 103 &reader, false, &result, &zone));
106 CHECK(result.tree != NULL); 104 CHECK(result.tree != NULL);
107 CHECK(result.error.is_null()); 105 CHECK(result.error.is_null());
108 OStringStream os; 106 OStringStream os;
109 result.tree->Print(os, &zone); 107 result.tree->Print(os, &zone);
110 CHECK_EQ(expected, os.c_str()); 108 CHECK_EQ(expected, os.c_str());
111 } 109 }
112 110
113 111
114 static bool CheckSimple(const char* input) { 112 static bool CheckSimple(const char* input) {
115 V8::Initialize(NULL);
116 v8::HandleScope scope(CcTest::isolate()); 113 v8::HandleScope scope(CcTest::isolate());
117 Zone zone(CcTest::i_isolate()); 114 Zone zone(CcTest::i_isolate());
118 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); 115 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input));
119 RegExpCompileData result; 116 RegExpCompileData result;
120 CHECK(v8::internal::RegExpParser::ParseRegExp( 117 CHECK(v8::internal::RegExpParser::ParseRegExp(
121 &reader, false, &result, &zone)); 118 &reader, false, &result, &zone));
122 CHECK(result.tree != NULL); 119 CHECK(result.tree != NULL);
123 CHECK(result.error.is_null()); 120 CHECK(result.error.is_null());
124 return result.simple; 121 return result.simple;
125 } 122 }
126 123
127 struct MinMaxPair { 124 struct MinMaxPair {
128 int min_match; 125 int min_match;
129 int max_match; 126 int max_match;
130 }; 127 };
131 128
132 129
133 static MinMaxPair CheckMinMaxMatch(const char* input) { 130 static MinMaxPair CheckMinMaxMatch(const char* input) {
134 V8::Initialize(NULL);
135 v8::HandleScope scope(CcTest::isolate()); 131 v8::HandleScope scope(CcTest::isolate());
136 Zone zone(CcTest::i_isolate()); 132 Zone zone(CcTest::i_isolate());
137 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); 133 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input));
138 RegExpCompileData result; 134 RegExpCompileData result;
139 CHECK(v8::internal::RegExpParser::ParseRegExp( 135 CHECK(v8::internal::RegExpParser::ParseRegExp(
140 &reader, false, &result, &zone)); 136 &reader, false, &result, &zone));
141 CHECK(result.tree != NULL); 137 CHECK(result.tree != NULL);
142 CHECK(result.error.is_null()); 138 CHECK(result.error.is_null());
143 int min_match = result.tree->min_match(); 139 int min_match = result.tree->min_match();
144 int max_match = result.tree->max_match(); 140 int max_match = result.tree->max_match();
145 MinMaxPair pair = { min_match, max_match }; 141 MinMaxPair pair = { min_match, max_match };
146 return pair; 142 return pair;
147 } 143 }
148 144
149 145
150 #define CHECK_PARSE_ERROR(input) CHECK(!CheckParse(input)) 146 #define CHECK_PARSE_ERROR(input) CHECK(!CheckParse(input))
151 #define CHECK_SIMPLE(input, simple) CHECK_EQ(simple, CheckSimple(input)); 147 #define CHECK_SIMPLE(input, simple) CHECK_EQ(simple, CheckSimple(input));
152 #define CHECK_MIN_MAX(input, min, max) \ 148 #define CHECK_MIN_MAX(input, min, max) \
153 { MinMaxPair min_max = CheckMinMaxMatch(input); \ 149 { MinMaxPair min_max = CheckMinMaxMatch(input); \
154 CHECK_EQ(min, min_max.min_match); \ 150 CHECK_EQ(min, min_max.min_match); \
155 CHECK_EQ(max, min_max.max_match); \ 151 CHECK_EQ(max, min_max.max_match); \
156 } 152 }
157 153
158 TEST(Parser) { 154 TEST(Parser) {
159 V8::Initialize(NULL);
160
161 CHECK_PARSE_ERROR("?"); 155 CHECK_PARSE_ERROR("?");
162 156
163 CheckParseEq("abc", "'abc'"); 157 CheckParseEq("abc", "'abc'");
164 CheckParseEq("", "%"); 158 CheckParseEq("", "%");
165 CheckParseEq("abc|def", "(| 'abc' 'def')"); 159 CheckParseEq("abc|def", "(| 'abc' 'def')");
166 CheckParseEq("abc|def|ghi", "(| 'abc' 'def' 'ghi')"); 160 CheckParseEq("abc|def|ghi", "(| 'abc' 'def' 'ghi')");
167 CheckParseEq("^xxx$", "(: @^i 'xxx' @$i)"); 161 CheckParseEq("^xxx$", "(: @^i 'xxx' @$i)");
168 CheckParseEq("ab\\b\\d\\bcd", "(: 'ab' @b [0-9] @b 'cd')"); 162 CheckParseEq("ab\\b\\d\\bcd", "(: 'ab' @b [0-9] @b 'cd')");
169 CheckParseEq("\\w|\\d", "(| [0-9 A-Z _ a-z] [0-9])"); 163 CheckParseEq("\\w|\\d", "(| [0-9 A-Z _ a-z] [0-9])");
170 CheckParseEq("a*", "(# 0 - g 'a')"); 164 CheckParseEq("a*", "(# 0 - g 'a')");
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 394
401 TEST(ParserRegression) { 395 TEST(ParserRegression) {
402 CheckParseEq("[A-Z$-][x]", "(! [A-Z $ -] [x])"); 396 CheckParseEq("[A-Z$-][x]", "(! [A-Z $ -] [x])");
403 CheckParseEq("a{3,4*}", "(: 'a{3,' (# 0 - g '4') '}')"); 397 CheckParseEq("a{3,4*}", "(: 'a{3,' (# 0 - g '4') '}')");
404 CheckParseEq("{", "'{'"); 398 CheckParseEq("{", "'{'");
405 CheckParseEq("a|", "(| 'a' %)"); 399 CheckParseEq("a|", "(| 'a' %)");
406 } 400 }
407 401
408 static void ExpectError(const char* input, 402 static void ExpectError(const char* input,
409 const char* expected) { 403 const char* expected) {
410 V8::Initialize(NULL);
411 v8::HandleScope scope(CcTest::isolate()); 404 v8::HandleScope scope(CcTest::isolate());
412 Zone zone(CcTest::i_isolate()); 405 Zone zone(CcTest::i_isolate());
413 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); 406 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input));
414 RegExpCompileData result; 407 RegExpCompileData result;
415 CHECK(!v8::internal::RegExpParser::ParseRegExp( 408 CHECK(!v8::internal::RegExpParser::ParseRegExp(
416 &reader, false, &result, &zone)); 409 &reader, false, &result, &zone));
417 CHECK(result.tree == NULL); 410 CHECK(result.tree == NULL);
418 CHECK(!result.error.is_null()); 411 CHECK(!result.error.is_null());
419 SmartArrayPointer<char> str = result.error->ToCString(ALLOW_NULLS); 412 SmartArrayPointer<char> str = result.error->ToCString(ALLOW_NULLS);
420 CHECK_EQ(expected, str.get()); 413 CHECK_EQ(expected, str.get());
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 for (int j = 0; !in_class && j < ranges->length(); j++) { 480 for (int j = 0; !in_class && j < ranges->length(); j++) {
488 CharacterRange& range = ranges->at(j); 481 CharacterRange& range = ranges->at(j);
489 in_class = (range.from() <= i && i <= range.to()); 482 in_class = (range.from() <= i && i <= range.to());
490 } 483 }
491 CHECK_EQ(pred(i), in_class); 484 CHECK_EQ(pred(i), in_class);
492 } 485 }
493 } 486 }
494 487
495 488
496 TEST(CharacterClassEscapes) { 489 TEST(CharacterClassEscapes) {
497 v8::internal::V8::Initialize(NULL);
498 TestCharacterClassEscapes('.', IsRegExpNewline); 490 TestCharacterClassEscapes('.', IsRegExpNewline);
499 TestCharacterClassEscapes('d', IsDigit); 491 TestCharacterClassEscapes('d', IsDigit);
500 TestCharacterClassEscapes('D', NotDigit); 492 TestCharacterClassEscapes('D', NotDigit);
501 TestCharacterClassEscapes('s', IsWhiteSpaceOrLineTerminator); 493 TestCharacterClassEscapes('s', IsWhiteSpaceOrLineTerminator);
502 TestCharacterClassEscapes('S', NotWhiteSpaceNorLineTermiantor); 494 TestCharacterClassEscapes('S', NotWhiteSpaceNorLineTermiantor);
503 TestCharacterClassEscapes('w', IsRegExpWord); 495 TestCharacterClassEscapes('w', IsRegExpWord);
504 TestCharacterClassEscapes('W', NotWord); 496 TestCharacterClassEscapes('W', NotWord);
505 } 497 }
506 498
507 499
508 static RegExpNode* Compile(const char* input, bool multiline, bool is_one_byte, 500 static RegExpNode* Compile(const char* input, bool multiline, bool is_one_byte,
509 Zone* zone) { 501 Zone* zone) {
510 V8::Initialize(NULL);
511 Isolate* isolate = CcTest::i_isolate(); 502 Isolate* isolate = CcTest::i_isolate();
512 FlatStringReader reader(isolate, CStrVector(input)); 503 FlatStringReader reader(isolate, CStrVector(input));
513 RegExpCompileData compile_data; 504 RegExpCompileData compile_data;
514 if (!v8::internal::RegExpParser::ParseRegExp(&reader, multiline, 505 if (!v8::internal::RegExpParser::ParseRegExp(&reader, multiline,
515 &compile_data, zone)) 506 &compile_data, zone))
516 return NULL; 507 return NULL;
517 Handle<String> pattern = isolate->factory()-> 508 Handle<String> pattern = isolate->factory()->
518 NewStringFromUtf8(CStrVector(input)).ToHandleChecked(); 509 NewStringFromUtf8(CStrVector(input)).ToHandleChecked();
519 Handle<String> sample_subject = 510 Handle<String> sample_subject =
520 isolate->factory()->NewStringFromUtf8(CStrVector("")).ToHandleChecked(); 511 isolate->factory()->NewStringFromUtf8(CStrVector("")).ToHandleChecked();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 548
558 const int TestConfig::kNoKey = 0; 549 const int TestConfig::kNoKey = 0;
559 550
560 551
561 static unsigned PseudoRandom(int i, int j) { 552 static unsigned PseudoRandom(int i, int j) {
562 return ~(~((i * 781) ^ (j * 329))); 553 return ~(~((i * 781) ^ (j * 329)));
563 } 554 }
564 555
565 556
566 TEST(SplayTreeSimple) { 557 TEST(SplayTreeSimple) {
567 v8::internal::V8::Initialize(NULL);
568 static const unsigned kLimit = 1000; 558 static const unsigned kLimit = 1000;
569 Zone zone(CcTest::i_isolate()); 559 Zone zone(CcTest::i_isolate());
570 ZoneSplayTree<TestConfig> tree(&zone); 560 ZoneSplayTree<TestConfig> tree(&zone);
571 bool seen[kLimit]; 561 bool seen[kLimit];
572 for (unsigned i = 0; i < kLimit; i++) seen[i] = false; 562 for (unsigned i = 0; i < kLimit; i++) seen[i] = false;
573 #define CHECK_MAPS_EQUAL() do { \ 563 #define CHECK_MAPS_EQUAL() do { \
574 for (unsigned k = 0; k < kLimit; k++) \ 564 for (unsigned k = 0; k < kLimit; k++) \
575 CHECK_EQ(seen[k], tree.Find(k, &loc)); \ 565 CHECK_EQ(seen[k], tree.Find(k, &loc)); \
576 } while (false) 566 } while (false)
577 for (int i = 0; i < 50; i++) { 567 for (int i = 0; i < 50; i++) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 CHECK(tree.FindLeastGreaterThan(val, &loc)); 600 CHECK(tree.FindLeastGreaterThan(val, &loc));
611 CHECK_EQ(loc.key(), val); 601 CHECK_EQ(loc.key(), val);
612 break; 602 break;
613 } 603 }
614 } 604 }
615 } 605 }
616 } 606 }
617 607
618 608
619 TEST(DispatchTableConstruction) { 609 TEST(DispatchTableConstruction) {
620 v8::internal::V8::Initialize(NULL);
621 // Initialize test data. 610 // Initialize test data.
622 static const int kLimit = 1000; 611 static const int kLimit = 1000;
623 static const int kRangeCount = 8; 612 static const int kRangeCount = 8;
624 static const int kRangeSize = 16; 613 static const int kRangeSize = 16;
625 uc16 ranges[kRangeCount][2 * kRangeSize]; 614 uc16 ranges[kRangeCount][2 * kRangeSize];
626 for (int i = 0; i < kRangeCount; i++) { 615 for (int i = 0; i < kRangeCount; i++) {
627 Vector<uc16> range(ranges[i], 2 * kRangeSize); 616 Vector<uc16> range(ranges[i], 2 * kRangeSize);
628 for (int j = 0; j < 2 * kRangeSize; j++) { 617 for (int j = 0; j < 2 * kRangeSize; j++) {
629 range[j] = PseudoRandom(i + 25, j + 87) % kLimit; 618 range[j] = PseudoRandom(i + 25, j + 87) % kLimit;
630 } 619 }
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 CHECK_EQ(NativeRegExpMacroAssembler::SUCCESS, result); 1344 CHECK_EQ(NativeRegExpMacroAssembler::SUCCESS, result);
1356 CHECK_EQ(0, captures[0]); 1345 CHECK_EQ(0, captures[0]);
1357 CHECK_EQ(42, captures[1]); 1346 CHECK_EQ(42, captures[1]);
1358 1347
1359 isolate->clear_pending_exception(); 1348 isolate->clear_pending_exception();
1360 } 1349 }
1361 1350
1362 #else // V8_INTERPRETED_REGEXP 1351 #else // V8_INTERPRETED_REGEXP
1363 1352
1364 TEST(MacroAssembler) { 1353 TEST(MacroAssembler) {
1365 V8::Initialize(NULL);
1366 byte codes[1024]; 1354 byte codes[1024];
1367 Zone zone(CcTest::i_isolate()); 1355 Zone zone(CcTest::i_isolate());
1368 RegExpMacroAssemblerIrregexp m(Vector<byte>(codes, 1024), &zone); 1356 RegExpMacroAssemblerIrregexp m(Vector<byte>(codes, 1024), &zone);
1369 // ^f(o)o. 1357 // ^f(o)o.
1370 Label start, fail, backtrack; 1358 Label start, fail, backtrack;
1371 1359
1372 m.SetRegister(4, 42); 1360 m.SetRegister(4, 42);
1373 m.PushRegister(4, RegExpMacroAssembler::kNoStackLimitCheck); 1361 m.PushRegister(4, RegExpMacroAssembler::kNoStackLimitCheck);
1374 m.AdvanceRegister(4, 42); 1362 m.AdvanceRegister(4, 42);
1375 m.GoTo(&start); 1363 m.GoTo(&start);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1421 Vector<const uc16>(str2, 6)).ToHandleChecked(); 1409 Vector<const uc16>(str2, 6)).ToHandleChecked();
1422 1410
1423 CHECK(!IrregexpInterpreter::Match(isolate, array, f2_16, captures, 0)); 1411 CHECK(!IrregexpInterpreter::Match(isolate, array, f2_16, captures, 0));
1424 CHECK_EQ(42, captures[0]); 1412 CHECK_EQ(42, captures[0]);
1425 } 1413 }
1426 1414
1427 #endif // V8_INTERPRETED_REGEXP 1415 #endif // V8_INTERPRETED_REGEXP
1428 1416
1429 1417
1430 TEST(AddInverseToTable) { 1418 TEST(AddInverseToTable) {
1431 v8::internal::V8::Initialize(NULL);
1432 static const int kLimit = 1000; 1419 static const int kLimit = 1000;
1433 static const int kRangeCount = 16; 1420 static const int kRangeCount = 16;
1434 for (int t = 0; t < 10; t++) { 1421 for (int t = 0; t < 10; t++) {
1435 Zone zone(CcTest::i_isolate()); 1422 Zone zone(CcTest::i_isolate());
1436 ZoneList<CharacterRange>* ranges = 1423 ZoneList<CharacterRange>* ranges =
1437 new(&zone) ZoneList<CharacterRange>(kRangeCount, &zone); 1424 new(&zone) ZoneList<CharacterRange>(kRangeCount, &zone);
1438 for (int i = 0; i < kRangeCount; i++) { 1425 for (int i = 0; i < kRangeCount; i++) {
1439 int from = PseudoRandom(t + 87, i + 25) % kLimit; 1426 int from = PseudoRandom(t + 87, i + 25) % kLimit;
1440 int to = from + (PseudoRandom(i + 87, t + 25) % (kLimit / 20)); 1427 int to = from + (PseudoRandom(i + 87, t + 25) % (kLimit / 20));
1441 if (to > kLimit) to = kLimit; 1428 if (to > kLimit) to = kLimit;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1581 1568
1582 static void TestSimpleRangeCaseIndependence(CharacterRange input, 1569 static void TestSimpleRangeCaseIndependence(CharacterRange input,
1583 CharacterRange expected) { 1570 CharacterRange expected) {
1584 EmbeddedVector<CharacterRange, 1> vector; 1571 EmbeddedVector<CharacterRange, 1> vector;
1585 vector[0] = expected; 1572 vector[0] = expected;
1586 TestRangeCaseIndependence(input, vector); 1573 TestRangeCaseIndependence(input, vector);
1587 } 1574 }
1588 1575
1589 1576
1590 TEST(CharacterRangeCaseIndependence) { 1577 TEST(CharacterRangeCaseIndependence) {
1591 v8::internal::V8::Initialize(NULL);
1592 TestSimpleRangeCaseIndependence(CharacterRange::Singleton('a'), 1578 TestSimpleRangeCaseIndependence(CharacterRange::Singleton('a'),
1593 CharacterRange::Singleton('A')); 1579 CharacterRange::Singleton('A'));
1594 TestSimpleRangeCaseIndependence(CharacterRange::Singleton('z'), 1580 TestSimpleRangeCaseIndependence(CharacterRange::Singleton('z'),
1595 CharacterRange::Singleton('Z')); 1581 CharacterRange::Singleton('Z'));
1596 TestSimpleRangeCaseIndependence(CharacterRange('a', 'z'), 1582 TestSimpleRangeCaseIndependence(CharacterRange('a', 'z'),
1597 CharacterRange('A', 'Z')); 1583 CharacterRange('A', 'Z'));
1598 TestSimpleRangeCaseIndependence(CharacterRange('c', 'f'), 1584 TestSimpleRangeCaseIndependence(CharacterRange('c', 'f'),
1599 CharacterRange('C', 'F')); 1585 CharacterRange('C', 'F'));
1600 TestSimpleRangeCaseIndependence(CharacterRange('a', 'b'), 1586 TestSimpleRangeCaseIndependence(CharacterRange('a', 'b'),
1601 CharacterRange('A', 'B')); 1587 CharacterRange('A', 'B'));
(...skipping 21 matching lines...) Expand all
1623 for (int i = 0; i < ranges->length(); i++) { 1609 for (int i = 0; i < ranges->length(); i++) {
1624 CharacterRange range = ranges->at(i); 1610 CharacterRange range = ranges->at(i);
1625 if (range.from() <= c && c <= range.to()) 1611 if (range.from() <= c && c <= range.to())
1626 return true; 1612 return true;
1627 } 1613 }
1628 return false; 1614 return false;
1629 } 1615 }
1630 1616
1631 1617
1632 TEST(CharClassDifference) { 1618 TEST(CharClassDifference) {
1633 v8::internal::V8::Initialize(NULL);
1634 Zone zone(CcTest::i_isolate()); 1619 Zone zone(CcTest::i_isolate());
1635 ZoneList<CharacterRange>* base = 1620 ZoneList<CharacterRange>* base =
1636 new(&zone) ZoneList<CharacterRange>(1, &zone); 1621 new(&zone) ZoneList<CharacterRange>(1, &zone);
1637 base->Add(CharacterRange::Everything(), &zone); 1622 base->Add(CharacterRange::Everything(), &zone);
1638 Vector<const int> overlay = CharacterRange::GetWordBounds(); 1623 Vector<const int> overlay = CharacterRange::GetWordBounds();
1639 ZoneList<CharacterRange>* included = NULL; 1624 ZoneList<CharacterRange>* included = NULL;
1640 ZoneList<CharacterRange>* excluded = NULL; 1625 ZoneList<CharacterRange>* excluded = NULL;
1641 CharacterRange::Split(base, overlay, &included, &excluded, &zone); 1626 CharacterRange::Split(base, overlay, &included, &excluded, &zone);
1642 for (int i = 0; i < (1 << 16); i++) { 1627 for (int i = 0; i < (1 << 16); i++) {
1643 bool in_base = InClass(i, base); 1628 bool in_base = InClass(i, base);
1644 if (in_base) { 1629 if (in_base) {
1645 bool in_overlay = false; 1630 bool in_overlay = false;
1646 for (int j = 0; !in_overlay && j < overlay.length(); j += 2) { 1631 for (int j = 0; !in_overlay && j < overlay.length(); j += 2) {
1647 if (overlay[j] <= i && i < overlay[j+1]) 1632 if (overlay[j] <= i && i < overlay[j+1])
1648 in_overlay = true; 1633 in_overlay = true;
1649 } 1634 }
1650 CHECK_EQ(in_overlay, InClass(i, included)); 1635 CHECK_EQ(in_overlay, InClass(i, included));
1651 CHECK_EQ(!in_overlay, InClass(i, excluded)); 1636 CHECK_EQ(!in_overlay, InClass(i, excluded));
1652 } else { 1637 } else {
1653 CHECK(!InClass(i, included)); 1638 CHECK(!InClass(i, included));
1654 CHECK(!InClass(i, excluded)); 1639 CHECK(!InClass(i, excluded));
1655 } 1640 }
1656 } 1641 }
1657 } 1642 }
1658 1643
1659 1644
1660 TEST(CanonicalizeCharacterSets) { 1645 TEST(CanonicalizeCharacterSets) {
1661 v8::internal::V8::Initialize(NULL);
1662 Zone zone(CcTest::i_isolate()); 1646 Zone zone(CcTest::i_isolate());
1663 ZoneList<CharacterRange>* list = 1647 ZoneList<CharacterRange>* list =
1664 new(&zone) ZoneList<CharacterRange>(4, &zone); 1648 new(&zone) ZoneList<CharacterRange>(4, &zone);
1665 CharacterSet set(list); 1649 CharacterSet set(list);
1666 1650
1667 list->Add(CharacterRange(10, 20), &zone); 1651 list->Add(CharacterRange(10, 20), &zone);
1668 list->Add(CharacterRange(30, 40), &zone); 1652 list->Add(CharacterRange(30, 40), &zone);
1669 list->Add(CharacterRange(50, 60), &zone); 1653 list->Add(CharacterRange(50, 60), &zone);
1670 set.Canonicalize(); 1654 set.Canonicalize();
1671 DCHECK_EQ(3, list->length()); 1655 DCHECK_EQ(3, list->length());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1713 list->Add(CharacterRange(21, 30), &zone); 1697 list->Add(CharacterRange(21, 30), &zone);
1714 list->Add(CharacterRange(20, 20), &zone); 1698 list->Add(CharacterRange(20, 20), &zone);
1715 set.Canonicalize(); 1699 set.Canonicalize();
1716 DCHECK_EQ(1, list->length()); 1700 DCHECK_EQ(1, list->length());
1717 DCHECK_EQ(10, list->at(0).from()); 1701 DCHECK_EQ(10, list->at(0).from());
1718 DCHECK_EQ(30, list->at(0).to()); 1702 DCHECK_EQ(30, list->at(0).to());
1719 } 1703 }
1720 1704
1721 1705
1722 TEST(CharacterRangeMerge) { 1706 TEST(CharacterRangeMerge) {
1723 v8::internal::V8::Initialize(NULL);
1724 Zone zone(CcTest::i_isolate()); 1707 Zone zone(CcTest::i_isolate());
1725 ZoneList<CharacterRange> l1(4, &zone); 1708 ZoneList<CharacterRange> l1(4, &zone);
1726 ZoneList<CharacterRange> l2(4, &zone); 1709 ZoneList<CharacterRange> l2(4, &zone);
1727 // Create all combinations of intersections of ranges, both singletons and 1710 // Create all combinations of intersections of ranges, both singletons and
1728 // longer. 1711 // longer.
1729 1712
1730 int offset = 0; 1713 int offset = 0;
1731 1714
1732 // The five kinds of singleton intersections: 1715 // The five kinds of singleton intersections:
1733 // X 1716 // X
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1801 DCHECK(CharacterRange::IsCanonical(&l1)); 1784 DCHECK(CharacterRange::IsCanonical(&l1));
1802 DCHECK(CharacterRange::IsCanonical(&l2)); 1785 DCHECK(CharacterRange::IsCanonical(&l2));
1803 1786
1804 ZoneList<CharacterRange> first_only(4, &zone); 1787 ZoneList<CharacterRange> first_only(4, &zone);
1805 ZoneList<CharacterRange> second_only(4, &zone); 1788 ZoneList<CharacterRange> second_only(4, &zone);
1806 ZoneList<CharacterRange> both(4, &zone); 1789 ZoneList<CharacterRange> both(4, &zone);
1807 } 1790 }
1808 1791
1809 1792
1810 TEST(Graph) { 1793 TEST(Graph) {
1811 V8::Initialize(NULL);
1812 Execute("\\b\\w+\\b", false, true, true); 1794 Execute("\\b\\w+\\b", false, true, true);
1813 } 1795 }
OLDNEW
« no previous file with comments | « test/cctest/test-random-number-generator.cc ('k') | test/cctest/test-serialize.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698