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

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

Issue 11473: Bugfixes (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
« no previous file with comments | « 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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 CHECK_ESCAPES("a(?:b)", false); 212 CHECK_ESCAPES("a(?:b)", false);
213 CHECK_ESCAPES("a(?=b)", false); 213 CHECK_ESCAPES("a(?=b)", false);
214 CHECK_ESCAPES("a(?!b)", false); 214 CHECK_ESCAPES("a(?!b)", false);
215 CHECK_ESCAPES("\\x60", true); 215 CHECK_ESCAPES("\\x60", true);
216 CHECK_ESCAPES("\\u0060", true); 216 CHECK_ESCAPES("\\u0060", true);
217 CHECK_ESCAPES("\\cA", true); 217 CHECK_ESCAPES("\\cA", true);
218 CHECK_ESCAPES("\\q", true); 218 CHECK_ESCAPES("\\q", true);
219 CHECK_ESCAPES("\\1112", true); 219 CHECK_ESCAPES("\\1112", true);
220 CHECK_ESCAPES("\\0", true); 220 CHECK_ESCAPES("\\0", true);
221 CHECK_ESCAPES("(a)\\1", false); 221 CHECK_ESCAPES("(a)\\1", false);
222
223 CHECK_PARSE_EQ("a{}", "'a{}'");
224 CHECK_PARSE_EQ("a{,}", "'a{,}'");
225 CHECK_PARSE_EQ("a{", "'a{'");
226 CHECK_PARSE_EQ("a{z}", "'a{z}'");
227 CHECK_PARSE_EQ("a{1z}", "'a{1z}'");
228 CHECK_PARSE_EQ("a{12z}", "'a{12z}'");
229 CHECK_PARSE_EQ("a{12,", "'a{12,'");
230 CHECK_PARSE_EQ("a{12,3b", "'a{12,3b'");
231 CHECK_PARSE_EQ("{}", "'{}'");
232 CHECK_PARSE_EQ("{,}", "'{,}'");
233 CHECK_PARSE_EQ("{", "'{'");
234 CHECK_PARSE_EQ("{z}", "'{z}'");
235 CHECK_PARSE_EQ("{1z}", "'{1z}'");
236 CHECK_PARSE_EQ("{12z}", "'{12z}'");
237 CHECK_PARSE_EQ("{12,", "'{12,'");
238 CHECK_PARSE_EQ("{12,3b", "'{12,3b'");
222 } 239 }
223 240
224 TEST(ParserRegression) { 241 TEST(ParserRegression) {
225 CHECK_PARSE_EQ("[A-Z$-][x]", "(! [A-Z $ -] [x])"); 242 CHECK_PARSE_EQ("[A-Z$-][x]", "(! [A-Z $ -] [x])");
243 CHECK_PARSE_EQ("a{3,4*}", "(: 'a{3,' (# 0 - g '4') '}')");
244 CHECK_PARSE_EQ("{", "'{'");
245 CHECK_PARSE_EQ("a|", "(| 'a' %)");
226 } 246 }
227 247
228 static void ExpectError(const char* input, 248 static void ExpectError(const char* input,
229 const char* expected) { 249 const char* expected) {
230 v8::HandleScope scope; 250 v8::HandleScope scope;
231 ZoneScope zone_scope(DELETE_ON_EXIT); 251 ZoneScope zone_scope(DELETE_ON_EXIT);
232 FlatStringReader reader(CStrVector(input)); 252 FlatStringReader reader(CStrVector(input));
233 RegExpParseResult result; 253 RegExpParseResult result;
234 CHECK_EQ(false, v8::internal::ParseRegExp(&reader, &result)); 254 CHECK_EQ(false, v8::internal::ParseRegExp(&reader, &result));
235 CHECK(result.tree == NULL); 255 CHECK(result.tree == NULL);
236 CHECK(!result.error.is_null()); 256 CHECK(!result.error.is_null());
237 SmartPointer<char> str = result.error->ToCString(ALLOW_NULLS); 257 SmartPointer<char> str = result.error->ToCString(ALLOW_NULLS);
238 CHECK_EQ(expected, *str); 258 CHECK_EQ(expected, *str);
239 } 259 }
240 260
241 261
242 TEST(Errors) { 262 TEST(Errors) {
243 V8::Initialize(NULL); 263 V8::Initialize(NULL);
244 const char* kEndBackslash = "\\ at end of pattern"; 264 const char* kEndBackslash = "\\ at end of pattern";
245 ExpectError("\\", kEndBackslash); 265 ExpectError("\\", kEndBackslash);
246 const char* kInvalidQuantifier = "Invalid quantifier";
247 ExpectError("a{}", kInvalidQuantifier);
248 ExpectError("a{,}", kInvalidQuantifier);
249 ExpectError("a{", kInvalidQuantifier);
250 ExpectError("a{z}", kInvalidQuantifier);
251 ExpectError("a{1z}", kInvalidQuantifier);
252 ExpectError("a{12z}", kInvalidQuantifier);
253 ExpectError("a{12,", kInvalidQuantifier);
254 ExpectError("a{12,3b", kInvalidQuantifier);
255 const char* kUnterminatedGroup = "Unterminated group"; 266 const char* kUnterminatedGroup = "Unterminated group";
256 ExpectError("(foo", kUnterminatedGroup); 267 ExpectError("(foo", kUnterminatedGroup);
257 const char* kInvalidGroup = "Invalid group"; 268 const char* kInvalidGroup = "Invalid group";
258 ExpectError("(?", kInvalidGroup); 269 ExpectError("(?", kInvalidGroup);
259 const char* kUnterminatedCharacterClass = "Unterminated character class"; 270 const char* kUnterminatedCharacterClass = "Unterminated character class";
260 ExpectError("[", kUnterminatedCharacterClass); 271 ExpectError("[", kUnterminatedCharacterClass);
261 ExpectError("[a-", kUnterminatedCharacterClass); 272 ExpectError("[a-", kUnterminatedCharacterClass);
262 const char* kIllegalCharacterClass = "Illegal character class"; 273 const char* kIllegalCharacterClass = "Illegal character class";
263 ExpectError("[a-\\w]", kIllegalCharacterClass); 274 ExpectError("[a-\\w]", kIllegalCharacterClass);
264 const char* kEndControl = "\\c at end of pattern"; 275 const char* kEndControl = "\\c at end of pattern";
265 ExpectError("\\c", kEndControl); 276 ExpectError("\\c", kEndControl);
277 static char* kNothingToRepeat = "Nothing to repeat";
278 ExpectError("*", kNothingToRepeat);
279 ExpectError("?", kNothingToRepeat);
280 ExpectError("+", kNothingToRepeat);
281 ExpectError("{1}", kNothingToRepeat);
282 ExpectError("{1,2}", kNothingToRepeat);
283 ExpectError("{1,}", kNothingToRepeat);
266 } 284 }
267 285
268 286
269 static bool IsDigit(uc16 c) { 287 static bool IsDigit(uc16 c) {
270 return ('0' <= c && c <= '9'); 288 return ('0' <= c && c <= '9');
271 } 289 }
272 290
273 291
274 static bool NotDigit(uc16 c) { 292 static bool NotDigit(uc16 c) {
275 return !IsDigit(c); 293 return !IsDigit(c);
(...skipping 30 matching lines...) Expand all
306 || (c == '_'); 324 || (c == '_');
307 } 325 }
308 326
309 327
310 static bool NotWord(uc16 c) { 328 static bool NotWord(uc16 c) {
311 return !IsWord(c); 329 return !IsWord(c);
312 } 330 }
313 331
314 332
315 static bool Dot(uc16 c) { 333 static bool Dot(uc16 c) {
316 return true; 334 switch (c) {
335 // CR LF LS PS
336 case 0x000A: case 0x000D: case 0x2028: case 0x2029:
337 return false;
338 default:
339 return true;
340 }
317 } 341 }
318 342
319 343
320 static void TestCharacterClassEscapes(uc16 c, bool (pred)(uc16 c)) { 344 static void TestCharacterClassEscapes(uc16 c, bool (pred)(uc16 c)) {
321 ZoneScope scope(DELETE_ON_EXIT); 345 ZoneScope scope(DELETE_ON_EXIT);
322 ZoneList<CharacterRange>* ranges = new ZoneList<CharacterRange>(2); 346 ZoneList<CharacterRange>* ranges = new ZoneList<CharacterRange>(2);
323 CharacterRange::AddClassEscape(c, ranges); 347 CharacterRange::AddClassEscape(c, ranges);
324 for (unsigned i = 0; i < (1 << 16); i++) { 348 for (unsigned i = 0; i < (1 << 16); i++) {
325 bool in_class = false; 349 bool in_class = false;
326 for (int j = 0; !in_class && j < ranges->length(); j++) { 350 for (int j = 0; !in_class && j < ranges->length(); j++) {
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 ZoneScope zone_scope(DELETE_ON_EXIT); 809 ZoneScope zone_scope(DELETE_ON_EXIT);
786 RegExpNode* node = Compile("(a|^b|c)"); 810 RegExpNode* node = Compile("(a|^b|c)");
787 CHECK(node->info()->determine_start); 811 CHECK(node->info()->determine_start);
788 } 812 }
789 813
790 814
791 TEST(Graph) { 815 TEST(Graph) {
792 V8::Initialize(NULL); 816 V8::Initialize(NULL);
793 Execute("(a|^b|c)", "", true); 817 Execute("(a|^b|c)", "", true);
794 } 818 }
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698