Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(799)

Side by Side Diff: test/mjsunit/harmony/regexp-named-captures.js

Issue 2788423003: [regexp] Updates for unicode escapes in capture names (Closed)
Patch Set: Address comments and rebase Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/regexp/regexp-parser.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 // Backslash as ID_Start and ID_Continue (v8:5868). 180 // Backslash as ID_Start and ID_Continue (v8:5868).
181 assertThrows("/(?<\\>.)/", SyntaxError); // '\' misclassified as ID_Start. 181 assertThrows("/(?<\\>.)/", SyntaxError); // '\' misclassified as ID_Start.
182 assertThrows("/(?<a\\>.)/", SyntaxError); // '\' misclassified as ID_Continue. 182 assertThrows("/(?<a\\>.)/", SyntaxError); // '\' misclassified as ID_Continue.
183 183
184 // Backreference before the group (exercises the capture mini-parser). 184 // Backreference before the group (exercises the capture mini-parser).
185 assertThrows("/\\1(?:.)/u", SyntaxError); 185 assertThrows("/\\1(?:.)/u", SyntaxError);
186 assertThrows("/\\1(?<=a)./u", SyntaxError); 186 assertThrows("/\\1(?<=a)./u", SyntaxError);
187 assertThrows("/\\1(?<!a)./u", SyntaxError); 187 assertThrows("/\\1(?<!a)./u", SyntaxError);
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.
191 assertTrue(/(?<a\uD801\uDCA4>.)/u.test("a")); // \u Lead \u Trail
192 assertThrows("/(?<a\\uD801>.)/u", SyntaxError); // \u Lead
193 assertThrows("/(?<a\\uDCA4>.)/u", SyntaxError); // \u Trail
194 assertTrue(/(?<\u0041>.)/u.test("a")); // \u NonSurrogate
195 assertTrue(/(?<\u{0041}>.)/u.test("a")); // \u{ Non-surrogate }
196 assertTrue(/(?<a\u{104A4}>.)/u.test("a")); // \u{ Surrogate, ID_Continue }
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
200 assertTrue(RegExp("(?<\u{0041}>.)", "u").test("a")); // Non-surrogate
201 assertTrue(RegExp("(?<a\u{104A4}>.)", "u").test("a")); // Surrogate,ID_Continue
202
203 assertThrows("/(?<a\\uD801\uDCA4>.)/", SyntaxError);
204 assertThrows("/(?<a\\uD801>.)/", SyntaxError);
205 assertThrows("/(?<a\\uDCA4>.)/", SyntaxError);
206 assertTrue(/(?<\u0041>.)/.test("a"));
207 assertThrows("/(?<\\u{0041}>.)/", SyntaxError);
208 assertThrows("/(?<a\\u{104A4}>.)/", SyntaxError);
209 assertThrows("/(?<a\\u{10FFFF}>.)/", SyntaxError);
210 assertThrows("/(?<a\uD801>.)/", SyntaxError); // Lead
211 assertThrows("/(?<a\uDCA4>.)/", SyntaxError); // Trail
212 assertTrue(RegExp("(?<\u{0041}>.)").test("a")); // Non-surrogate
213 assertTrue(RegExp("(?<a\u{104A4}>.)").test("a")); // Surrogate, ID_Continue
214
190 // @@replace with a callable replacement argument (no named captures). 215 // @@replace with a callable replacement argument (no named captures).
191 { 216 {
192 let result = "abcd".replace(/(.)(.)/u, (match, fst, snd, offset, str) => { 217 let result = "abcd".replace(/(.)(.)/u, (match, fst, snd, offset, str) => {
193 assertEquals("ab", match); 218 assertEquals("ab", match);
194 assertEquals("a", fst); 219 assertEquals("a", fst);
195 assertEquals("b", snd); 220 assertEquals("b", snd);
196 assertEquals(0, offset); 221 assertEquals(0, offset);
197 assertEquals("abcd", str); 222 assertEquals("abcd", str);
198 return `${snd}${fst}`; 223 return `${snd}${fst}`;
199 }); 224 });
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 // named captures). 391 // named captures).
367 { 392 {
368 let re = toSlowMode(/(?<fst>.)(?<snd>.)/u); 393 let re = toSlowMode(/(?<fst>.)(?<snd>.)/u);
369 assertEquals("bacd", "abcd".replace(re, "$<snd>$<fst>")); 394 assertEquals("bacd", "abcd".replace(re, "$<snd>$<fst>"));
370 assertEquals("bacd", "abcd".replace(re, "$2$1")); 395 assertEquals("bacd", "abcd".replace(re, "$2$1"));
371 assertThrows(() => "abcd".replace(re, "$<snd"), SyntaxError); 396 assertThrows(() => "abcd".replace(re, "$<snd"), SyntaxError);
372 assertEquals("cd", "abcd".replace(re, "$<42$1>")); 397 assertEquals("cd", "abcd".replace(re, "$<42$1>"));
373 assertEquals("cd", "abcd".replace(re, "$<thd>")); 398 assertEquals("cd", "abcd".replace(re, "$<thd>"));
374 assertEquals("cd", "abcd".replace(re, "$<$1>")); 399 assertEquals("cd", "abcd".replace(re, "$<$1>"));
375 } 400 }
OLDNEW
« no previous file with comments | « src/regexp/regexp-parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698