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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 | 195 |
158 re = /[^\s\S]/; | 196 re = /[^\s\S]/; |
159 assertFalse(re.test('-')); | 197 assertFalse(re.test('-')); |
160 assertFalse(re.test(':')); | 198 assertFalse(re.test(':')); |
161 assertFalse(re.test(' ')); | 199 assertFalse(re.test(' ')); |
162 assertFalse(re.test('\t')); | 200 assertFalse(re.test('\t')); |
163 assertFalse(re.test('\n')); | 201 assertFalse(re.test('\n')); |
164 assertFalse(re.test('a')); | 202 assertFalse(re.test('a')); |
165 assertFalse(re.test('Z')); | 203 assertFalse(re.test('Z')); |
166 | 204 |
| 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 |
167 // Test beginning and end of line assertions with or without the | 216 // Test beginning and end of line assertions with or without the |
168 // multiline flag. | 217 // multiline flag. |
169 re = /^\d+/; | 218 re = /^\d+/; |
170 assertFalse(re.test("asdf\n123")); | 219 assertFalse(re.test("asdf\n123")); |
171 re = /^\d+/m; | 220 re = /^\d+/m; |
172 assertTrue(re.test("asdf\n123")); | 221 assertTrue(re.test("asdf\n123")); |
173 | 222 |
174 re = /\d+$/; | 223 re = /\d+$/; |
175 assertFalse(re.test("123\nasdf")); | 224 assertFalse(re.test("123\nasdf")); |
176 re = /\d+$/m; | 225 re = /\d+$/m; |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 // Only partially anchored. | 652 // Only partially anchored. |
604 var re = /(?:a|bc$)/; | 653 var re = /(?:a|bc$)/; |
605 assertTrue(re.test("a")); | 654 assertTrue(re.test("a")); |
606 assertTrue(re.test("bc")); | 655 assertTrue(re.test("bc")); |
607 assertEquals(["a"], re.exec("abc")); | 656 assertEquals(["a"], re.exec("abc")); |
608 assertEquals(4, re.exec("zimzamzumba").index); | 657 assertEquals(4, re.exec("zimzamzumba").index); |
609 assertEquals(["bc"], re.exec("zimzomzumbc")); | 658 assertEquals(["bc"], re.exec("zimzomzumbc")); |
610 assertFalse(re.test("c")); | 659 assertFalse(re.test("c")); |
611 assertFalse(re.test("")); | 660 assertFalse(re.test("")); |
612 | 661 |
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 |