tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

duplicate-names-match.js (1695B)


      1 // Copyright 2022 Kevin Gibbons. 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("bab".match(/(?<x>a)|(?<x>b)/), ["b", undefined, "b"]);
     12 assert.compareArray("bab".match(/(?<x>b)|(?<x>a)/), ["b", "b", undefined]);
     13 
     14 assert.compareArray("aa".match(/(?:(?<x>a)|(?<x>b))\k<x>/), ["aa", "a", undefined]);
     15 assert.compareArray("bb".match(/(?:(?<x>a)|(?<x>b))\k<x>/), ["bb", undefined, "b"]);
     16 
     17 let matchResult = "aabb".match(/(?:(?:(?<x>a)|(?<x>b))\k<x>){2}/);
     18 assert.compareArray(matchResult, ["aabb", undefined, "b"]);
     19 assert.sameValue(matchResult.groups.x, "b");
     20 
     21 assert.sameValue("abab".match(/(?:(?:(?<x>a)|(?<x>b))\k<x>){2}/), null);
     22 
     23 assert.sameValue("abab".match(/(?:(?<x>a)|(?<x>b))\k<x>/), null);
     24 
     25 assert.sameValue("cdef".match(/(?:(?<x>a)|(?<x>b))\k<x>/), null);
     26 
     27 assert.compareArray("xx".match(/^(?:(?<a>x)|(?<a>y)|z)\k<a>$/), ["xx", "x", undefined]);
     28 assert.compareArray("z".match(/^(?:(?<a>x)|(?<a>y)|z)\k<a>$/), ["z", undefined, undefined]);
     29 assert.sameValue("zz".match(/^(?:(?<a>x)|(?<a>y)|z)\k<a>$/), null);
     30 assert.compareArray("zy".match(/(?<a>x)|(?:zy\k<a>)/), ["zy", undefined]);
     31 
     32 assert.compareArray("xz".match(/^(?:(?<a>x)|(?<a>y)|z){2}\k<a>$/), ["xz", undefined, undefined]);
     33 assert.compareArray("yz".match(/^(?:(?<a>x)|(?<a>y)|z){2}\k<a>$/), ["yz", undefined, undefined]);
     34 assert.sameValue("xzx".match(/^(?:(?<a>x)|(?<a>y)|z){2}\k<a>$/), null);
     35 assert.sameValue("yzy".match(/^(?:(?<a>x)|(?<a>y)|z){2}\k<a>$/), null);
     36 
     37 reportCompare(0, 0);