tor-browser

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

captures.js (1658B)


      1 // Copyright (C) 2017 the V8 project authors. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 esid: sec-assertion
      6 description: >
      7  Capturing matches
      8 info: |
      9  The production Assertion :: (?<=Disjunction) evaluates as follows:
     10    1. Evaluate Disjunction with -1 as its direction argument to obtain a Matcher m.
     11    2. Return an internal Matcher closure that takes two arguments, a State x and a Continuation
     12        c, and performs the following steps:
     13      a. Let d be a Continuation that always returns its State argument as a successful MatchResult.
     14      b. Call m(x, d) and let r be its result.
     15      c. If r is failure, return failure.
     16      d. Let y be r's State.
     17      e. Let cap be y's captures List.
     18      f. Let xe be x's endIndex.
     19      g. Let z be the State (xe, cap).
     20      h. Call c(z) and return its result.
     21 features: [regexp-lookbehind]
     22 includes: [compareArray.js]
     23 ---*/
     24 
     25 var str = "abcdef";
     26 assert.compareArray(str.match(/(?<=(c))def/), ["def", "c"], "#1");
     27 assert.compareArray(str.match(/(?<=(\w{2}))def/), ["def", "bc"], "#2");
     28 assert.compareArray(str.match(/(?<=(\w(\w)))def/), ["def", "bc", "c"], "#3");
     29 assert.compareArray(str.match(/(?<=(\w){3})def/), ["def", "a"], "#4");
     30 assert.compareArray(str.match(/(?<=(bc)|(cd))./), ["d", "bc", undefined], "#5");
     31 assert.compareArray(str.match(/(?<=([ab]{1,2})\D|(abc))\w/), ["c", "a", undefined], "#6");
     32 assert.compareArray(str.match(/\D(?<=([ab]+))(\w)/), ["ab", "a", "b"], "#7");
     33 assert.compareArray(str.match(/(?<=b|c)\w/g), ["c", "d"], "#8");
     34 assert.compareArray(str.match(/(?<=[b-e])\w{2}/g), ["cd", "ef"], "#9");
     35 
     36 reportCompare(0, 0);