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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 // The '__proto__' property on the groups object. | 176 // The '__proto__' property on the groups object. |
177 assertEquals(undefined, /(?<a>.)/u.exec("a").groups.__proto__); | 177 assertEquals(undefined, /(?<a>.)/u.exec("a").groups.__proto__); |
178 assertEquals("a", /(?<__proto__>a)/u.exec("a").groups.__proto__); | 178 assertEquals("a", /(?<__proto__>a)/u.exec("a").groups.__proto__); |
179 | 179 |
180 // Backreference before the group (exercises the capture mini-parser). | 180 // Backreference before the group (exercises the capture mini-parser). |
181 assertThrows("/\\1(?:.)/u", SyntaxError); | 181 assertThrows("/\\1(?:.)/u", SyntaxError); |
182 assertThrows("/\\1(?<=a)./u", SyntaxError); | 182 assertThrows("/\\1(?<=a)./u", SyntaxError); |
183 assertThrows("/\\1(?<!a)./u", SyntaxError); | 183 assertThrows("/\\1(?<!a)./u", SyntaxError); |
184 assertEquals(["a", "a"], /\1(?<a>.)/u.exec("abcd")); | 184 assertEquals(["a", "a"], /\1(?<a>.)/u.exec("abcd")); |
185 | 185 |
186 // Unicode escapes in capture names. | |
187 assertTrue(/(?<a\uD801\uDCA4>.)/u.test("a")); // \u Lead \u Trail | |
188 assertThrows("/(?<a\\uD801>.)/u", SyntaxError); // \u Lead | |
Yang
2017/04/05 08:03:35
Also test the case where you don't use the \u esca
jgruber
2017/04/07 08:01:23
You mean just a standard group name? "/(?<a\uD801>
jgruber
2017/04/07 08:02:54
Never mind, it's not. Will add a test.
| |
189 assertThrows("/(?<a\\uDCA4>.)/u", SyntaxError); // \u Trail | |
190 assertTrue(/(?<\u0041>.)/u.test("a")); // \u NonSurrogate | |
191 assertTrue(/(?<\u{0041}>.)/u.test("a")); // \u{ Non-surrogate } | |
192 assertTrue(/(?<a\u{104A4}>.)/u.test("a")); // \u{ Surrogate, ID_Continue } | |
193 assertThrows("/(?<a\\u{110000}>.)/u", SyntaxError); // \u{ Out-of-bounds } | |
194 | |
195 assertThrows("/(?<a\\uD801\uDCA4>.)/", SyntaxError); | |
196 assertThrows("/(?<a\\uD801>.)/", SyntaxError); | |
197 assertThrows("/(?<a\\uDCA4>.)/", SyntaxError); | |
198 assertTrue(/(?<\u0041>.)/.test("a")); | |
199 assertThrows("/(?<\\u{0041}>.)/", SyntaxError); | |
200 assertThrows("/(?<a\\u{104A4}>.)/", SyntaxError); | |
201 assertThrows("/(?<a\\u{10FFFF}>.)/", SyntaxError); | |
202 | |
186 // @@replace with a callable replacement argument (no named captures). | 203 // @@replace with a callable replacement argument (no named captures). |
187 { | 204 { |
188 let result = "abcd".replace(/(.)(.)/u, (match, fst, snd, offset, str) => { | 205 let result = "abcd".replace(/(.)(.)/u, (match, fst, snd, offset, str) => { |
189 assertEquals("ab", match); | 206 assertEquals("ab", match); |
190 assertEquals("a", fst); | 207 assertEquals("a", fst); |
191 assertEquals("b", snd); | 208 assertEquals("b", snd); |
192 assertEquals(0, offset); | 209 assertEquals(0, offset); |
193 assertEquals("abcd", str); | 210 assertEquals("abcd", str); |
194 return `${snd}${fst}`; | 211 return `${snd}${fst}`; |
195 }); | 212 }); |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
362 // named captures). | 379 // named captures). |
363 { | 380 { |
364 let re = toSlowMode(/(?<fst>.)(?<snd>.)/u); | 381 let re = toSlowMode(/(?<fst>.)(?<snd>.)/u); |
365 assertEquals("bacd", "abcd".replace(re, "$<snd>$<fst>")); | 382 assertEquals("bacd", "abcd".replace(re, "$<snd>$<fst>")); |
366 assertEquals("bacd", "abcd".replace(re, "$2$1")); | 383 assertEquals("bacd", "abcd".replace(re, "$2$1")); |
367 assertThrows(() => "abcd".replace(re, "$<snd"), SyntaxError); | 384 assertThrows(() => "abcd".replace(re, "$<snd"), SyntaxError); |
368 assertEquals("cd", "abcd".replace(re, "$<42$1>")); | 385 assertEquals("cd", "abcd".replace(re, "$<42$1>")); |
369 assertEquals("cd", "abcd".replace(re, "$<thd>")); | 386 assertEquals("cd", "abcd".replace(re, "$<thd>")); |
370 assertEquals("cd", "abcd".replace(re, "$<$1>")); | 387 assertEquals("cd", "abcd".replace(re, "$<$1>")); |
371 } | 388 } |
OLD | NEW |