OLD | NEW |
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 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 assertEquals(false, desc.value); | 582 assertEquals(false, desc.value); |
583 assertEquals(false, desc.configurable); | 583 assertEquals(false, desc.configurable); |
584 assertEquals(false, desc.enumerable); | 584 assertEquals(false, desc.enumerable); |
585 assertEquals(false, desc.writable); | 585 assertEquals(false, desc.writable); |
586 | 586 |
587 desc = Object.getOwnPropertyDescriptor(re, "lastIndex"); | 587 desc = Object.getOwnPropertyDescriptor(re, "lastIndex"); |
588 assertEquals(0, desc.value); | 588 assertEquals(0, desc.value); |
589 assertEquals(false, desc.configurable); | 589 assertEquals(false, desc.configurable); |
590 assertEquals(false, desc.enumerable); | 590 assertEquals(false, desc.enumerable); |
591 assertEquals(true, desc.writable); | 591 assertEquals(true, desc.writable); |
| 592 |
| 593 |
| 594 // Check that end-anchored regexps are optimized correctly. |
| 595 var re = /(?:a|bc)g$/; |
| 596 assertTrue(re.test("ag")); |
| 597 assertTrue(re.test("bcg")); |
| 598 assertTrue(re.test("abcg")); |
| 599 assertTrue(re.test("zimbag")); |
| 600 assertTrue(re.test("zimbcg")); |
| 601 |
| 602 assertFalse(re.test("g")); |
| 603 assertFalse(re.test("")); |
| 604 |
| 605 // Global regexp (non-zero start). |
| 606 var re = /(?:a|bc)g$/g; |
| 607 assertTrue(re.test("ag")); |
| 608 re.lastIndex = 1; // Near start of string. |
| 609 assertTrue(re.test("zimbag")); |
| 610 re.lastIndex = 6; // At end of string. |
| 611 assertFalse(re.test("zimbag")); |
| 612 re.lastIndex = 5; // Near end of string. |
| 613 assertFalse(re.test("zimbag")); |
| 614 re.lastIndex = 4; |
| 615 assertTrue(re.test("zimbag")); |
| 616 |
| 617 // Anchored at both ends. |
| 618 var re = /^(?:a|bc)g$/g; |
| 619 assertTrue(re.test("ag")); |
| 620 re.lastIndex = 1; |
| 621 assertFalse(re.test("ag")); |
| 622 re.lastIndex = 1; |
| 623 assertFalse(re.test("zag")); |
| 624 |
| 625 // Long max_length of RegExp. |
| 626 var re = /VeryLongRegExp!{1,1000}$/; |
| 627 assertTrue(re.test("BahoolaVeryLongRegExp!!!!!!")); |
| 628 assertFalse(re.test("VeryLongRegExp")); |
| 629 assertFalse(re.test("!")); |
| 630 |
| 631 // End anchor inside disjunction. |
| 632 var re = /(?:a$|bc$)/; |
| 633 assertTrue(re.test("a")); |
| 634 assertTrue(re.test("bc")); |
| 635 assertTrue(re.test("abc")); |
| 636 assertTrue(re.test("zimzamzumba")); |
| 637 assertTrue(re.test("zimzamzumbc")); |
| 638 assertFalse(re.test("c")); |
| 639 assertFalse(re.test("")); |
| 640 |
| 641 // Only partially anchored. |
| 642 var re = /(?:a|bc$)/; |
| 643 assertTrue(re.test("a")); |
| 644 assertTrue(re.test("bc")); |
| 645 assertEquals(["a"], re.exec("abc")); |
| 646 assertEquals(4, re.exec("zimzamzumba").index); |
| 647 assertEquals(["bc"], re.exec("zimzomzumbc")); |
| 648 assertFalse(re.test("c")); |
| 649 assertFalse(re.test("")); |
OLD | NEW |