| 1 |
// |reftest| shell-option(--enable-regexp-duplicate-named-groups) skip-if(!xulRuntime.shell) -- requires shell-options |
| 2 |
// Copyright 2022 Kevin Gibbons. All rights reserved. |
| 3 |
// This code is governed by the BSD license found in the LICENSE file. |
| 4 |
|
| 5 |
/*--- |
| 6 |
description: Matching behavior with duplicate named capture groups |
| 7 |
esid: prod-GroupSpecifier |
| 8 |
features: [regexp-duplicate-named-groups] |
| 9 |
includes: [compareArray.js] |
| 10 |
---*/ |
| 11 |
|
| 12 |
assert.compareArray("bab".match(/(?<x>a)|(?<x>b)/), ["b", undefined, "b"]); |
| 13 |
assert.compareArray("bab".match(/(?<x>b)|(?<x>a)/), ["b", "b", undefined]); |
| 14 |
|
| 15 |
assert.compareArray("aa".match(/(?:(?<x>a)|(?<x>b))\k<x>/), ["aa", "a", undefined]); |
| 16 |
assert.compareArray("bb".match(/(?:(?<x>a)|(?<x>b))\k<x>/), ["bb", undefined, "b"]); |
| 17 |
|
| 18 |
let matchResult = "aabb".match(/(?:(?:(?<x>a)|(?<x>b))\k<x>){2}/); |
| 19 |
assert.compareArray(matchResult, ["aabb", undefined, "b"]); |
| 20 |
assert.sameValue(matchResult.groups.x, "b"); |
| 21 |
|
| 22 |
assert.sameValue("abab".match(/(?:(?:(?<x>a)|(?<x>b))\k<x>){2}/), null); |
| 23 |
|
| 24 |
assert.sameValue("abab".match(/(?:(?<x>a)|(?<x>b))\k<x>/), null); |
| 25 |
|
| 26 |
assert.sameValue("cdef".match(/(?:(?<x>a)|(?<x>b))\k<x>/), null); |
| 27 |
|
| 28 |
assert.compareArray("xx".match(/^(?:(?<a>x)|(?<a>y)|z)\k<a>$/), ["xx", "x", undefined]); |
| 29 |
assert.compareArray("z".match(/^(?:(?<a>x)|(?<a>y)|z)\k<a>$/), ["z", undefined, undefined]); |
| 30 |
assert.sameValue("zz".match(/^(?:(?<a>x)|(?<a>y)|z)\k<a>$/), null); |
| 31 |
assert.compareArray("zy".match(/(?<a>x)|(?:zy\k<a>)/), ["zy", undefined]); |
| 32 |
|
| 33 |
assert.compareArray("xz".match(/^(?:(?<a>x)|(?<a>y)|z){2}\k<a>$/), ["xz", undefined, undefined]); |
| 34 |
assert.compareArray("yz".match(/^(?:(?<a>x)|(?<a>y)|z){2}\k<a>$/), ["yz", undefined, undefined]); |
| 35 |
assert.sameValue("xzx".match(/^(?:(?<a>x)|(?<a>y)|z){2}\k<a>$/), null); |
| 36 |
assert.sameValue("yzy".match(/^(?:(?<a>x)|(?<a>y)|z){2}\k<a>$/), null); |
| 37 |
|
| 38 |
reportCompare(0, 0); |