OLD | NEW |
1 // Copyright 2017 the V8 project authors. All rights reserved. | 1 // Copyright 2017 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --harmony-regexp-named-captures --harmony-regexp-lookbehind | 5 // Flags: --harmony-regexp-named-captures --harmony-regexp-lookbehind |
6 | 6 |
7 // Malformed named captures. | 7 // Malformed named captures. |
8 assertThrows("/(?<>a)/u", SyntaxError); // Empty name. | 8 assertThrows("/(?<>a)/u", SyntaxError); // Empty name. |
9 assertThrows("/(?<aa)/u", SyntaxError); // Unterminated name. | 9 assertThrows("/(?<aa)/u", SyntaxError); // Unterminated name. |
10 assertThrows("/(?<42a>a)/u", SyntaxError); // Name starting with digits. | 10 assertThrows("/(?<42a>a)/u", SyntaxError); // Name starting with digits. |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 assertEquals(["a", "a"], /\1(?<a>.)/u.exec("abcd")); | 188 assertEquals(["a", "a"], /\1(?<a>.)/u.exec("abcd")); |
189 | 189 |
190 // Unicode escapes in capture names. | 190 // Unicode escapes in capture names. |
191 assertTrue(/(?<a\uD801\uDCA4>.)/u.test("a")); // \u Lead \u Trail | 191 assertTrue(/(?<a\uD801\uDCA4>.)/u.test("a")); // \u Lead \u Trail |
192 assertThrows("/(?<a\\uD801>.)/u", SyntaxError); // \u Lead | 192 assertThrows("/(?<a\\uD801>.)/u", SyntaxError); // \u Lead |
193 assertThrows("/(?<a\\uDCA4>.)/u", SyntaxError); // \u Trail | 193 assertThrows("/(?<a\\uDCA4>.)/u", SyntaxError); // \u Trail |
194 assertTrue(/(?<\u0041>.)/u.test("a")); // \u NonSurrogate | 194 assertTrue(/(?<\u0041>.)/u.test("a")); // \u NonSurrogate |
195 assertTrue(/(?<\u{0041}>.)/u.test("a")); // \u{ Non-surrogate } | 195 assertTrue(/(?<\u{0041}>.)/u.test("a")); // \u{ Non-surrogate } |
196 assertTrue(/(?<a\u{104A4}>.)/u.test("a")); // \u{ Surrogate, ID_Continue } | 196 assertTrue(/(?<a\u{104A4}>.)/u.test("a")); // \u{ Surrogate, ID_Continue } |
197 assertThrows("/(?<a\\u{110000}>.)/u", SyntaxError); // \u{ Out-of-bounds } | 197 assertThrows("/(?<a\\u{110000}>.)/u", SyntaxError); // \u{ Out-of-bounds } |
| 198 assertThrows("/(?<a\\uD801>.)/u", SyntaxError); // Lead |
| 199 assertThrows("/(?<a\\uDCA4>.)/u", SyntaxError); // Trail |
198 assertThrows("/(?<a\uD801>.)/u", SyntaxError); // Lead | 200 assertThrows("/(?<a\uD801>.)/u", SyntaxError); // Lead |
199 assertThrows("/(?<a\uDCA4>.)/u", SyntaxError); // Trail | 201 assertThrows("/(?<a\uDCA4>.)/u", SyntaxError); // Trail |
| 202 assertTrue(RegExp("(?<\\u{0041}>.)", "u").test("a")); // Non-surrogate |
| 203 assertTrue(RegExp("(?<a\\u{104A4}>.)", "u").test("a")); // Surrogate,ID_Continu
e |
200 assertTrue(RegExp("(?<\u{0041}>.)", "u").test("a")); // Non-surrogate | 204 assertTrue(RegExp("(?<\u{0041}>.)", "u").test("a")); // Non-surrogate |
201 assertTrue(RegExp("(?<a\u{104A4}>.)", "u").test("a")); // Surrogate,ID_Continue | 205 assertTrue(RegExp("(?<a\u{104A4}>.)", "u").test("a")); // Surrogate,ID_Continue |
| 206 assertTrue(RegExp("(?<\\u0041>.)", "u").test("a")); // Non-surrogate |
202 | 207 |
203 assertThrows("/(?<a\\uD801\uDCA4>.)/", SyntaxError); | 208 assertThrows("/(?<a\\uD801\uDCA4>.)/", SyntaxError); |
204 assertThrows("/(?<a\\uD801>.)/", SyntaxError); | 209 assertThrows("/(?<a\\uD801>.)/", SyntaxError); |
205 assertThrows("/(?<a\\uDCA4>.)/", SyntaxError); | 210 assertThrows("/(?<a\\uDCA4>.)/", SyntaxError); |
206 assertTrue(/(?<\u0041>.)/.test("a")); | 211 assertTrue(/(?<\u0041>.)/.test("a")); |
207 assertThrows("/(?<\\u{0041}>.)/", SyntaxError); | 212 assertThrows("/(?<\\u{0041}>.)/", SyntaxError); |
208 assertThrows("/(?<a\\u{104A4}>.)/", SyntaxError); | 213 assertThrows("/(?<a\\u{104A4}>.)/", SyntaxError); |
209 assertThrows("/(?<a\\u{10FFFF}>.)/", SyntaxError); | 214 assertThrows("/(?<a\\u{10FFFF}>.)/", SyntaxError); |
| 215 assertThrows("/(?<a\\uD801>.)/", SyntaxError); // Lead |
| 216 assertThrows("/(?<a\\uDCA4>.)/", SyntaxError); // Trail; |
210 assertThrows("/(?<a\uD801>.)/", SyntaxError); // Lead | 217 assertThrows("/(?<a\uD801>.)/", SyntaxError); // Lead |
211 assertThrows("/(?<a\uDCA4>.)/", SyntaxError); // Trail | 218 assertThrows("/(?<a\uDCA4>.)/", SyntaxError); // Trail |
| 219 assertThrows("/(?<\\u{0041}>.)/", SyntaxError); // Non-surrogate |
| 220 assertThrows("/(?<a\\u{104A4}>.)/", SyntaxError); // Surrogate, ID_Continue |
212 assertTrue(RegExp("(?<\u{0041}>.)").test("a")); // Non-surrogate | 221 assertTrue(RegExp("(?<\u{0041}>.)").test("a")); // Non-surrogate |
213 assertTrue(RegExp("(?<a\u{104A4}>.)").test("a")); // Surrogate, ID_Continue | 222 assertTrue(RegExp("(?<a\u{104A4}>.)").test("a")); // Surrogate, ID_Continue |
| 223 assertTrue(RegExp("(?<\\u0041>.)").test("a")); // Non-surrogate |
214 | 224 |
215 // @@replace with a callable replacement argument (no named captures). | 225 // @@replace with a callable replacement argument (no named captures). |
216 { | 226 { |
217 let result = "abcd".replace(/(.)(.)/u, (match, fst, snd, offset, str) => { | 227 let result = "abcd".replace(/(.)(.)/u, (match, fst, snd, offset, str) => { |
218 assertEquals("ab", match); | 228 assertEquals("ab", match); |
219 assertEquals("a", fst); | 229 assertEquals("a", fst); |
220 assertEquals("b", snd); | 230 assertEquals("b", snd); |
221 assertEquals(0, offset); | 231 assertEquals(0, offset); |
222 assertEquals("abcd", str); | 232 assertEquals("abcd", str); |
223 return `${snd}${fst}`; | 233 return `${snd}${fst}`; |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 { | 406 { |
397 let re = toSlowMode(/(?<fst>.)(?<snd>.)|(?<thd>x)/u); | 407 let re = toSlowMode(/(?<fst>.)(?<snd>.)|(?<thd>x)/u); |
398 assertEquals("bacd", "abcd".replace(re, "$<snd>$<fst>")); | 408 assertEquals("bacd", "abcd".replace(re, "$<snd>$<fst>")); |
399 assertEquals("bacd", "abcd".replace(re, "$2$1")); | 409 assertEquals("bacd", "abcd".replace(re, "$2$1")); |
400 assertEquals("cd", "abcd".replace(re, "$<thd>")); | 410 assertEquals("cd", "abcd".replace(re, "$<thd>")); |
401 assertThrows(() => "abcd".replace(re, "$<snd"), SyntaxError); | 411 assertThrows(() => "abcd".replace(re, "$<snd"), SyntaxError); |
402 assertThrows(() => "abcd".replace(re, "$<42$1>"), SyntaxError); | 412 assertThrows(() => "abcd".replace(re, "$<42$1>"), SyntaxError); |
403 assertThrows(() => "abcd".replace(re, "$<fth>"), SyntaxError); | 413 assertThrows(() => "abcd".replace(re, "$<fth>"), SyntaxError); |
404 assertThrows(() => "abcd".replace(re, "$<$1>"), SyntaxError); | 414 assertThrows(() => "abcd".replace(re, "$<$1>"), SyntaxError); |
405 } | 415 } |
OLD | NEW |