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