test262/test/built-ins/RegExp/named-groups/string-replace-missing.js
Daniel Ehrenberg 6cf15f523a RegExp named group tests (#998)
Tests against the Stage 3 named capture groups proposal
https://tc39.github.io/proposal-regexp-named-groups
2017-04-27 12:50:59 -04:00

26 lines
907 B
JavaScript

// Copyright 2017 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: SyntaxError is thrown for malformed replacements
esid: sec-getsubstitution
features: [regexp-named-groups]
info: >
Runtime Semantics: GetSubstitution( matched, str, position, captures, namedCaptures, replacement )
Table: Replacement Text Symbol Substitutions
Unicode Characters: $<
Replacement text:
2. Otherwise,
b. If ? HasProperty(namedCaptures, groupName) is false, throw a SyntaxError exception.
---*/
let source = "(?<fst>.)(?<snd>.)|(?<thd>x)";
for (let flags of ["", "u", "g", "gu"]) {
let re = new RegExp(source, flags);
assert.throws(SyntaxError, () => "abcd".replace(re, "$<42$1>"));
assert.throws(SyntaxError, () => "abcd".replace(re, "$<fth>"));
assert.throws(SyntaxError, () => "abcd".replace(re, "$<$1>"));
}