// |reftest| skip -- regexp-duplicate-named-groups is not supported // Copyright 2022 Igalia S.L. 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(/(?a)|(?b)/.exec("bab"), ["b", undefined, "b"]); assert.compareArray(/(?b)|(?a)/.exec("bab"), ["b", "b", undefined]); assert.compareArray(/(?:(?a)|(?b))\k/.exec("aa"), ["aa", "a", undefined]); assert.compareArray(/(?:(?a)|(?b))\k/.exec("bb"), ["bb", undefined, "b"]); let matchResult = /(?:(?:(?a)|(?b))\k){2}/.exec("aabb"); assert.compareArray(matchResult, ["aabb", undefined, "b"]); assert.sameValue(matchResult.groups.x, "b"); assert.sameValue(/(?:(?:(?a)|(?b))\k){2}/.exec("abab"), null); assert.sameValue(/(?:(?a)|(?b))\k/.exec("abab"), null); assert.sameValue(/(?:(?a)|(?b))\k/.exec("cdef"), null); assert.compareArray(/^(?:(?x)|(?y)|z)\k$/.exec("xx"), ["xx", "x", undefined]); assert.compareArray(/^(?:(?x)|(?y)|z)\k$/.exec("z"), ["z", undefined, undefined]); assert.sameValue(/^(?:(?x)|(?y)|z)\k$/.exec("zz"), null); assert.compareArray(/(?x)|(?:zy\k)/.exec("zy"), ["zy", undefined]); assert.compareArray(/^(?:(?x)|(?y)|z){2}\k$/.exec("xz"), ["xz", undefined, undefined]); assert.compareArray(/^(?:(?x)|(?y)|z){2}\k$/.exec("yz"), ["yz", undefined, undefined]); assert.sameValue(/^(?:(?x)|(?y)|z){2}\k$/.exec("xzx"), null); assert.sameValue(/^(?:(?x)|(?y)|z){2}\k$/.exec("yzy"), null); reportCompare(0, 0);