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

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

Issue 11231: Flat string reader (Closed)
Patch Set: Created 12 years, 1 month 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
« src/objects.cc ('K') | « src/parser.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 29 matching lines...) Expand all
40 #include "regexp-macro-assembler.h" 40 #include "regexp-macro-assembler.h"
41 #include "regexp-macro-assembler-re2k.h" 41 #include "regexp-macro-assembler-re2k.h"
42 #include "interpreter-re2k.h" 42 #include "interpreter-re2k.h"
43 43
44 44
45 using namespace v8::internal; 45 using namespace v8::internal;
46 46
47 47
48 static SmartPointer<const char> Parse(const char* input) { 48 static SmartPointer<const char> Parse(const char* input) {
49 v8::HandleScope scope; 49 v8::HandleScope scope;
50 unibrow::Utf8InputBuffer<> buffer(input, strlen(input));
51 ZoneScope zone_scope(DELETE_ON_EXIT); 50 ZoneScope zone_scope(DELETE_ON_EXIT);
51 FlatStringReader reader(CStrVector(input));
52 RegExpParseResult result; 52 RegExpParseResult result;
53 CHECK(v8::internal::ParseRegExp(&buffer, &result)); 53 CHECK(v8::internal::ParseRegExp(&reader, &result));
54 CHECK(result.tree != NULL); 54 CHECK(result.tree != NULL);
55 CHECK(result.error.is_null()); 55 CHECK(result.error.is_null());
56 SmartPointer<const char> output = result.tree->ToString(); 56 SmartPointer<const char> output = result.tree->ToString();
57 return output; 57 return output;
58 } 58 }
59 59
60 static bool ParseEscapes(const char* input) { 60 static bool ParseEscapes(const char* input) {
61 v8::HandleScope scope; 61 v8::HandleScope scope;
62 unibrow::Utf8InputBuffer<> buffer(input, strlen(input)); 62 unibrow::Utf8InputBuffer<> buffer(input, strlen(input));
63 ZoneScope zone_scope(DELETE_ON_EXIT); 63 ZoneScope zone_scope(DELETE_ON_EXIT);
64 FlatStringReader reader(CStrVector(input));
64 RegExpParseResult result; 65 RegExpParseResult result;
65 CHECK(v8::internal::ParseRegExp(&buffer, &result)); 66 CHECK(v8::internal::ParseRegExp(&reader, &result));
66 CHECK(result.tree != NULL); 67 CHECK(result.tree != NULL);
67 CHECK(result.error.is_null()); 68 CHECK(result.error.is_null());
68 return result.has_character_escapes; 69 return result.has_character_escapes;
69 } 70 }
70 71
71 72
72 #define CHECK_PARSE_EQ(input, expected) CHECK_EQ(expected, *Parse(input)) 73 #define CHECK_PARSE_EQ(input, expected) CHECK_EQ(expected, *Parse(input))
73 #define CHECK_ESCAPES(input, has_escapes) CHECK_EQ(has_escapes, \ 74 #define CHECK_ESCAPES(input, has_escapes) CHECK_EQ(has_escapes, \
74 ParseEscapes(input)); 75 ParseEscapes(input));
75 76
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 CHECK_ESCAPES("(a)\\1", false); 221 CHECK_ESCAPES("(a)\\1", false);
221 } 222 }
222 223
223 TEST(ParserRegression) { 224 TEST(ParserRegression) {
224 CHECK_PARSE_EQ("[A-Z$-][x]", "(! [A-Z $ -] [x])"); 225 CHECK_PARSE_EQ("[A-Z$-][x]", "(! [A-Z $ -] [x])");
225 } 226 }
226 227
227 static void ExpectError(const char* input, 228 static void ExpectError(const char* input,
228 const char* expected) { 229 const char* expected) {
229 v8::HandleScope scope; 230 v8::HandleScope scope;
230 unibrow::Utf8InputBuffer<> buffer(input, strlen(input));
231 ZoneScope zone_scope(DELETE_ON_EXIT); 231 ZoneScope zone_scope(DELETE_ON_EXIT);
232 FlatStringReader reader(CStrVector(input));
232 RegExpParseResult result; 233 RegExpParseResult result;
233 CHECK_EQ(false, v8::internal::ParseRegExp(&buffer, &result)); 234 CHECK_EQ(false, v8::internal::ParseRegExp(&reader, &result));
234 CHECK(result.tree == NULL); 235 CHECK(result.tree == NULL);
235 CHECK(!result.error.is_null()); 236 CHECK(!result.error.is_null());
236 SmartPointer<char> str = result.error->ToCString(ALLOW_NULLS); 237 SmartPointer<char> str = result.error->ToCString(ALLOW_NULLS);
237 CHECK_EQ(expected, *str); 238 CHECK_EQ(expected, *str);
238 } 239 }
239 240
240 241
241 TEST(Errors) { 242 TEST(Errors) {
242 V8::Initialize(NULL); 243 V8::Initialize(NULL);
243 const char* kEndBackslash = "\\ at end of pattern"; 244 const char* kEndBackslash = "\\ at end of pattern";
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 TestCharacterClassEscapes('d', IsDigit); 329 TestCharacterClassEscapes('d', IsDigit);
329 TestCharacterClassEscapes('D', NotDigit); 330 TestCharacterClassEscapes('D', NotDigit);
330 TestCharacterClassEscapes('s', IsWhiteSpace); 331 TestCharacterClassEscapes('s', IsWhiteSpace);
331 TestCharacterClassEscapes('S', NotWhiteSpace); 332 TestCharacterClassEscapes('S', NotWhiteSpace);
332 TestCharacterClassEscapes('w', IsWord); 333 TestCharacterClassEscapes('w', IsWord);
333 TestCharacterClassEscapes('W', NotWord); 334 TestCharacterClassEscapes('W', NotWord);
334 } 335 }
335 336
336 337
337 static RegExpNode* Compile(const char* input) { 338 static RegExpNode* Compile(const char* input) {
338 unibrow::Utf8InputBuffer<> buffer(input, strlen(input)); 339 FlatStringReader reader(CStrVector(input));
339 RegExpParseResult result; 340 RegExpParseResult result;
340 if (!v8::internal::ParseRegExp(&buffer, &result)) 341 if (!v8::internal::ParseRegExp(&reader, &result))
341 return NULL; 342 return NULL;
342 RegExpNode* node = NULL; 343 RegExpNode* node = NULL;
343 RegExpEngine::Compile(&result, &node, false); 344 RegExpEngine::Compile(&result, &node, false);
344 return node; 345 return node;
345 } 346 }
346 347
347 348
348 static void Execute(const char* input, 349 static void Execute(const char* input,
349 const char* str, 350 const char* str,
350 bool dot_output = false) { 351 bool dot_output = false) {
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 v8::HandleScope scope; 766 v8::HandleScope scope;
766 ZoneScope zone_scope(DELETE_ON_EXIT); 767 ZoneScope zone_scope(DELETE_ON_EXIT);
767 RegExpNode* node = Compile("(a|^b|c)"); 768 RegExpNode* node = Compile("(a|^b|c)");
768 CHECK(node->info()->determine_start); 769 CHECK(node->info()->determine_start);
769 } 770 }
770 771
771 772
772 TEST(Graph) { 773 TEST(Graph) {
773 Execute("(a|^b|c)", "", true); 774 Execute("(a|^b|c)", "", true);
774 } 775 }
OLDNEW
« src/objects.cc ('K') | « src/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698