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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 assertFalse(re.test("\x03")); // I.e., read as \cc | 103 assertFalse(re.test("\x03")); // I.e., read as \cc |
104 | 104 |
105 re = /^[\c]]$/; | 105 re = /^[\c]]$/; |
106 assertTrue(re.test("c]")); | 106 assertTrue(re.test("c]")); |
107 assertFalse(re.test("\\]")); | 107 assertFalse(re.test("\\]")); |
108 assertFalse(re.test("\x1d")); // ']' & 0x1f | 108 assertFalse(re.test("\x1d")); // ']' & 0x1f |
109 assertFalse(re.test("\\]")); | 109 assertFalse(re.test("\\]")); |
110 assertFalse(re.test("\x03]")); // I.e., read as \cc | 110 assertFalse(re.test("\x03]")); // I.e., read as \cc |
111 | 111 |
112 | 112 |
| 113 // Test that we handle \s and \S correctly inside some bizarre |
| 114 // character classes. |
| 115 re = /[\s-:]/; |
| 116 assertTrue(re.test('-')); |
| 117 assertTrue(re.test(':')); |
| 118 assertTrue(re.test(' ')); |
| 119 assertTrue(re.test('\t')); |
| 120 assertTrue(re.test('\n')); |
| 121 assertFalse(re.test('a')); |
| 122 assertFalse(re.test('Z')); |
| 123 |
| 124 re = /[\S-:]/; |
| 125 assertTrue(re.test('-')); |
| 126 assertTrue(re.test(':')); |
| 127 assertFalse(re.test(' ')); |
| 128 assertFalse(re.test('\t')); |
| 129 assertFalse(re.test('\n')); |
| 130 assertTrue(re.test('a')); |
| 131 assertTrue(re.test('Z')); |
| 132 |
| 133 re = /[^\s-:]/; |
| 134 assertFalse(re.test('-')); |
| 135 assertFalse(re.test(':')); |
| 136 assertFalse(re.test(' ')); |
| 137 assertFalse(re.test('\t')); |
| 138 assertFalse(re.test('\n')); |
| 139 assertTrue(re.test('a')); |
| 140 assertTrue(re.test('Z')); |
| 141 |
| 142 re = /[^\S-:]/; |
| 143 assertFalse(re.test('-')); |
| 144 assertFalse(re.test(':')); |
| 145 assertTrue(re.test(' ')); |
| 146 assertTrue(re.test('\t')); |
| 147 assertTrue(re.test('\n')); |
| 148 assertFalse(re.test('a')); |
| 149 assertFalse(re.test('Z')); |
| 150 |
113 re = /[\s]/; | 151 re = /[\s]/; |
114 assertFalse(re.test('-')); | 152 assertFalse(re.test('-')); |
115 assertFalse(re.test(':')); | 153 assertFalse(re.test(':')); |
116 assertTrue(re.test(' ')); | 154 assertTrue(re.test(' ')); |
117 assertTrue(re.test('\t')); | 155 assertTrue(re.test('\t')); |
118 assertTrue(re.test('\n')); | 156 assertTrue(re.test('\n')); |
119 assertFalse(re.test('a')); | 157 assertFalse(re.test('a')); |
120 assertFalse(re.test('Z')); | 158 assertFalse(re.test('Z')); |
121 | 159 |
122 re = /[^\s]/; | 160 re = /[^\s]/; |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 | 640 |
603 // Only partially anchored. | 641 // Only partially anchored. |
604 var re = /(?:a|bc$)/; | 642 var re = /(?:a|bc$)/; |
605 assertTrue(re.test("a")); | 643 assertTrue(re.test("a")); |
606 assertTrue(re.test("bc")); | 644 assertTrue(re.test("bc")); |
607 assertEquals(["a"], re.exec("abc")); | 645 assertEquals(["a"], re.exec("abc")); |
608 assertEquals(4, re.exec("zimzamzumba").index); | 646 assertEquals(4, re.exec("zimzamzumba").index); |
609 assertEquals(["bc"], re.exec("zimzomzumbc")); | 647 assertEquals(["bc"], re.exec("zimzomzumbc")); |
610 assertFalse(re.test("c")); | 648 assertFalse(re.test("c")); |
611 assertFalse(re.test("")); | 649 assertFalse(re.test("")); |
612 | |
613 | |
614 function testInvalidRange(str) { | |
615 try { | |
616 RegExp(str).test("x"); | |
617 } catch (e) { | |
618 return; | |
619 } | |
620 assetUnreachable("Allowed invalid range in " + str); | |
621 } | |
622 | |
623 function testValidRange(str) { | |
624 try { | |
625 RegExp(str).test("x"); | |
626 } catch (e) { | |
627 assertUnreachable("Shouldn't fail parsing: " + str + ", was: " + e); | |
628 } | |
629 } | |
630 | |
631 testInvalidRange("[\\d-z]"); | |
632 testInvalidRange("[z-\\d]"); | |
633 testInvalidRange("[\\d-\\d]"); | |
634 testInvalidRange("[z-x]"); // Larger value first. | |
635 testInvalidRange("[x-\\d-\\d]"); | |
636 | |
637 testValidRange("[x-z]"); | |
638 testValidRange("[!--\d]"); // Second "-" is end of range. | |
639 testValidRange("[\d-]"); | |
640 testValidRange("[-\d]"); | |
641 testValidRange("[-\d-]"); | |
642 testValidRange("[^-\d-]"); | |
643 testValidRange("[^-\d-]"); | |
644 testValidRange("[0-9-\w]"); | |
645 | |
646 // Escaped dashes do not count as range operators. | |
647 testValidRange("[\\d\\-z]"); | |
648 testValidRange("[z\\-\\d]"); | |
649 testValidRange("[\\d\\-\\d]"); | |
650 testValidRange("[z\\-x]"); | |
651 testValidRange("[x\\-\\d\\-\\d]"); | |
652 | |
653 | |
654 | |
655 | |
OLD | NEW |