OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 | 5 // Flags: --harmony-regexp-named-captures |
6 | 6 |
7 // Malformed named captures. | 7 // Malformed named captures. |
8 assertThrows("/(?<>a)/u"); // Empty name. | 8 assertThrows("/(?<>a)/u"); // Empty name. |
9 assertThrows("/(?<aa)/u"); // Unterminated name. | 9 assertThrows("/(?<aa)/u"); // Unterminated name. |
10 assertThrows("/(?<42a>a)/u"); // Name starting with digits. | 10 assertThrows("/(?<42a>a)/u"); // Name starting with digits. |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 assertEquals("a", /(?<_\u200C>a)/u.exec("bab").groups._\u200C); | 90 assertEquals("a", /(?<_\u200C>a)/u.exec("bab").groups._\u200C); |
91 assertEquals("a", /(?<_\u200D>a)/u.exec("bab").groups._\u200D); | 91 assertEquals("a", /(?<_\u200D>a)/u.exec("bab").groups._\u200D); |
92 assertEquals("a", /(?<ಠ_ಠ>a)/u.exec("bab").groups.ಠ_ಠ); | 92 assertEquals("a", /(?<ಠ_ಠ>a)/u.exec("bab").groups.ಠ_ಠ); |
93 assertThrows('/(?<❤>a)/u', SyntaxError); | 93 assertThrows('/(?<❤>a)/u', SyntaxError); |
94 assertThrows('/(?<𐒤>a)/u', SyntaxError); // ID_Continue but not ID_Start. | 94 assertThrows('/(?<𐒤>a)/u', SyntaxError); // ID_Continue but not ID_Start. |
95 | 95 |
96 // The '__proto__' property on the groups object. | 96 // The '__proto__' property on the groups object. |
97 assertEquals(undefined, /(?<a>.)/u.exec("a").groups.__proto__); | 97 assertEquals(undefined, /(?<a>.)/u.exec("a").groups.__proto__); |
98 assertEquals("a", /(?<__proto__>a)/u.exec("a").groups.__proto__); | 98 assertEquals("a", /(?<__proto__>a)/u.exec("a").groups.__proto__); |
99 | 99 |
| 100 // Backreference before the group (exercises the capture mini-parser). |
| 101 assertThrows("/\\1(?:.)/u", SyntaxError); |
| 102 assertThrows("/\\1(?<=a)./u", SyntaxError); |
| 103 assertThrows("/\\1(?<!a)./u", SyntaxError); |
| 104 assertEquals(["a", "a"], /\1(?<a>.)/u.exec("abcd")); |
| 105 |
100 // @@replace with a callable replacement argument (no named captures). | 106 // @@replace with a callable replacement argument (no named captures). |
101 { | 107 { |
102 let result = "abcd".replace(/(.)(.)/u, (match, fst, snd, offset, str) => { | 108 let result = "abcd".replace(/(.)(.)/u, (match, fst, snd, offset, str) => { |
103 assertEquals("ab", match); | 109 assertEquals("ab", match); |
104 assertEquals("a", fst); | 110 assertEquals("a", fst); |
105 assertEquals("b", snd); | 111 assertEquals("b", snd); |
106 assertEquals(0, offset); | 112 assertEquals(0, offset); |
107 assertEquals("abcd", str); | 113 assertEquals("abcd", str); |
108 return `${snd}${fst}`; | 114 return `${snd}${fst}`; |
109 }); | 115 }); |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 // named captures). | 282 // named captures). |
277 { | 283 { |
278 let re = toSlowMode(/(?<fst>.)(?<snd>.)/u); | 284 let re = toSlowMode(/(?<fst>.)(?<snd>.)/u); |
279 assertEquals("bacd", "abcd".replace(re, "$<snd>$<fst>")); | 285 assertEquals("bacd", "abcd".replace(re, "$<snd>$<fst>")); |
280 assertEquals("bacd", "abcd".replace(re, "$2$1")); | 286 assertEquals("bacd", "abcd".replace(re, "$2$1")); |
281 assertThrows(() => "abcd".replace(re, "$<snd"), SyntaxError); | 287 assertThrows(() => "abcd".replace(re, "$<snd"), SyntaxError); |
282 assertEquals("cd", "abcd".replace(re, "$<42$1>")); | 288 assertEquals("cd", "abcd".replace(re, "$<42$1>")); |
283 assertEquals("cd", "abcd".replace(re, "$<thd>")); | 289 assertEquals("cd", "abcd".replace(re, "$<thd>")); |
284 assertEquals("cd", "abcd".replace(re, "$<$1>")); | 290 assertEquals("cd", "abcd".replace(re, "$<$1>")); |
285 } | 291 } |
OLD | NEW |