// Copyright (C) 2020 Alexey Shvayka. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- esid: sec-getsubstitution description: > RegExp.prototype[Symbol.replace] works with named capture references as expected. (string replacement) info: | GetSubstitution ( matched, str, position, captures, namedCaptures, replacement ) Table: Replacement Text Symbol Substitutions Unicode Characters: $< Replacement text: 1. If namedCaptures is undefined, the replacement text is the literal string $<. 2. Else, a. Assert: Type(namedCaptures) is Object. b. Scan until the next > U+003E (GREATER-THAN SIGN). c. If none is found, the replacement text is the String "$<". d. Else, i. Let groupName be the enclosed substring. ii. Let capture be ? Get(namedCaptures, groupName). iii. If capture is undefined, replace the text through > with the empty String. iv. Otherwise, replace the text through > with ? ToString(capture). features: [Symbol.replace, regexp-named-groups] ---*/ assert.sameValue(/b/u[Symbol.replace]("abc", "$&$d"), "c$dc$d"); assert.sameValue(/(b)./[Symbol.replace]("abc", "$$1"), "a$b"); assert.sameValue(/(?.)(?.)/[Symbol.replace]("abc", "$$"), "bac"); assert.sameValue(/(?.)(?.)/gu[Symbol.replace]("abc", "$2$$1"), "baac"); assert.sameValue(/(?b)/u[Symbol.replace]("abc", "c$d"), "acdc"); assert.sameValue(/(?.)/g[Symbol.replace]("abc", "$<$1>"), ""); assert.sameValue(/(?b)/[Symbol.replace]("abc", "$<>"), "ac"); assert.sameValue(/(?.)(?.)/g[Symbol.replace]("abc", "$2$1"), "bac"); assert.sameValue(/(?b)/u[Symbol.replace]("abc", "$.)/gu[Symbol.replace]("abc", "$"), ""); assert.sameValue(/(?b)/[Symbol.replace]("abc", "$$$&"), "a$bc"); assert.sameValue(/(?<𝒜>b)/u[Symbol.replace]("abc", "d$<𝒜>$`"), "adbac"); assert.sameValue(/(?<$𐒤>b)/gu[Symbol.replace]("abc", "$'$<$𐒤>d"), "acbdc"); reportCompare(0, 0);