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 | |
151 re = /[\s]/; | 113 re = /[\s]/; |
152 assertFalse(re.test('-')); | 114 assertFalse(re.test('-')); |
153 assertFalse(re.test(':')); | 115 assertFalse(re.test(':')); |
154 assertTrue(re.test(' ')); | 116 assertTrue(re.test(' ')); |
155 assertTrue(re.test('\t')); | 117 assertTrue(re.test('\t')); |
156 assertTrue(re.test('\n')); | 118 assertTrue(re.test('\n')); |
157 assertFalse(re.test('a')); | 119 assertFalse(re.test('a')); |
158 assertFalse(re.test('Z')); | 120 assertFalse(re.test('Z')); |
159 | 121 |
160 re = /[^\s]/; | 122 re = /[^\s]/; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 | 157 |
196 re = /[^\s\S]/; | 158 re = /[^\s\S]/; |
197 assertFalse(re.test('-')); | 159 assertFalse(re.test('-')); |
198 assertFalse(re.test(':')); | 160 assertFalse(re.test(':')); |
199 assertFalse(re.test(' ')); | 161 assertFalse(re.test(' ')); |
200 assertFalse(re.test('\t')); | 162 assertFalse(re.test('\t')); |
201 assertFalse(re.test('\n')); | 163 assertFalse(re.test('\n')); |
202 assertFalse(re.test('a')); | 164 assertFalse(re.test('a')); |
203 assertFalse(re.test('Z')); | 165 assertFalse(re.test('Z')); |
204 | 166 |
205 // First - is treated as range operator, second as literal minus. | |
206 // This follows the specification in parsing, but doesn't throw on | |
207 // the \s at the beginning of the range. | |
208 re = /[\s-0-9]/; | |
209 assertTrue(re.test(' ')); | |
210 assertTrue(re.test('\xA0')); | |
211 assertTrue(re.test('-')); | |
212 assertTrue(re.test('0')); | |
213 assertTrue(re.test('9')); | |
214 assertFalse(re.test('1')); | |
215 | |
216 // Test beginning and end of line assertions with or without the | 167 // Test beginning and end of line assertions with or without the |
217 // multiline flag. | 168 // multiline flag. |
218 re = /^\d+/; | 169 re = /^\d+/; |
219 assertFalse(re.test("asdf\n123")); | 170 assertFalse(re.test("asdf\n123")); |
220 re = /^\d+/m; | 171 re = /^\d+/m; |
221 assertTrue(re.test("asdf\n123")); | 172 assertTrue(re.test("asdf\n123")); |
222 | 173 |
223 re = /\d+$/; | 174 re = /\d+$/; |
224 assertFalse(re.test("123\nasdf")); | 175 assertFalse(re.test("123\nasdf")); |
225 re = /\d+$/m; | 176 re = /\d+$/m; |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 // Only partially anchored. | 603 // Only partially anchored. |
653 var re = /(?:a|bc$)/; | 604 var re = /(?:a|bc$)/; |
654 assertTrue(re.test("a")); | 605 assertTrue(re.test("a")); |
655 assertTrue(re.test("bc")); | 606 assertTrue(re.test("bc")); |
656 assertEquals(["a"], re.exec("abc")); | 607 assertEquals(["a"], re.exec("abc")); |
657 assertEquals(4, re.exec("zimzamzumba").index); | 608 assertEquals(4, re.exec("zimzamzumba").index); |
658 assertEquals(["bc"], re.exec("zimzomzumbc")); | 609 assertEquals(["bc"], re.exec("zimzomzumbc")); |
659 assertFalse(re.test("c")); | 610 assertFalse(re.test("c")); |
660 assertFalse(re.test("")); | 611 assertFalse(re.test("")); |
661 | 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 |