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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 v8::HandleScope scope(CcTest::isolate()); | 102 v8::HandleScope scope(CcTest::isolate()); |
103 Zone zone; | 103 Zone zone; |
104 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); | 104 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); |
105 RegExpCompileData result; | 105 RegExpCompileData result; |
106 CHECK(v8::internal::RegExpParser::ParseRegExp( | 106 CHECK(v8::internal::RegExpParser::ParseRegExp( |
107 CcTest::i_isolate(), &zone, &reader, false, false, &result)); | 107 CcTest::i_isolate(), &zone, &reader, false, false, &result)); |
108 CHECK(result.tree != NULL); | 108 CHECK(result.tree != NULL); |
109 CHECK(result.error.is_null()); | 109 CHECK(result.error.is_null()); |
110 std::ostringstream os; | 110 std::ostringstream os; |
111 result.tree->Print(os, &zone); | 111 result.tree->Print(os, &zone); |
112 CHECK_EQ(0, strcmp(expected, os.str().c_str())); | 112 CHECK_EQ(expected, os.str().c_str()); |
113 } | 113 } |
114 | 114 |
115 | 115 |
116 static bool CheckSimple(const char* input) { | 116 static bool CheckSimple(const char* input) { |
117 v8::HandleScope scope(CcTest::isolate()); | 117 v8::HandleScope scope(CcTest::isolate()); |
118 Zone zone; | 118 Zone zone; |
119 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); | 119 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); |
120 RegExpCompileData result; | 120 RegExpCompileData result; |
121 CHECK(v8::internal::RegExpParser::ParseRegExp( | 121 CHECK(v8::internal::RegExpParser::ParseRegExp( |
122 CcTest::i_isolate(), &zone, &reader, false, false, &result)); | 122 CcTest::i_isolate(), &zone, &reader, false, false, &result)); |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 const char* expected) { | 407 const char* expected) { |
408 v8::HandleScope scope(CcTest::isolate()); | 408 v8::HandleScope scope(CcTest::isolate()); |
409 Zone zone; | 409 Zone zone; |
410 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); | 410 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); |
411 RegExpCompileData result; | 411 RegExpCompileData result; |
412 CHECK(!v8::internal::RegExpParser::ParseRegExp( | 412 CHECK(!v8::internal::RegExpParser::ParseRegExp( |
413 CcTest::i_isolate(), &zone, &reader, false, false, &result)); | 413 CcTest::i_isolate(), &zone, &reader, false, false, &result)); |
414 CHECK(result.tree == NULL); | 414 CHECK(result.tree == NULL); |
415 CHECK(!result.error.is_null()); | 415 CHECK(!result.error.is_null()); |
416 SmartArrayPointer<char> str = result.error->ToCString(ALLOW_NULLS); | 416 SmartArrayPointer<char> str = result.error->ToCString(ALLOW_NULLS); |
417 CHECK_EQ(0, strcmp(expected, str.get())); | 417 CHECK_EQ(expected, str.get()); |
418 } | 418 } |
419 | 419 |
420 | 420 |
421 TEST(Errors) { | 421 TEST(Errors) { |
422 const char* kEndBackslash = "\\ at end of pattern"; | 422 const char* kEndBackslash = "\\ at end of pattern"; |
423 ExpectError("\\", kEndBackslash); | 423 ExpectError("\\", kEndBackslash); |
424 const char* kUnterminatedGroup = "Unterminated group"; | 424 const char* kUnterminatedGroup = "Unterminated group"; |
425 ExpectError("(foo", kUnterminatedGroup); | 425 ExpectError("(foo", kUnterminatedGroup); |
426 const char* kInvalidGroup = "Invalid group"; | 426 const char* kInvalidGroup = "Invalid group"; |
427 ExpectError("(?", kInvalidGroup); | 427 ExpectError("(?", kInvalidGroup); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 Zone zone; | 565 Zone zone; |
566 ZoneSplayTree<TestConfig> tree(&zone); | 566 ZoneSplayTree<TestConfig> tree(&zone); |
567 bool seen[kLimit]; | 567 bool seen[kLimit]; |
568 for (unsigned i = 0; i < kLimit; i++) seen[i] = false; | 568 for (unsigned i = 0; i < kLimit; i++) seen[i] = false; |
569 #define CHECK_MAPS_EQUAL() do { \ | 569 #define CHECK_MAPS_EQUAL() do { \ |
570 for (unsigned k = 0; k < kLimit; k++) \ | 570 for (unsigned k = 0; k < kLimit; k++) \ |
571 CHECK_EQ(seen[k], tree.Find(k, &loc)); \ | 571 CHECK_EQ(seen[k], tree.Find(k, &loc)); \ |
572 } while (false) | 572 } while (false) |
573 for (int i = 0; i < 50; i++) { | 573 for (int i = 0; i < 50; i++) { |
574 for (int j = 0; j < 50; j++) { | 574 for (int j = 0; j < 50; j++) { |
575 int next = PseudoRandom(i, j) % kLimit; | 575 unsigned next = PseudoRandom(i, j) % kLimit; |
576 if (seen[next]) { | 576 if (seen[next]) { |
577 // We've already seen this one. Check the value and remove | 577 // We've already seen this one. Check the value and remove |
578 // it. | 578 // it. |
579 ZoneSplayTree<TestConfig>::Locator loc; | 579 ZoneSplayTree<TestConfig>::Locator loc; |
580 CHECK(tree.Find(next, &loc)); | 580 CHECK(tree.Find(next, &loc)); |
581 CHECK_EQ(next, loc.key()); | 581 CHECK_EQ(next, loc.key()); |
582 CHECK_EQ(3 * next, loc.value()); | 582 CHECK_EQ(3 * next, loc.value()); |
583 tree.Remove(next); | 583 tree.Remove(next); |
584 seen[next] = false; | 584 seen[next] = false; |
585 CHECK_MAPS_EQUAL(); | 585 CHECK_MAPS_EQUAL(); |
(...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1480 return c; | 1480 return c; |
1481 } else { | 1481 } else { |
1482 CHECK_EQ(1, count); | 1482 CHECK_EQ(1, count); |
1483 return canon[0]; | 1483 return canon[0]; |
1484 } | 1484 } |
1485 } | 1485 } |
1486 | 1486 |
1487 | 1487 |
1488 TEST(LatinCanonicalize) { | 1488 TEST(LatinCanonicalize) { |
1489 unibrow::Mapping<unibrow::Ecma262UnCanonicalize> un_canonicalize; | 1489 unibrow::Mapping<unibrow::Ecma262UnCanonicalize> un_canonicalize; |
1490 for (unibrow::uchar lower = 'a'; lower <= 'z'; lower++) { | 1490 for (char lower = 'a'; lower <= 'z'; lower++) { |
1491 unibrow::uchar upper = lower + ('A' - 'a'); | 1491 char upper = lower + ('A' - 'a'); |
1492 CHECK_EQ(canonicalize(lower), canonicalize(upper)); | 1492 CHECK_EQ(canonicalize(lower), canonicalize(upper)); |
1493 unibrow::uchar uncanon[unibrow::Ecma262UnCanonicalize::kMaxWidth]; | 1493 unibrow::uchar uncanon[unibrow::Ecma262UnCanonicalize::kMaxWidth]; |
1494 int length = un_canonicalize.get(lower, '\0', uncanon); | 1494 int length = un_canonicalize.get(lower, '\0', uncanon); |
1495 CHECK_EQ(2, length); | 1495 CHECK_EQ(2, length); |
1496 CHECK_EQ(upper, uncanon[0]); | 1496 CHECK_EQ(upper, uncanon[0]); |
1497 CHECK_EQ(lower, uncanon[1]); | 1497 CHECK_EQ(lower, uncanon[1]); |
1498 } | 1498 } |
1499 for (uc32 c = 128; c < (1 << 21); c++) | 1499 for (uc32 c = 128; c < (1 << 21); c++) |
1500 CHECK_GE(canonicalize(c), 128); | 1500 CHECK_GE(canonicalize(c), 128); |
1501 unibrow::Mapping<unibrow::ToUppercase> to_upper; | 1501 unibrow::Mapping<unibrow::ToUppercase> to_upper; |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1808 | 1808 |
1809 ZoneList<CharacterRange> first_only(4, &zone); | 1809 ZoneList<CharacterRange> first_only(4, &zone); |
1810 ZoneList<CharacterRange> second_only(4, &zone); | 1810 ZoneList<CharacterRange> second_only(4, &zone); |
1811 ZoneList<CharacterRange> both(4, &zone); | 1811 ZoneList<CharacterRange> both(4, &zone); |
1812 } | 1812 } |
1813 | 1813 |
1814 | 1814 |
1815 TEST(Graph) { | 1815 TEST(Graph) { |
1816 Execute("\\b\\w+\\b", false, true, true); | 1816 Execute("\\b\\w+\\b", false, true, true); |
1817 } | 1817 } |
OLD | NEW |