Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/RegExp/named-groups/string-replace-missing.js

raw
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 the group doesn't exist, replace with the empty string
6 esid: sec-getsubstitution
7 features: [regexp-named-groups]
8 ---*/
9
10 let source = "(?<fst>.)(?<snd>.)|(?<thd>x)";
11 for (let flags of ["", "u"]) {
12 let re = new RegExp(source, flags);
13 assert.sameValue("cd", "abcd".replace(re, "$<42$1>"));
14 assert.sameValue("cd", "abcd".replace(re, "$<fth>"));
15 assert.sameValue("cd", "abcd".replace(re, "$<$1>"));
16 assert.sameValue("cd", "abcd".replace(re, "$<>"));
17 }
18 for (let flags of ["g", "gu"]) {
19 let re = new RegExp(source, flags);
20 assert.sameValue("", "abcd".replace(re, "$<42$1>"));
21 assert.sameValue("", "abcd".replace(re, "$<fth>"));
22 assert.sameValue("", "abcd".replace(re, "$<$1>"));
23 assert.sameValue("", "abcd".replace(re, "$<>"));
24 }