Debian Codegraph @

js/src/tests/test262/built-ins/RegExp/named-groups/non-unicode-references.js

raw
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: Named backreferences in non-Unicode RegExps
6 esid: prod-GroupSpecifier
7 features: [regexp-named-groups]
8 includes: [compareArray.js]
9 ---*/
10
11 // Named references.
12 assert.compareArray(["bab", "b"], "bab".match(/(?<b>.).\k<b>/));
13 assert.sameValue(null, "baa".match(/(?<b>.).\k<b>/));
14
15 // Reference inside group.
16 assert.compareArray(["bab", "b"], "bab".match(/(?<a>\k<a>\w)../));
17 assert.sameValue("b", "bab".match(/(?<a>\k<a>\w)../).groups.a);
18
19 // Reference before group.
20 assert.compareArray(["bab", "b"], "bab".match(/\k<a>(?<a>b)\w\k<a>/));
21 assert.sameValue("b", "bab".match(/\k<a>(?<a>b)\w\k<a>/).groups.a);
22 assert.compareArray(["bab", "b", "a"], "bab".match(/(?<b>b)\k<a>(?<a>a)\k<b>/));
23 let {a, b} = "bab".match(/(?<b>b)\k<a>(?<a>a)\k<b>/).groups;
24 assert.sameValue(a, "a");
25 assert.sameValue(b, "b");
26
27 assert.compareArray(["bab", "b"], "bab".match(/\k<a>(?<a>b)\w\k<a>/));
28 assert.compareArray(["bab", "b", "a"], "bab".match(/(?<b>b)\k<a>(?<a>a)\k<b>/));
29
30 // Reference properties.
31 assert.sameValue("a", /(?<a>a)(?<b>b)\k<a>/.exec("aba").groups.a);
32 assert.sameValue("b", /(?<a>a)(?<b>b)\k<a>/.exec("aba").groups.b);
33 assert.sameValue(undefined, /(?<a>a)(?<b>b)\k<a>/.exec("aba").groups.c);
34 assert.sameValue(undefined, /(?<a>a)(?<b>b)\k<a>|(?<c>c)/.exec("aba").groups.c);
35
36 reportCompare(0, 0);