tor-browser

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

string-replace-nocaptures.js (1237B)


      1 // Copyright 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 description: If there are no named captures, don't replace $<>
      6 esid: sec-getsubstitution
      7 features: [regexp-named-groups]
      8 info: |
      9  Runtime Semantics: GetSubstitution( matched, str, position, captures, namedCaptures, replacement )
     10 
     11  Table: Replacement Text Symbol Substitutions
     12 
     13  Unicode Characters: $<
     14  Replacement text:
     15    1. If namedCaptures is undefined, the replacement text is the literal string $<.
     16 ---*/
     17 
     18 // @@replace with a string replacement argument (no named captures).
     19 
     20 let source = "(.)(.)|(x)";
     21 for (let flags of ["", "u"]) {
     22  let re = new RegExp(source, flags);
     23  assert.sameValue("$<snd>$<fst>cd", "abcd".replace(re, "$<snd>$<fst>"));
     24  assert.sameValue("bacd", "abcd".replace(re, "$2$1"));
     25  assert.sameValue("cd", "abcd".replace(re, "$3"));
     26  assert.sameValue("$<sndcd", "abcd".replace(re, "$<snd"));
     27  assert.sameValue("$<sndacd", "abcd".replace(re, "$<snd$1"));
     28  assert.sameValue("$<42a>cd", "abcd".replace(re, "$<42$1>"));
     29  assert.sameValue("$<fth>cd", "abcd".replace(re, "$<fth>"));
     30  assert.sameValue("$<a>cd", "abcd".replace(re, "$<$1>"));
     31 }
     32 
     33 
     34 reportCompare(0, 0);