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

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

Issue 13343: More assertion propagation. (Closed)
Patch Set: "Does it lint?" Created 12 years 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/jsregexp.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 2008 the V8 project authors. All rights reserved. 1 // Copyright 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 49
50 using namespace v8::internal; 50 using namespace v8::internal;
51 51
52 52
53 static SmartPointer<const char> Parse(const char* input) { 53 static SmartPointer<const char> Parse(const char* input) {
54 V8::Initialize(NULL); 54 V8::Initialize(NULL);
55 v8::HandleScope scope; 55 v8::HandleScope scope;
56 ZoneScope zone_scope(DELETE_ON_EXIT); 56 ZoneScope zone_scope(DELETE_ON_EXIT);
57 FlatStringReader reader(CStrVector(input)); 57 FlatStringReader reader(CStrVector(input));
58 RegExpParseResult result; 58 RegExpCompileData result;
59 CHECK(v8::internal::ParseRegExp(&reader, false, &result)); 59 CHECK(v8::internal::ParseRegExp(&reader, false, &result));
60 CHECK(result.tree != NULL); 60 CHECK(result.tree != NULL);
61 CHECK(result.error.is_null()); 61 CHECK(result.error.is_null());
62 SmartPointer<const char> output = result.tree->ToString(); 62 SmartPointer<const char> output = result.tree->ToString();
63 return output; 63 return output;
64 } 64 }
65 65
66 static bool ParseEscapes(const char* input) { 66 static bool ParseEscapes(const char* input) {
67 V8::Initialize(NULL); 67 V8::Initialize(NULL);
68 v8::HandleScope scope; 68 v8::HandleScope scope;
69 unibrow::Utf8InputBuffer<> buffer(input, strlen(input)); 69 unibrow::Utf8InputBuffer<> buffer(input, strlen(input));
70 ZoneScope zone_scope(DELETE_ON_EXIT); 70 ZoneScope zone_scope(DELETE_ON_EXIT);
71 FlatStringReader reader(CStrVector(input)); 71 FlatStringReader reader(CStrVector(input));
72 RegExpParseResult result; 72 RegExpCompileData result;
73 CHECK(v8::internal::ParseRegExp(&reader, false, &result)); 73 CHECK(v8::internal::ParseRegExp(&reader, false, &result));
74 CHECK(result.tree != NULL); 74 CHECK(result.tree != NULL);
75 CHECK(result.error.is_null()); 75 CHECK(result.error.is_null());
76 return result.has_character_escapes; 76 return result.has_character_escapes;
77 } 77 }
78 78
79 79
80 #define CHECK_PARSE_EQ(input, expected) CHECK_EQ(expected, *Parse(input)) 80 #define CHECK_PARSE_EQ(input, expected) CHECK_EQ(expected, *Parse(input))
81 #define CHECK_ESCAPES(input, has_escapes) CHECK_EQ(has_escapes, \ 81 #define CHECK_ESCAPES(input, has_escapes) CHECK_EQ(has_escapes, \
82 ParseEscapes(input)); 82 ParseEscapes(input));
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 CHECK_PARSE_EQ("{", "'{'"); 252 CHECK_PARSE_EQ("{", "'{'");
253 CHECK_PARSE_EQ("a|", "(| 'a' %)"); 253 CHECK_PARSE_EQ("a|", "(| 'a' %)");
254 } 254 }
255 255
256 static void ExpectError(const char* input, 256 static void ExpectError(const char* input,
257 const char* expected) { 257 const char* expected) {
258 V8::Initialize(NULL); 258 V8::Initialize(NULL);
259 v8::HandleScope scope; 259 v8::HandleScope scope;
260 ZoneScope zone_scope(DELETE_ON_EXIT); 260 ZoneScope zone_scope(DELETE_ON_EXIT);
261 FlatStringReader reader(CStrVector(input)); 261 FlatStringReader reader(CStrVector(input));
262 RegExpParseResult result; 262 RegExpCompileData result;
263 CHECK_EQ(false, v8::internal::ParseRegExp(&reader, false, &result)); 263 CHECK_EQ(false, v8::internal::ParseRegExp(&reader, false, &result));
264 CHECK(result.tree == NULL); 264 CHECK(result.tree == NULL);
265 CHECK(!result.error.is_null()); 265 CHECK(!result.error.is_null());
266 SmartPointer<char> str = result.error->ToCString(ALLOW_NULLS); 266 SmartPointer<char> str = result.error->ToCString(ALLOW_NULLS);
267 CHECK_EQ(expected, *str); 267 CHECK_EQ(expected, *str);
268 } 268 }
269 269
270 270
271 TEST(Errors) { 271 TEST(Errors) {
272 V8::Initialize(NULL); 272 V8::Initialize(NULL);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 TestCharacterClassEscapes('s', IsWhiteSpace); 351 TestCharacterClassEscapes('s', IsWhiteSpace);
352 TestCharacterClassEscapes('S', NotWhiteSpace); 352 TestCharacterClassEscapes('S', NotWhiteSpace);
353 TestCharacterClassEscapes('w', IsRegExpWord); 353 TestCharacterClassEscapes('w', IsRegExpWord);
354 TestCharacterClassEscapes('W', NotWord); 354 TestCharacterClassEscapes('W', NotWord);
355 } 355 }
356 356
357 357
358 static RegExpNode* Compile(const char* input, bool multiline, bool is_ascii) { 358 static RegExpNode* Compile(const char* input, bool multiline, bool is_ascii) {
359 V8::Initialize(NULL); 359 V8::Initialize(NULL);
360 FlatStringReader reader(CStrVector(input)); 360 FlatStringReader reader(CStrVector(input));
361 RegExpParseResult result; 361 RegExpCompileData compile_data;
362 if (!v8::internal::ParseRegExp(&reader, multiline, &result)) 362 if (!v8::internal::ParseRegExp(&reader, multiline, &compile_data))
363 return NULL; 363 return NULL;
364 RegExpNode* node = NULL;
365 Handle<String> pattern = Factory::NewStringFromUtf8(CStrVector(input)); 364 Handle<String> pattern = Factory::NewStringFromUtf8(CStrVector(input));
366 RegExpEngine::Compile(&result, &node, false, multiline, pattern, is_ascii); 365 RegExpEngine::Compile(&compile_data, false, multiline, pattern, is_ascii);
367 return node; 366 return compile_data.node;
368 } 367 }
369 368
370 369
371 static void Execute(const char* input, 370 static void Execute(const char* input,
372 bool multiline, 371 bool multiline,
373 bool is_ascii, 372 bool is_ascii,
374 bool dot_output = false) { 373 bool dot_output = false) {
375 v8::HandleScope scope; 374 v8::HandleScope scope;
376 ZoneScope zone_scope(DELETE_ON_EXIT); 375 ZoneScope zone_scope(DELETE_ON_EXIT);
377 RegExpNode* node = Compile(input, multiline, is_ascii); 376 RegExpNode* node = Compile(input, multiline, is_ascii);
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after
1121 upper[0] = c; 1120 upper[0] = c;
1122 } 1121 }
1123 uc32 u = upper[0]; 1122 uc32 u = upper[0];
1124 if (length > 1 || (c >= 128 && u < 128)) 1123 if (length > 1 || (c >= 128 && u < 128))
1125 u = c; 1124 u = c;
1126 CHECK_EQ(u, canonicalize(c)); 1125 CHECK_EQ(u, canonicalize(c));
1127 } 1126 }
1128 } 1127 }
1129 1128
1130 1129
1131 TEST(SimplePropagation) {
1132 v8::HandleScope scope;
1133 ZoneScope zone_scope(DELETE_ON_EXIT);
1134 RegExpNode* node = Compile("(a|^b|c)", false, true);
1135 CHECK(node->info()->follows_start_interest);
1136 }
1137
1138
1139 static uc32 CanonRange(uc32 c) { 1130 static uc32 CanonRange(uc32 c) {
1140 unibrow::uchar canon[unibrow::CanonicalizationRange::kMaxWidth]; 1131 unibrow::uchar canon[unibrow::CanonicalizationRange::kMaxWidth];
1141 int count = unibrow::CanonicalizationRange::Convert(c, '\0', canon, NULL); 1132 int count = unibrow::CanonicalizationRange::Convert(c, '\0', canon, NULL);
1142 if (count == 0) { 1133 if (count == 0) {
1143 return c; 1134 return c;
1144 } else { 1135 } else {
1145 CHECK_EQ(1, count); 1136 CHECK_EQ(1, count);
1146 return canon[0]; 1137 return canon[0];
1147 } 1138 }
1148 } 1139 }
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1294 } else { 1285 } else {
1295 CHECK(!InClass(i, included)); 1286 CHECK(!InClass(i, included));
1296 CHECK(!InClass(i, excluded)); 1287 CHECK(!InClass(i, excluded));
1297 } 1288 }
1298 } 1289 }
1299 } 1290 }
1300 1291
1301 1292
1302 TEST(Graph) { 1293 TEST(Graph) {
1303 V8::Initialize(NULL); 1294 V8::Initialize(NULL);
1304 Execute("(?=[d#.])", false, true, true); 1295 Execute("\\bboy\\b", false, true, true);
Lasse Reichstein 2008/12/11 08:34:23 Could you (plural, everybody using this) not move
Christian Plesner Hansen 2008/12/11 09:14:12 It's really convenient to be able to build this al
1305 } 1296 }
OLDNEW
« src/jsregexp.cc ('K') | « src/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698