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

Side by Side Diff: test/mjsunit/regexp.js

Issue 6869007: Cleanup of mjsunit.js code and make assertEquals more strict. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed review comments Created 9 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 | Annotate | Revision Log
« no previous file with comments | « test/mjsunit/override-eval-with-non-function.js ('k') | test/mjsunit/regexp-capture.js » ('j') | 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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 assertTrue(test, testName); 326 assertTrue(test, testName);
327 } else { 327 } else {
328 assertFalse(test, testName); 328 assertFalse(test, testName);
329 } 329 }
330 } 330 }
331 331
332 assertFalse(/f(o)$\1/.test('foo'), "backref detects at_end"); 332 assertFalse(/f(o)$\1/.test('foo'), "backref detects at_end");
333 333
334 // Check decimal escapes doesn't overflow. 334 // Check decimal escapes doesn't overflow.
335 // (Note: \214 is interpreted as octal). 335 // (Note: \214 is interpreted as octal).
336 assertEquals(/\2147483648/.exec("\x8c7483648"), 336 assertArrayEquals(["\x8c7483648"],
337 ["\x8c7483648"], 337 /\2147483648/.exec("\x8c7483648"),
338 "Overflow decimal escape"); 338 "Overflow decimal escape");
339 339
340 340
341 // Check numbers in quantifiers doesn't overflow and doesn't throw on 341 // Check numbers in quantifiers doesn't overflow and doesn't throw on
342 // too large numbers. 342 // too large numbers.
343 assertFalse(/a{111111111111111111111111111111111111111111111}/.test('b'), 343 assertFalse(/a{111111111111111111111111111111111111111111111}/.test('b'),
344 "overlarge1"); 344 "overlarge1");
345 assertFalse(/a{999999999999999999999999999999999999999999999}/.test('b'), 345 assertFalse(/a{999999999999999999999999999999999999999999999}/.test('b'),
346 "overlarge2"); 346 "overlarge2");
347 assertFalse(/a{1,111111111111111111111111111111111111111111111}/.test('b'), 347 assertFalse(/a{1,111111111111111111111111111111111111111111111}/.test('b'),
348 "overlarge3"); 348 "overlarge3");
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 re.compile("ro+", "gim"); 428 re.compile("ro+", "gim");
429 assertEquals("ro+", re.source); 429 assertEquals("ro+", re.source);
430 assertTrue(re.global); 430 assertTrue(re.global);
431 assertTrue(re.ignoreCase); 431 assertTrue(re.ignoreCase);
432 assertTrue(re.multiline); 432 assertTrue(re.multiline);
433 assertEquals(0, re.lastIndex); 433 assertEquals(0, re.lastIndex);
434 434
435 re.lastIndex = 42; 435 re.lastIndex = 42;
436 re.someOtherProperty = 42; 436 re.someOtherProperty = 42;
437 re.someDeletableProperty = 42; 437 re.someDeletableProperty = 42;
438 re[37] = 37; 438 re[37] = 37;
439 re[42] = 42; 439 re[42] = 42;
440 440
441 re.compile("ra+", "i"); 441 re.compile("ra+", "i");
442 assertEquals("ra+", re.source); 442 assertEquals("ra+", re.source);
443 assertFalse(re.global); 443 assertFalse(re.global);
444 assertTrue(re.ignoreCase); 444 assertTrue(re.ignoreCase);
445 assertFalse(re.multiline); 445 assertFalse(re.multiline);
446 assertEquals(0, re.lastIndex); 446 assertEquals(0, re.lastIndex);
447 447
448 assertEquals(42, re.someOtherProperty); 448 assertEquals(42, re.someOtherProperty);
449 assertEquals(42, re.someDeletableProperty); 449 assertEquals(42, re.someDeletableProperty);
450 assertEquals(37, re[37]); 450 assertEquals(37, re[37]);
451 assertEquals(42, re[42]); 451 assertEquals(42, re[42]);
452 452
453 re.lastIndex = -1; 453 re.lastIndex = -1;
454 re.someOtherProperty = 37; 454 re.someOtherProperty = 37;
455 re[42] = 37; 455 re[42] = 37;
456 assertTrue(delete re[37]); 456 assertTrue(delete re[37]);
457 assertTrue(delete re.someDeletableProperty); 457 assertTrue(delete re.someDeletableProperty);
458 re.compile("ri+", "gm"); 458 re.compile("ri+", "gm");
459 459
460 assertEquals("ri+", re.source); 460 assertEquals("ri+", re.source);
461 assertTrue(re.global); 461 assertTrue(re.global);
462 assertFalse(re.ignoreCase); 462 assertFalse(re.ignoreCase);
463 assertTrue(re.multiline); 463 assertTrue(re.multiline);
464 assertEquals(0, re.lastIndex); 464 assertEquals(0, re.lastIndex);
465 assertEquals(37, re.someOtherProperty); 465 assertEquals(37, re.someOtherProperty);
466 assertEquals(37, re[42]); 466 assertEquals(37, re[42]);
467 467
468 // Test boundary-checks. 468 // Test boundary-checks.
469 function assertRegExpTest(re, input, test) { 469 function assertRegExpTest(re, input, test) {
470 assertEquals(test, re.test(input), "test:" + re + ":" + input); 470 assertEquals(test, re.test(input), "test:" + re + ":" + input);
471 } 471 }
472 472
473 assertRegExpTest(/b\b/, "b", true); 473 assertRegExpTest(/b\b/, "b", true);
474 assertRegExpTest(/b\b$/, "b", true); 474 assertRegExpTest(/b\b$/, "b", true);
475 assertRegExpTest(/\bb/, "b", true); 475 assertRegExpTest(/\bb/, "b", true);
476 assertRegExpTest(/^\bb/, "b", true); 476 assertRegExpTest(/^\bb/, "b", true);
477 assertRegExpTest(/,\b/, ",", false); 477 assertRegExpTest(/,\b/, ",", false);
478 assertRegExpTest(/,\b$/, ",", false); 478 assertRegExpTest(/,\b$/, ",", false);
479 assertRegExpTest(/\b,/, ",", false); 479 assertRegExpTest(/\b,/, ",", false);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 for (var i = 0; i < 100; i++) { 518 for (var i = 0; i < 100; i++) {
519 var re = /x(y)z/; 519 var re = /x(y)z/;
520 var res = re.exec("axyzb"); 520 var res = re.exec("axyzb");
521 assertTrue(!!res); 521 assertTrue(!!res);
522 assertEquals(2, res.length); 522 assertEquals(2, res.length);
523 assertEquals("xyz", res[0]); 523 assertEquals("xyz", res[0]);
524 assertEquals("y", res[1]); 524 assertEquals("y", res[1]);
525 assertEquals(1, res.index); 525 assertEquals(1, res.index);
526 assertEquals("axyzb", res.input); 526 assertEquals("axyzb", res.input);
527 assertEquals(undefined, res.foobar); 527 assertEquals(undefined, res.foobar);
528 528
529 res.foobar = "Arglebargle"; 529 res.foobar = "Arglebargle";
530 res[3] = "Glopglyf"; 530 res[3] = "Glopglyf";
531 assertEquals("Arglebargle", res.foobar); 531 assertEquals("Arglebargle", res.foobar);
532 } 532 }
533 533
534 // Test that we perform the spec required conversions in the correct order. 534 // Test that we perform the spec required conversions in the correct order.
535 var log; 535 var log;
536 var string = "the string"; 536 var string = "the string";
537 var fakeLastIndex = { 537 var fakeLastIndex = {
538 valueOf: function() { 538 valueOf: function() {
539 log.push("li"); 539 log.push("li");
540 return 0; 540 return 0;
541 } 541 }
542 }; 542 };
543 var fakeString = { 543 var fakeString = {
544 toString: function() { 544 toString: function() {
545 log.push("ts"); 545 log.push("ts");
546 return string; 546 return string;
547 }, 547 },
548 length: 0 548 length: 0
549 }; 549 };
550 550
551 var re = /str/; 551 var re = /str/;
552 log = []; 552 log = [];
553 re.lastIndex = fakeLastIndex; 553 re.lastIndex = fakeLastIndex;
554 var result = re.exec(fakeString); 554 var result = re.exec(fakeString);
555 assertEquals(["str"], result); 555 assertEquals(["str"], result);
556 assertEquals(["ts", "li"], log); 556 assertEquals(["ts", "li"], log);
557 557
558 // Again, to check if caching interferes. 558 // Again, to check if caching interferes.
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 // Syntax extension relative to ES5, for matching JSC (and ES3). 683 // Syntax extension relative to ES5, for matching JSC (and ES3).
684 // Shouldn't throw. 684 // Shouldn't throw.
685 re = RegExp("(?=x)*"); 685 re = RegExp("(?=x)*");
686 re = RegExp("(?!x)*"); 686 re = RegExp("(?!x)*");
687 687
688 // Should throw. Shouldn't hit asserts in debug mode. 688 // Should throw. Shouldn't hit asserts in debug mode.
689 assertThrows("RegExp('(*)')"); 689 assertThrows("RegExp('(*)')");
690 assertThrows("RegExp('(?:*)')"); 690 assertThrows("RegExp('(?:*)')");
691 assertThrows("RegExp('(?=*)')"); 691 assertThrows("RegExp('(?=*)')");
692 assertThrows("RegExp('(?!*)')"); 692 assertThrows("RegExp('(?!*)')");
OLDNEW
« no previous file with comments | « test/mjsunit/override-eval-with-non-function.js ('k') | test/mjsunit/regexp-capture.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698