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

Side by Side Diff: tests/corelib_strong/regexp/regexp_test.dart

Issue 2771453003: Format all tests. (Closed)
Patch Set: Format files Created 3 years, 8 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 (c) 2014, the Dart project authors. All rights reserved. 1 // Copyright (c) 2014, the Dart project authors. All rights reserved.
2 // Copyright 2012 the V8 project authors. All rights reserved. 2 // Copyright 2012 the V8 project authors. All rights reserved.
3 // Redistribution and use in source and binary forms, with or without 3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are 4 // modification, are permitted provided that the following conditions are
5 // met: 5 // met:
6 // 6 //
7 // * Redistributions of source code must retain the above copyright 7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer. 8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above 9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following 10 // copyright notice, this list of conditions and the following
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 testEscape("foo bar baz", new RegExp(r"\s")); 43 testEscape("foo bar baz", new RegExp(r"\s"));
44 testEscape("foo\tbar\tbaz", new RegExp(r"\s")); 44 testEscape("foo\tbar\tbaz", new RegExp(r"\s"));
45 testEscape("foo-bar-baz", new RegExp(r"\u002D")); 45 testEscape("foo-bar-baz", new RegExp(r"\u002D"));
46 46
47 // Test containing null char in regexp. 47 // Test containing null char in regexp.
48 var s = '[' + new String.fromCharCode(0) + ']'; 48 var s = '[' + new String.fromCharCode(0) + ']';
49 var re = new RegExp(s); 49 var re = new RegExp(s);
50 assertEquals(re.allMatches(s).length, 1); 50 assertEquals(re.allMatches(s).length, 1);
51 assertEquals(re.stringMatch(s), new String.fromCharCode(0)); 51 assertEquals(re.stringMatch(s), new String.fromCharCode(0));
52 52
53 final _vmFrame = new RegExp( 53 final _vmFrame = new RegExp(r'^#\d+\s+(\S.*) \((.+?):(\d+)(?::(\d+))?\)$');
54 r'^#\d+\s+(\S.*) \((.+?):(\d+)(?::(\d+))?\)$');
55 final _traceLine = 54 final _traceLine =
56 "#0 Trace.Trace.parse (package:stack_trace/src/trace.dart:130:7)"; 55 "#0 Trace.Trace.parse (package:stack_trace/src/trace.dart:130:7)";
57 Expect.equals(_vmFrame.firstMatch(_traceLine).group(0), _traceLine); 56 Expect.equals(_vmFrame.firstMatch(_traceLine).group(0), _traceLine);
58 57
59 // Test the UTF16 case insensitive comparison. 58 // Test the UTF16 case insensitive comparison.
60 re = new RegExp(r"x(a)\1x", caseSensitive: false); 59 re = new RegExp(r"x(a)\1x", caseSensitive: false);
61 Expect.equals(re.firstMatch("xaAx\u1234").group(0), "xaAx"); 60 Expect.equals(re.firstMatch("xaAx\u1234").group(0), "xaAx");
62 61
63 // Test strings containing all line separators 62 // Test strings containing all line separators
64 s = 'aA\nbB\rcC\r\ndD\u2028eE\u2029fF'; 63 s = 'aA\nbB\rcC\r\ndD\u2028eE\u2029fF';
65 // any non-newline character at the beginning of a line 64 // any non-newline character at the beginning of a line
66 re = new RegExp(r"^.", multiLine: true); 65 re = new RegExp(r"^.", multiLine: true);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 assertEquals(result[1][0], 'B'); 103 assertEquals(result[1][0], 'B');
105 assertEquals(result[2][0], 'C'); 104 assertEquals(result[2][0], 'C');
106 assertEquals(result[3][0], '\r'); 105 assertEquals(result[3][0], '\r');
107 assertEquals(result[4][0], 'D'); 106 assertEquals(result[4][0], 'D');
108 assertEquals(result[5][0], 'E'); 107 assertEquals(result[5][0], 'E');
109 assertEquals(result[6][0], 'F'); 108 assertEquals(result[6][0], 'F');
110 109
111 // Some tests from the Mozilla tests, where our behavior used to differ 110 // Some tests from the Mozilla tests, where our behavior used to differ
112 // from SpiderMonkey. 111 // from SpiderMonkey.
113 // From ecma_3/RegExp/regress-334158.js 112 // From ecma_3/RegExp/regress-334158.js
114 assertTrue( "\x01" .contains(new RegExp(r"\ca"))); 113 assertTrue("\x01".contains(new RegExp(r"\ca")));
115 assertFalse( "\\ca" .contains(new RegExp(r"\ca"))); 114 assertFalse("\\ca".contains(new RegExp(r"\ca")));
116 assertFalse( "ca" .contains(new RegExp(r"\ca"))); 115 assertFalse("ca".contains(new RegExp(r"\ca")));
117 assertTrue( "\\ca" .contains(new RegExp(r"\c[a/]"))); 116 assertTrue("\\ca".contains(new RegExp(r"\c[a/]")));
118 assertTrue( "\\c/" .contains(new RegExp(r"\c[a/]"))); 117 assertTrue("\\c/".contains(new RegExp(r"\c[a/]")));
119 118
120 // Test \c in character class 119 // Test \c in character class
121 re = r"^[\cM]$"; 120 re = r"^[\cM]$";
122 assertTrue("\r".contains(new RegExp(re))); 121 assertTrue("\r".contains(new RegExp(re)));
123 assertFalse("M".contains(new RegExp(re))); 122 assertFalse("M".contains(new RegExp(re)));
124 assertFalse("c".contains(new RegExp(re))); 123 assertFalse("c".contains(new RegExp(re)));
125 assertFalse("\\".contains(new RegExp(re))); 124 assertFalse("\\".contains(new RegExp(re)));
126 assertFalse("\x03".contains(new RegExp(re))); // I.e., read as \cc 125 assertFalse("\x03".contains(new RegExp(re))); // I.e., read as \cc
127 126
128 re = r"^[\c]]$"; 127 re = r"^[\c]]$";
129 assertTrue("c]".contains(new RegExp(re))); 128 assertTrue("c]".contains(new RegExp(re)));
130 assertTrue("\\]".contains(new RegExp(re))); 129 assertTrue("\\]".contains(new RegExp(re)));
131 assertFalse("\x1d".contains(new RegExp(re))); // ']' & 0x1f 130 assertFalse("\x1d".contains(new RegExp(re))); // ']' & 0x1f
132 assertFalse("\x03]".contains(new RegExp(re))); // I.e., read as \cc 131 assertFalse("\x03]".contains(new RegExp(re))); // I.e., read as \cc
133 132
134 // Digit control characters are masked in character classes. 133 // Digit control characters are masked in character classes.
135 re = r"^[\c1]$"; 134 re = r"^[\c1]$";
136 assertTrue("\x11".contains(new RegExp(re))); 135 assertTrue("\x11".contains(new RegExp(re)));
137 assertFalse("\\".contains(new RegExp(re))); 136 assertFalse("\\".contains(new RegExp(re)));
138 assertFalse("c".contains(new RegExp(re))); 137 assertFalse("c".contains(new RegExp(re)));
139 assertFalse("1".contains(new RegExp(re))); 138 assertFalse("1".contains(new RegExp(re)));
140 139
141 // Underscore control character is masked in character classes. 140 // Underscore control character is masked in character classes.
142 re = r"^[\c_]$"; 141 re = r"^[\c_]$";
143 assertTrue("\x1f".contains(new RegExp(re))); 142 assertTrue("\x1f".contains(new RegExp(re)));
144 assertFalse("\\".contains(new RegExp(re))); 143 assertFalse("\\".contains(new RegExp(re)));
145 assertFalse("c".contains(new RegExp(re))); 144 assertFalse("c".contains(new RegExp(re)));
146 assertFalse("_".contains(new RegExp(re))); 145 assertFalse("_".contains(new RegExp(re)));
147 146
148 re = r"^[\c$]$"; // Other characters are interpreted literally. 147 re = r"^[\c$]$"; // Other characters are interpreted literally.
149 assertFalse("\x04".contains(new RegExp(re))); 148 assertFalse("\x04".contains(new RegExp(re)));
150 assertTrue("\\".contains(new RegExp(re))); 149 assertTrue("\\".contains(new RegExp(re)));
151 assertTrue("c".contains(new RegExp(re))); 150 assertTrue("c".contains(new RegExp(re)));
152 assertTrue(r"$".contains(new RegExp(re))); 151 assertTrue(r"$".contains(new RegExp(re)));
153 152
154 assertTrue("Z[\\cde".contains(new RegExp(r"^[Z-\c-e]*$"))); 153 assertTrue("Z[\\cde".contains(new RegExp(r"^[Z-\c-e]*$")));
155 154
156 // Test that we handle \s and \S correctly on special Unicode characters. 155 // Test that we handle \s and \S correctly on special Unicode characters.
157 re = r"\s"; 156 re = r"\s";
158 assertTrue("\u2028".contains(new RegExp(re))); 157 assertTrue("\u2028".contains(new RegExp(re)));
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 re = r"\d+$"; 276 re = r"\d+$";
278 assertFalse("123\nasdf".contains(new RegExp(re))); 277 assertFalse("123\nasdf".contains(new RegExp(re)));
279 re = new RegExp(r"\d+$", multiLine: true); 278 re = new RegExp(r"\d+$", multiLine: true);
280 assertTrue("123\nasdf".contains(re)); 279 assertTrue("123\nasdf".contains(re));
281 280
282 // Test that empty matches are handled correctly for multiline global 281 // Test that empty matches are handled correctly for multiline global
283 // regexps. 282 // regexps.
284 re = new RegExp(r"^(.*)", multiLine: true); 283 re = new RegExp(r"^(.*)", multiLine: true);
285 assertEquals(3, re.allMatches("a\n\rb").length); 284 assertEquals(3, re.allMatches("a\n\rb").length);
286 assertEquals("*a\n*b\r*c\n*\r*d\r*\n*e", 285 assertEquals("*a\n*b\r*c\n*\r*d\r*\n*e",
287 "a\nb\rc\n\rd\r\ne".replaceAllMapped( 286 "a\nb\rc\n\rd\r\ne".replaceAllMapped(re, (Match m) => "*${m.group(1)}"));
288 re, (Match m) => "*${m.group(1)}"));
289 287
290 // Test that empty matches advance one character 288 // Test that empty matches advance one character
291 re = new RegExp(""); 289 re = new RegExp("");
292 assertEquals("xAx", "A".replaceAll(re, "x")); 290 assertEquals("xAx", "A".replaceAll(re, "x"));
293 assertEquals(3, new String.fromCharCode(161).replaceAll(re, "x").length); 291 assertEquals(3, new String.fromCharCode(161).replaceAll(re, "x").length);
294 292
295 // Check for lazy RegExp literal creation 293 // Check for lazy RegExp literal creation
296 lazyLiteral(doit) { 294 lazyLiteral(doit) {
297 if (doit) return "".replaceAll( 295 if (doit)
298 new RegExp(r"foo(", caseSensitive: false), ""); 296 return "".replaceAll(new RegExp(r"foo(", caseSensitive: false), "");
299 return true; 297 return true;
300 } 298 }
301 299
302 assertTrue(lazyLiteral(false)); 300 assertTrue(lazyLiteral(false));
303 assertThrows(() => lazyLiteral(true)); 301 assertThrows(() => lazyLiteral(true));
304 302
305 // Check $01 and $10 303 // Check $01 and $10
306 re = new RegExp("(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)"); 304 re = new RegExp("(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)");
307 assertEquals("t", "123456789t".replaceAllMapped( 305 assertEquals(
308 re, (Match m) => m.group(10))); 306 "t", "123456789t".replaceAllMapped(re, (Match m) => m.group(10)));
309 assertEquals("15", "123456789t".replaceAllMapped( 307 assertEquals(
310 re, (Match m) => "${m.group(1)}5")); 308 "15", "123456789t".replaceAllMapped(re, (Match m) => "${m.group(1)}5"));
311 assertEquals("1", "123456789t".replaceAllMapped( 309 assertEquals("1", "123456789t".replaceAllMapped(re, (Match m) => m.group(1)));
312 re, (Match m) => m.group(1)));
313 310
314 assertFalse("football".contains(new RegExp(r"()foo$\1")), "football1"); 311 assertFalse("football".contains(new RegExp(r"()foo$\1")), "football1");
315 assertFalse("football".contains(new RegExp(r"foo$(?=ball)")), "football2"); 312 assertFalse("football".contains(new RegExp(r"foo$(?=ball)")), "football2");
316 assertFalse("football".contains(new RegExp(r"foo$(?!bar)")), "football3"); 313 assertFalse("football".contains(new RegExp(r"foo$(?!bar)")), "football3");
317 assertTrue("foo".contains(new RegExp(r"()foo$\1")), "football4"); 314 assertTrue("foo".contains(new RegExp(r"()foo$\1")), "football4");
318 assertTrue("foo".contains(new RegExp(r"foo$(?=(ball)?)")), "football5"); 315 assertTrue("foo".contains(new RegExp(r"foo$(?=(ball)?)")), "football5");
319 assertTrue("foo".contains(new RegExp(r"()foo$(?!bar)")), "football6"); 316 assertTrue("foo".contains(new RegExp(r"()foo$(?!bar)")), "football6");
320 assertFalse("football".contains(new RegExp(r"(x?)foo$\1")), "football7"); 317 assertFalse("football".contains(new RegExp(r"(x?)foo$\1")), "football7");
321 assertFalse("football".contains(new RegExp(r"foo$(?=ball)")), "football8"); 318 assertFalse("football".contains(new RegExp(r"foo$(?=ball)")), "football8");
322 assertFalse("football".contains(new RegExp(r"foo$(?!bar)")), "football9"); 319 assertFalse("football".contains(new RegExp(r"foo$(?!bar)")), "football9");
323 assertTrue("foo".contains(new RegExp(r"(x?)foo$\1")), "football10"); 320 assertTrue("foo".contains(new RegExp(r"(x?)foo$\1")), "football10");
324 assertTrue("foo".contains(new RegExp(r"foo$(?=(ball)?)")), "football11"); 321 assertTrue("foo".contains(new RegExp(r"foo$(?=(ball)?)")), "football11");
325 assertTrue("foo".contains(new RegExp(r"foo$(?!bar)")), "football12"); 322 assertTrue("foo".contains(new RegExp(r"foo$(?!bar)")), "football12");
326 323
327 // Check that the back reference has two successors. See 324 // Check that the back reference has two successors. See
328 // BackReferenceNode::PropagateForward. 325 // BackReferenceNode::PropagateForward.
329 assertFalse('foo'.contains(new RegExp(r"f(o)\b\1"))); 326 assertFalse('foo'.contains(new RegExp(r"f(o)\b\1")));
330 assertTrue('foo'.contains(new RegExp(r"f(o)\B\1"))); 327 assertTrue('foo'.contains(new RegExp(r"f(o)\B\1")));
331 328
332 // Back-reference, ignore case: 329 // Back-reference, ignore case:
333 // ASCII 330 // ASCII
334 assertEquals("a", new RegExp(r"x(a)\1x", caseSensitive: false) 331 assertEquals(
335 .firstMatch("xaAx").group(1), "backref-ASCII"); 332 "a",
336 assertFalse("xaaaaa".contains(new RegExp(r"x(...)\1", 333 new RegExp(r"x(a)\1x", caseSensitive: false).firstMatch("xaAx").group(1),
337 caseSensitive: false)), 334 "backref-ASCII");
335 assertFalse("xaaaaa".contains(new RegExp(r"x(...)\1", caseSensitive: false)),
338 "backref-ASCII-short"); 336 "backref-ASCII-short");
339 assertTrue("xx".contains(new RegExp(r"x((?:))\1\1x", caseSensitive: false)), 337 assertTrue("xx".contains(new RegExp(r"x((?:))\1\1x", caseSensitive: false)),
340 "backref-ASCII-empty"); 338 "backref-ASCII-empty");
341 assertTrue("xabcx".contains( 339 assertTrue(
342 new RegExp(r"x(?:...|(...))\1x", caseSensitive: false)), 340 "xabcx".contains(new RegExp(r"x(?:...|(...))\1x", caseSensitive: false)),
343 "backref-ASCII-uncaptured"); 341 "backref-ASCII-uncaptured");
344 assertTrue("xabcABCx".contains( 342 assertTrue(
345 new RegExp(r"x(?:...|(...))\1x", caseSensitive: false)), 343 "xabcABCx"
344 .contains(new RegExp(r"x(?:...|(...))\1x", caseSensitive: false)),
346 "backref-ASCII-backtrack"); 345 "backref-ASCII-backtrack");
347 assertEquals("aBc", new RegExp(r"x(...)\1\1x", caseSensitive: false) 346 assertEquals(
348 .firstMatch("xaBcAbCABCx").group(1), "backref-ASCII-twice"); 347 "aBc",
348 new RegExp(r"x(...)\1\1x", caseSensitive: false)
349 .firstMatch("xaBcAbCABCx")
350 .group(1),
351 "backref-ASCII-twice");
349 352
350 for (var i = 0; i < 128; i++) { 353 for (var i = 0; i < 128; i++) {
351 var testName = "backref-ASCII-char-$i,,${i^0x20}"; 354 var testName = "backref-ASCII-char-$i,,${i^0x20}";
352 var test = new String.fromCharCodes([i, i ^ 0x20]) 355 var test = new String.fromCharCodes([i, i ^ 0x20])
353 .contains(new RegExp(r"^(.)\1$", caseSensitive: false)); 356 .contains(new RegExp(r"^(.)\1$", caseSensitive: false));
354 if (('A'.codeUnitAt(0) <= i && i <= 'Z'.codeUnitAt(0)) || 357 if (('A'.codeUnitAt(0) <= i && i <= 'Z'.codeUnitAt(0)) ||
355 ('a'.codeUnitAt(0) <= i && i <= 'z'.codeUnitAt(0))) { 358 ('a'.codeUnitAt(0) <= i && i <= 'z'.codeUnitAt(0))) {
356 assertTrue(test, testName); 359 assertTrue(test, testName);
357 } else { 360 } else {
358 assertFalse(test, testName); 361 assertFalse(test, testName);
359 } 362 }
360 } 363 }
361 364
362 assertFalse('foo'.contains(new RegExp(r"f(o)$\1")), 365 assertFalse('foo'.contains(new RegExp(r"f(o)$\1")), "backref detects at_end");
363 "backref detects at_end");
364 366
365 // Check decimal escapes doesn't overflow. 367 // Check decimal escapes doesn't overflow.
366 // (Note: \214 is interpreted as octal). 368 // (Note: \214 is interpreted as octal).
367 assertEquals("\x8c7483648", new RegExp(r"\2147483648") 369 assertEquals(
368 .firstMatch("\x8c7483648").group(0), "Overflow decimal escape"); 370 "\x8c7483648",
371 new RegExp(r"\2147483648").firstMatch("\x8c7483648").group(0),
372 "Overflow decimal escape");
369 373
370 // Check numbers in quantifiers doesn't overflow and doesn't throw on 374 // Check numbers in quantifiers doesn't overflow and doesn't throw on
371 // too large numbers. 375 // too large numbers.
372 assertFalse('b'.contains( 376 assertFalse(
373 new RegExp(r"a{111111111111111111111111111111111111111111111}")), 377 'b'.contains(
374 "overlarge1"); 378 new RegExp(r"a{111111111111111111111111111111111111111111111}")),
375 assertFalse('b'.contains( 379 "overlarge1");
376 new RegExp(r"a{999999999999999999999999999999999999999999999}")), 380 assertFalse(
377 "overlarge2"); 381 'b'.contains(
378 assertFalse('b'.contains( 382 new RegExp(r"a{999999999999999999999999999999999999999999999}")),
379 new RegExp(r"a{1,111111111111111111111111111111111111111111111}")), 383 "overlarge2");
380 "overlarge3"); 384 assertFalse(
381 assertFalse('b'.contains( 385 'b'.contains(
382 new RegExp(r"a{1,999999999999999999999999999999999999999999999}")), 386 new RegExp(r"a{1,111111111111111111111111111111111111111111111}")),
383 "overlarge4"); 387 "overlarge3");
384 assertFalse('b'.contains(new RegExp(r"a{2147483648}")), 388 assertFalse(
385 "overlarge5"); 389 'b'.contains(
386 assertFalse('b'.contains(new RegExp(r"a{21474836471}")), 390 new RegExp(r"a{1,999999999999999999999999999999999999999999999}")),
387 "overlarge6"); 391 "overlarge4");
388 assertFalse('b'.contains(new RegExp(r"a{1,2147483648}")), 392 assertFalse('b'.contains(new RegExp(r"a{2147483648}")), "overlarge5");
389 "overlarge7"); 393 assertFalse('b'.contains(new RegExp(r"a{21474836471}")), "overlarge6");
390 assertFalse('b'.contains(new RegExp(r"a{1,21474836471}")), 394 assertFalse('b'.contains(new RegExp(r"a{1,2147483648}")), "overlarge7");
391 "overlarge8"); 395 assertFalse('b'.contains(new RegExp(r"a{1,21474836471}")), "overlarge8");
392 assertFalse('b'.contains(new RegExp(r"a{2147483648,2147483648}")), 396 assertFalse(
393 "overlarge9"); 397 'b'.contains(new RegExp(r"a{2147483648,2147483648}")), "overlarge9");
394 assertFalse('b'.contains(new RegExp(r"a{21474836471,21474836471}")), 398 assertFalse(
395 "overlarge10"); 399 'b'.contains(new RegExp(r"a{21474836471,21474836471}")), "overlarge10");
396 assertFalse('b'.contains(new RegExp(r"a{2147483647}")), 400 assertFalse('b'.contains(new RegExp(r"a{2147483647}")), "overlarge11");
397 "overlarge11"); 401 assertFalse('b'.contains(new RegExp(r"a{1,2147483647}")), "overlarge12");
398 assertFalse('b'.contains(new RegExp(r"a{1,2147483647}")), 402 assertTrue('a'.contains(new RegExp(r"a{1,2147483647}")), "overlarge13");
399 "overlarge12"); 403 assertFalse(
400 assertTrue('a'.contains(new RegExp(r"a{1,2147483647}")), 404 'a'.contains(new RegExp(r"a{2147483647,2147483647}")), "overlarge14");
401 "overlarge13");
402 assertFalse('a'.contains(new RegExp(r"a{2147483647,2147483647}")),
403 "overlarge14");
404 405
405 // Check that we don't read past the end of the string. 406 // Check that we don't read past the end of the string.
406 assertFalse('b'.contains(new RegExp(r"f"))); 407 assertFalse('b'.contains(new RegExp(r"f")));
407 assertFalse('x'.contains(new RegExp(r"[abc]f"))); 408 assertFalse('x'.contains(new RegExp(r"[abc]f")));
408 assertFalse('xa'.contains(new RegExp(r"[abc]f"))); 409 assertFalse('xa'.contains(new RegExp(r"[abc]f")));
409 assertFalse('x'.contains(new RegExp(r"[abc]<"))); 410 assertFalse('x'.contains(new RegExp(r"[abc]<")));
410 assertFalse('xa'.contains(new RegExp(r"[abc]<"))); 411 assertFalse('xa'.contains(new RegExp(r"[abc]<")));
411 assertFalse('b'.contains(new RegExp(r"f", caseSensitive: false))); 412 assertFalse('b'.contains(new RegExp(r"f", caseSensitive: false)));
412 assertFalse('x'.contains(new RegExp(r"[abc]f", caseSensitive: false))); 413 assertFalse('x'.contains(new RegExp(r"[abc]f", caseSensitive: false)));
413 assertFalse('xa'.contains(new RegExp(r"[abc]f", caseSensitive: false))); 414 assertFalse('xa'.contains(new RegExp(r"[abc]f", caseSensitive: false)));
414 assertFalse('x'.contains(new RegExp(r"[abc]<", caseSensitive: false))); 415 assertFalse('x'.contains(new RegExp(r"[abc]<", caseSensitive: false)));
415 assertFalse('xa'.contains(new RegExp(r"[abc]<", caseSensitive: false))); 416 assertFalse('xa'.contains(new RegExp(r"[abc]<", caseSensitive: false)));
416 assertFalse('x'.contains(new RegExp(r"f[abc]"))); 417 assertFalse('x'.contains(new RegExp(r"f[abc]")));
417 assertFalse('xa'.contains(new RegExp(r"f[abc]"))); 418 assertFalse('xa'.contains(new RegExp(r"f[abc]")));
418 assertFalse('x'.contains(new RegExp(r"<[abc]"))); 419 assertFalse('x'.contains(new RegExp(r"<[abc]")));
419 assertFalse('xa'.contains(new RegExp(r"<[abc]"))); 420 assertFalse('xa'.contains(new RegExp(r"<[abc]")));
420 assertFalse('x'.contains(new RegExp(r"f[abc]", caseSensitive: false))); 421 assertFalse('x'.contains(new RegExp(r"f[abc]", caseSensitive: false)));
421 assertFalse('xa'.contains(new RegExp(r"f[abc]", caseSensitive: false))); 422 assertFalse('xa'.contains(new RegExp(r"f[abc]", caseSensitive: false)));
422 assertFalse('x'.contains(new RegExp(r"<[abc]", caseSensitive: false))); 423 assertFalse('x'.contains(new RegExp(r"<[abc]", caseSensitive: false)));
423 assertFalse('xa'.contains(new RegExp(r"<[abc]", caseSensitive: false))); 424 assertFalse('xa'.contains(new RegExp(r"<[abc]", caseSensitive: false)));
424 425
425 // Test that merging of quick test masks gets it right. 426 // Test that merging of quick test masks gets it right.
426 assertFalse('x7%%y'.contains(new RegExp(r"x([0-7]%%x|[0-6]%%y)")), 'qt'); 427 assertFalse('x7%%y'.contains(new RegExp(r"x([0-7]%%x|[0-6]%%y)")), 'qt');
427 assertFalse('xy7%%%y'.contains( 428 assertFalse(
428 new RegExp(r"()x\1(y([0-7]%%%x|[0-6]%%%y)|dkjasldkas)")), 'qt2'); 429 'xy7%%%y'
429 assertFalse('xy%%%y'.contains( 430 .contains(new RegExp(r"()x\1(y([0-7]%%%x|[0-6]%%%y)|dkjasldkas)")),
430 new RegExp(r"()x\1(y([0-7]%%%x|[0-6]%%%y)|dkjasldkas)")), 'qt3'); 431 'qt2');
431 assertFalse('xy7%%%y'.contains( 432 assertFalse(
432 new RegExp(r"()x\1y([0-7]%%%x|[0-6]%%%y)")), 'qt4'); 433 'xy%%%y'
433 assertFalse('xy%%%y'.contains( 434 .contains(new RegExp(r"()x\1(y([0-7]%%%x|[0-6]%%%y)|dkjasldkas)")),
434 new RegExp(r"()x\1(y([0-7]%%%x|[0-6]%%%y)|dkjasldkas)")), 'qt5'); 435 'qt3');
435 assertFalse('xy7%%%y'.contains( 436 assertFalse(
436 new RegExp(r"()x\1y([0-7]%%%x|[0-6]%%%y)")), 'qt6'); 437 'xy7%%%y'.contains(new RegExp(r"()x\1y([0-7]%%%x|[0-6]%%%y)")), 'qt4');
437 assertFalse('xy7%%%y'.contains( 438 assertFalse(
438 new RegExp(r"xy([0-7]%%%x|[0-6]%%%y)")), 'qt7'); 439 'xy%%%y'
439 assertFalse('x7%%%y'.contains(new RegExp(r"x([0-7]%%%x|[0-6]%%%y)")), 440 .contains(new RegExp(r"()x\1(y([0-7]%%%x|[0-6]%%%y)|dkjasldkas)")),
440 'qt8'); 441 'qt5');
441 442 assertFalse(
443 'xy7%%%y'.contains(new RegExp(r"()x\1y([0-7]%%%x|[0-6]%%%y)")), 'qt6');
444 assertFalse(
445 'xy7%%%y'.contains(new RegExp(r"xy([0-7]%%%x|[0-6]%%%y)")), 'qt7');
446 assertFalse('x7%%%y'.contains(new RegExp(r"x([0-7]%%%x|[0-6]%%%y)")), 'qt8');
442 447
443 // Don't hang on this one. 448 // Don't hang on this one.
444 "".contains(new RegExp(r"[^\xfe-\xff]*")); 449 "".contains(new RegExp(r"[^\xfe-\xff]*"));
445 450
446 var longbuffer = new StringBuffer("a"); 451 var longbuffer = new StringBuffer("a");
447 for (var i = 0; i < 100000; i++) { 452 for (var i = 0; i < 100000; i++) {
448 longbuffer.write("a?"); 453 longbuffer.write("a?");
449 } 454 }
450 var long = longbuffer.toString(); 455 var long = longbuffer.toString();
451 456
452 // Don't crash on this one, but maybe throw an exception. 457 // Don't crash on this one, but maybe throw an exception.
453 try { 458 try {
454 new RegExp(long).allMatches("a"); 459 new RegExp(long).allMatches("a");
455 } catch (e) { 460 } catch (e) {
456 assertTrue(e.toString().indexOf("Stack overflow") >= 0, "overflow"); 461 assertTrue(e.toString().indexOf("Stack overflow") >= 0, "overflow");
457 } 462 }
458 463
459
460 // Test boundary-checks. 464 // Test boundary-checks.
461 void assertRegExpTest(re, input, test) { 465 void assertRegExpTest(re, input, test) {
462 assertEquals(test, input.contains( 466 assertEquals(
463 new RegExp(re)), "test:" + re + ":" + input); 467 test, input.contains(new RegExp(re)), "test:" + re + ":" + input);
464 } 468 }
465 469
466 assertRegExpTest(r"b\b", "b", true); 470 assertRegExpTest(r"b\b", "b", true);
467 assertRegExpTest(r"b\b$", "b", true); 471 assertRegExpTest(r"b\b$", "b", true);
468 assertRegExpTest(r"\bb", "b", true); 472 assertRegExpTest(r"\bb", "b", true);
469 assertRegExpTest(r"^\bb", "b", true); 473 assertRegExpTest(r"^\bb", "b", true);
470 assertRegExpTest(r",\b", ",", false); 474 assertRegExpTest(r",\b", ",", false);
471 assertRegExpTest(r",\b$", ",", false); 475 assertRegExpTest(r",\b$", ",", false);
472 assertRegExpTest(r"\b,", ",", false); 476 assertRegExpTest(r"\b,", ",", false);
473 assertRegExpTest(r"^\b,", ",", false); 477 assertRegExpTest(r"^\b,", ",", false);
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 assertThrows(() => new RegExp('(?!*)')); 589 assertThrows(() => new RegExp('(?!*)'));
586 590
587 // Test trimmed regular expression for RegExp.test(). 591 // Test trimmed regular expression for RegExp.test().
588 assertTrue("abc".contains(new RegExp(r".*abc"))); 592 assertTrue("abc".contains(new RegExp(r".*abc")));
589 assertFalse("q".contains(new RegExp(r".*\d+"))); 593 assertFalse("q".contains(new RegExp(r".*\d+")));
590 594
591 // Tests skipped from V8: 595 // Tests skipped from V8:
592 // Test that RegExp.prototype.toString() throws TypeError for 596 // Test that RegExp.prototype.toString() throws TypeError for
593 // incompatible receivers (ES5 section 15.10.6 and 15.10.6.4). 597 // incompatible receivers (ES5 section 15.10.6 and 15.10.6.4).
594 } 598 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698