// |reftest| skip -- regexp-duplicate-named-groups is not supported // Copyright 2022 Kevin Gibbons. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- description: Matching behavior with duplicate named capture groups esid: prod-GroupSpecifier features: [regexp-duplicate-named-groups] includes: [compareArray.js] ---*/ assert.compareArray("bab".match(/(?a)|(?b)/), ["b", undefined, "b"]); assert.compareArray("bab".match(/(?b)|(?a)/), ["b", "b", undefined]); assert.compareArray("aa".match(/(?:(?a)|(?b))\k/), ["aa", "a", undefined]); assert.compareArray("bb".match(/(?:(?a)|(?b))\k/), ["bb", undefined, "b"]); let matchResult = "aabb".match(/(?:(?:(?a)|(?b))\k){2}/); assert.compareArray(matchResult, ["aabb", undefined, "b"]); assert.sameValue(matchResult.groups.x, "b"); assert.sameValue("abab".match(/(?:(?:(?a)|(?b))\k){2}/), null); assert.sameValue("abab".match(/(?:(?a)|(?b))\k/), null); assert.sameValue("cdef".match(/(?:(?a)|(?b))\k/), null); assert.compareArray("xx".match(/^(?:(?x)|(?y)|z)\k$/), ["xx", "x", undefined]); assert.compareArray("z".match(/^(?:(?x)|(?y)|z)\k$/), ["z", undefined, undefined]); assert.sameValue("zz".match(/^(?:(?x)|(?y)|z)\k$/), null); assert.compareArray("zy".match(/(?x)|(?:zy\k)/), ["zy", undefined]); assert.compareArray("xz".match(/^(?:(?x)|(?y)|z){2}\k$/), ["xz", undefined, undefined]); assert.compareArray("yz".match(/^(?:(?x)|(?y)|z){2}\k$/), ["yz", undefined, undefined]); assert.sameValue("xzx".match(/^(?:(?x)|(?y)|z){2}\k$/), null); assert.sameValue("yzy".match(/^(?:(?x)|(?y)|z){2}\k$/), null); reportCompare(0, 0);