tor-browser

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

lookbehind.js (2119B)


      1 // Copyright 2018 the V8 project authors. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 description: Named groups can be used in conjunction with lookbehind
      6 esid: prod-GroupSpecifier
      7 features: [regexp-named-groups, regexp-lookbehind]
      8 includes: [compareArray.js]
      9 ---*/
     10 
     11 // Unicode mode
     12 assert.compareArray(["f", "c"], "abcdef".match(/(?<=(?<a>\w){3})f/u));
     13 assert.sameValue("c", "abcdef".match(/(?<=(?<a>\w){3})f/u).groups.a);
     14 assert.sameValue("b", "abcdef".match(/(?<=(?<a>\w){4})f/u).groups.a);
     15 assert.sameValue("a", "abcdef".match(/(?<=(?<a>\w)+)f/u).groups.a);
     16 assert.sameValue(null, "abcdef".match(/(?<=(?<a>\w){6})f/u));
     17 
     18 assert.compareArray(["f", ""], "abcdef".match(/((?<=\w{3}))f/u));
     19 assert.compareArray(["f", ""], "abcdef".match(/(?<a>(?<=\w{3}))f/u));
     20 
     21 assert.compareArray(["f", undefined], "abcdef".match(/(?<!(?<a>\d){3})f/u));
     22 assert.sameValue(null, "abcdef".match(/(?<!(?<a>\D){3})f/u));
     23 
     24 assert.compareArray(["f", undefined], "abcdef".match(/(?<!(?<a>\D){3})f|f/u));
     25 assert.compareArray(["f", undefined], "abcdef".match(/(?<a>(?<!\D{3}))f|f/u));
     26 
     27 // Non-Unicode mode
     28 assert.compareArray(["f", "c"], "abcdef".match(/(?<=(?<a>\w){3})f/));
     29 assert.sameValue("c", "abcdef".match(/(?<=(?<a>\w){3})f/).groups.a);
     30 assert.sameValue("b", "abcdef".match(/(?<=(?<a>\w){4})f/).groups.a);
     31 assert.sameValue("a", "abcdef".match(/(?<=(?<a>\w)+)f/).groups.a);
     32 assert.sameValue(null, "abcdef".match(/(?<=(?<a>\w){6})f/));
     33 
     34 assert.compareArray(["f", ""], "abcdef".match(/((?<=\w{3}))f/));
     35 assert.compareArray(["f", ""], "abcdef".match(/(?<a>(?<=\w{3}))f/));
     36 
     37 assert.compareArray(["f", undefined], "abcdef".match(/(?<!(?<a>\d){3})f/));
     38 assert.sameValue(null, "abcdef".match(/(?<!(?<a>\D){3})f/));
     39 
     40 assert.compareArray(["f", undefined], "abcdef".match(/(?<!(?<a>\D){3})f|f/));
     41 assert.compareArray(["f", undefined], "abcdef".match(/(?<a>(?<!\D{3}))f|f/));
     42 
     43 // Even within a lookbehind, properties are created in left to right order
     44 assert.compareArray(["fst", "snd"], Object.getOwnPropertyNames(
     45    /(?<=(?<fst>.)|(?<snd>.))/u.exec("abcd").groups));
     46 
     47 reportCompare(0, 0);