| 1 |
// Copyright 2017 the V8 project authors. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
|
| 4 |
/*--- |
| 5 |
description: Exotic named group names in Unicode RegExps |
| 6 |
esid: prod-GroupSpecifier |
| 7 |
features: [regexp-named-groups] |
| 8 |
---*/ |
| 9 |
|
| 10 |
assert.sameValue("a", /(?<π>a)/u.exec("bab").groups.π); |
| 11 |
assert.sameValue("a", /(?<\u{03C0}>a)/u.exec("bab").groups.π); |
| 12 |
assert.sameValue("a", /(?<π>a)/u.exec("bab").groups.\u03C0); |
| 13 |
assert.sameValue("a", /(?<\u{03C0}>a)/u.exec("bab").groups.\u03C0); |
| 14 |
assert.sameValue("a", /(?<$>a)/u.exec("bab").groups.$); |
| 15 |
assert.sameValue("a", /(?<_>a)/u.exec("bab").groups._); |
| 16 |
assert.sameValue("a", /(?<$𐒤>a)/u.exec("bab").groups.$𐒤); |
| 17 |
assert.sameValue("a", /(?<_\u200C>a)/u.exec("bab").groups._\u200C); |
| 18 |
assert.sameValue("a", /(?<_\u200D>a)/u.exec("bab").groups._\u200D); |
| 19 |
assert.sameValue("a", /(?<ಠ_ಠ>a)/u.exec("bab").groups.ಠ_ಠ); |
| 20 |
assert.throws(SyntaxError, () => eval('/(?<❤>a)/u')); |
| 21 |
assert.throws(SyntaxError, () => eval('/(?<𐒤>a)/u'), "ID_Continue but not ID_Start."); |
| 22 |
|
| 23 |
// Unicode escapes in capture names. |
| 24 |
assert(/(?<a\uD801\uDCA4>.)/u.test("a"), "\\u Lead \\u Trail"); |
| 25 |
assert.throws(SyntaxError, () => eval("/(?<a\\uD801>.)/u"), "\\u Lea"); |
| 26 |
assert.throws(SyntaxError, () => eval("/(?<a\\uDCA4>.)/u"), "\\u Trai"); |
| 27 |
assert(/(?<\u0041>.)/u.test("a"), "\\u NonSurrogate"); |
| 28 |
assert(/(?<\u{0041}>.)/u.test("a"), "\\u{ Non-surrogate }"); |
| 29 |
assert(/(?<a\u{104A4}>.)/u.test("a"), "\\u{ Surrogate, ID_Continue }"); |
| 30 |
assert.throws(SyntaxError, () => eval("/(?<a\\u{110000}>.)/u"), "\\u{ Out-of-bounds "); |
| 31 |
assert.throws(SyntaxError, () => eval("/(?<a\uD801>.)/u"), "Lea"); |
| 32 |
assert.throws(SyntaxError, () => eval("/(?<a\uDCA4>.)/u"), "Trai"); |
| 33 |
assert(RegExp("(?<\u{0041}>.)", "u").test("a"), "Non-surrogate"); |
| 34 |
assert(RegExp("(?<a\u{104A4}>.)", "u").test("a"), "Surrogate,ID_Continue"); |
| 35 |
|
| 36 |
// Bracketed escapes are not allowed; |
| 37 |
// 4-char escapes must be the proper ID_Start/ID_Continue |
| 38 |
assert.throws(SyntaxError, () => eval("/(?<a\\uD801>.)/u"), "Lead"); |
| 39 |
assert.throws(SyntaxError, () => eval("/(?<a\\uDCA4>.)/u"), "Trail"); |
| 40 |
assert((/(?<\u{0041}>.)/u).test("a"), "Non-surrogate"); |
| 41 |
assert(/(?<a\u{104A4}>.)/u.test("a"), "Surrogate, ID_Continue"); |
| 42 |
assert(RegExp("(?<\\u0041>.)", "u").test("a"), "Non-surrogate"); |
| 43 |
|
| 44 |
// Backslash is not allowed as ID_Start and ID_Continue |
| 45 |
assert.throws(SyntaxError, () => eval("/(?<\\>.)/u"), "'\' misclassified as ID_Start"); |
| 46 |
assert.throws(SyntaxError, () => eval("/(?<a\\>.)/u"), "'\' misclassified as ID_Continue"); |