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

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

Issue 788043005: ES6 unicode escapes, part 2: Regexps. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: mirror regexp test Created 5 years, 11 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
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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::HandleScope scope(CcTest::isolate()); 88 v8::HandleScope scope(CcTest::isolate());
89 Zone zone(CcTest::i_isolate()); 89 Zone zone(CcTest::i_isolate());
90 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); 90 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input));
91 RegExpCompileData result; 91 RegExpCompileData result;
92 return v8::internal::RegExpParser::ParseRegExp( 92 return v8::internal::RegExpParser::ParseRegExp(&reader, false, false, &result,
93 &reader, false, &result, &zone); 93 &zone);
94 } 94 }
95 95
96 96
97 static void CheckParseEq(const char* input, const char* expected) { 97 static void CheckParseEq(const char* input, const char* expected) {
98 v8::HandleScope scope(CcTest::isolate()); 98 v8::HandleScope scope(CcTest::isolate());
99 Zone zone(CcTest::i_isolate()); 99 Zone zone(CcTest::i_isolate());
100 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); 100 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input));
101 RegExpCompileData result; 101 RegExpCompileData result;
102 CHECK(v8::internal::RegExpParser::ParseRegExp( 102 CHECK(v8::internal::RegExpParser::ParseRegExp(&reader, false, false, &result,
103 &reader, false, &result, &zone)); 103 &zone));
104 CHECK(result.tree != NULL); 104 CHECK(result.tree != NULL);
105 CHECK(result.error.is_null()); 105 CHECK(result.error.is_null());
106 std::ostringstream os; 106 std::ostringstream os;
107 result.tree->Print(os, &zone); 107 result.tree->Print(os, &zone);
108 CHECK_EQ(expected, os.str().c_str()); 108 CHECK_EQ(expected, os.str().c_str());
109 } 109 }
110 110
111 111
112 static bool CheckSimple(const char* input) { 112 static bool CheckSimple(const char* input) {
113 v8::HandleScope scope(CcTest::isolate()); 113 v8::HandleScope scope(CcTest::isolate());
114 Zone zone(CcTest::i_isolate()); 114 Zone zone(CcTest::i_isolate());
115 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); 115 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input));
116 RegExpCompileData result; 116 RegExpCompileData result;
117 CHECK(v8::internal::RegExpParser::ParseRegExp( 117 CHECK(v8::internal::RegExpParser::ParseRegExp(&reader, false, false, &result,
118 &reader, false, &result, &zone)); 118 &zone));
119 CHECK(result.tree != NULL); 119 CHECK(result.tree != NULL);
120 CHECK(result.error.is_null()); 120 CHECK(result.error.is_null());
121 return result.simple; 121 return result.simple;
122 } 122 }
123 123
124 struct MinMaxPair { 124 struct MinMaxPair {
125 int min_match; 125 int min_match;
126 int max_match; 126 int max_match;
127 }; 127 };
128 128
129 129
130 static MinMaxPair CheckMinMaxMatch(const char* input) { 130 static MinMaxPair CheckMinMaxMatch(const char* input) {
131 v8::HandleScope scope(CcTest::isolate()); 131 v8::HandleScope scope(CcTest::isolate());
132 Zone zone(CcTest::i_isolate()); 132 Zone zone(CcTest::i_isolate());
133 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); 133 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input));
134 RegExpCompileData result; 134 RegExpCompileData result;
135 CHECK(v8::internal::RegExpParser::ParseRegExp( 135 CHECK(v8::internal::RegExpParser::ParseRegExp(&reader, false, false, &result,
136 &reader, false, &result, &zone)); 136 &zone));
137 CHECK(result.tree != NULL); 137 CHECK(result.tree != NULL);
138 CHECK(result.error.is_null()); 138 CHECK(result.error.is_null());
139 int min_match = result.tree->min_match(); 139 int min_match = result.tree->min_match();
140 int max_match = result.tree->max_match(); 140 int max_match = result.tree->max_match();
141 MinMaxPair pair = { min_match, max_match }; 141 MinMaxPair pair = { min_match, max_match };
142 return pair; 142 return pair;
143 } 143 }
144 144
145 145
146 #define CHECK_PARSE_ERROR(input) CHECK(!CheckParse(input)) 146 #define CHECK_PARSE_ERROR(input) CHECK(!CheckParse(input))
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 CheckParseEq("{", "'{'"); 398 CheckParseEq("{", "'{'");
399 CheckParseEq("a|", "(| 'a' %)"); 399 CheckParseEq("a|", "(| 'a' %)");
400 } 400 }
401 401
402 static void ExpectError(const char* input, 402 static void ExpectError(const char* input,
403 const char* expected) { 403 const char* expected) {
404 v8::HandleScope scope(CcTest::isolate()); 404 v8::HandleScope scope(CcTest::isolate());
405 Zone zone(CcTest::i_isolate()); 405 Zone zone(CcTest::i_isolate());
406 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); 406 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input));
407 RegExpCompileData result; 407 RegExpCompileData result;
408 CHECK(!v8::internal::RegExpParser::ParseRegExp( 408 CHECK(!v8::internal::RegExpParser::ParseRegExp(&reader, false, false, &result,
409 &reader, false, &result, &zone)); 409 &zone));
410 CHECK(result.tree == NULL); 410 CHECK(result.tree == NULL);
411 CHECK(!result.error.is_null()); 411 CHECK(!result.error.is_null());
412 SmartArrayPointer<char> str = result.error->ToCString(ALLOW_NULLS); 412 SmartArrayPointer<char> str = result.error->ToCString(ALLOW_NULLS);
413 CHECK_EQ(expected, str.get()); 413 CHECK_EQ(expected, str.get());
414 } 414 }
415 415
416 416
417 TEST(Errors) { 417 TEST(Errors) {
418 const char* kEndBackslash = "\\ at end of pattern"; 418 const char* kEndBackslash = "\\ at end of pattern";
419 ExpectError("\\", kEndBackslash); 419 ExpectError("\\", kEndBackslash);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 TestCharacterClassEscapes('.', IsRegExpNewline); 490 TestCharacterClassEscapes('.', IsRegExpNewline);
491 TestCharacterClassEscapes('d', IsDigit); 491 TestCharacterClassEscapes('d', IsDigit);
492 TestCharacterClassEscapes('D', NotDigit); 492 TestCharacterClassEscapes('D', NotDigit);
493 TestCharacterClassEscapes('s', IsWhiteSpaceOrLineTerminator); 493 TestCharacterClassEscapes('s', IsWhiteSpaceOrLineTerminator);
494 TestCharacterClassEscapes('S', NotWhiteSpaceNorLineTermiantor); 494 TestCharacterClassEscapes('S', NotWhiteSpaceNorLineTermiantor);
495 TestCharacterClassEscapes('w', IsRegExpWord); 495 TestCharacterClassEscapes('w', IsRegExpWord);
496 TestCharacterClassEscapes('W', NotWord); 496 TestCharacterClassEscapes('W', NotWord);
497 } 497 }
498 498
499 499
500 static RegExpNode* Compile(const char* input, bool multiline, bool is_one_byte, 500 static RegExpNode* Compile(const char* input, bool multiline, bool unicode,
501 Zone* zone) { 501 bool is_one_byte, Zone* zone) {
502 Isolate* isolate = CcTest::i_isolate(); 502 Isolate* isolate = CcTest::i_isolate();
503 FlatStringReader reader(isolate, CStrVector(input)); 503 FlatStringReader reader(isolate, CStrVector(input));
504 RegExpCompileData compile_data; 504 RegExpCompileData compile_data;
505 if (!v8::internal::RegExpParser::ParseRegExp(&reader, multiline, 505 if (!v8::internal::RegExpParser::ParseRegExp(&reader, multiline, unicode,
506 &compile_data, zone)) 506 &compile_data, zone))
507 return NULL; 507 return NULL;
508 Handle<String> pattern = isolate->factory()-> 508 Handle<String> pattern = isolate->factory()
509 NewStringFromUtf8(CStrVector(input)).ToHandleChecked(); 509 ->NewStringFromUtf8(CStrVector(input))
510 .ToHandleChecked();
510 Handle<String> sample_subject = 511 Handle<String> sample_subject =
511 isolate->factory()->NewStringFromUtf8(CStrVector("")).ToHandleChecked(); 512 isolate->factory()->NewStringFromUtf8(CStrVector("")).ToHandleChecked();
512 RegExpEngine::Compile(&compile_data, false, false, multiline, false, pattern, 513 RegExpEngine::Compile(&compile_data, false, false, multiline, false, pattern,
513 sample_subject, is_one_byte, zone); 514 sample_subject, is_one_byte, zone);
514 return compile_data.node; 515 return compile_data.node;
515 } 516 }
516 517
517 518
518 static void Execute(const char* input, bool multiline, bool is_one_byte, 519 static void Execute(const char* input, bool multiline, bool unicode,
519 bool dot_output = false) { 520 bool is_one_byte, bool dot_output = false) {
520 v8::HandleScope scope(CcTest::isolate()); 521 v8::HandleScope scope(CcTest::isolate());
521 Zone zone(CcTest::i_isolate()); 522 Zone zone(CcTest::i_isolate());
522 RegExpNode* node = Compile(input, multiline, is_one_byte, &zone); 523 RegExpNode* node = Compile(input, multiline, unicode, is_one_byte, &zone);
523 USE(node); 524 USE(node);
524 #ifdef DEBUG 525 #ifdef DEBUG
525 if (dot_output) { 526 if (dot_output) {
526 RegExpEngine::DotPrint(input, node, false); 527 RegExpEngine::DotPrint(input, node, false);
527 } 528 }
528 #endif // DEBUG 529 #endif // DEBUG
529 } 530 }
530 531
531 532
532 class TestConfig { 533 class TestConfig {
(...skipping 1253 matching lines...) Expand 10 before | Expand all | Expand 10 after
1786 1787
1787 ZoneList<CharacterRange> first_only(4, &zone); 1788 ZoneList<CharacterRange> first_only(4, &zone);
1788 ZoneList<CharacterRange> second_only(4, &zone); 1789 ZoneList<CharacterRange> second_only(4, &zone);
1789 ZoneList<CharacterRange> both(4, &zone); 1790 ZoneList<CharacterRange> both(4, &zone);
1790 } 1791 }
1791 1792
1792 1793
1793 TEST(Graph) { 1794 TEST(Graph) {
1794 Execute("\\b\\w+\\b", false, true, true); 1795 Execute("\\b\\w+\\b", false, true, true);
1795 } 1796 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698