Index: test/mjsunit/harmony/regexp-named-captures.js |
diff --git a/test/mjsunit/harmony/regexp-named-captures.js b/test/mjsunit/harmony/regexp-named-captures.js |
index 33013c6c9b4b41b88d54b2863ffe1af49bc4ea34..0e256ec67d739c2f31dd3c9da9bf5d0c3b7476f8 100644 |
--- a/test/mjsunit/harmony/regexp-named-captures.js |
+++ b/test/mjsunit/harmony/regexp-named-captures.js |
@@ -208,3 +208,59 @@ function toSlowMode(re) { |
}); |
assertEquals("bacd", result); |
} |
+ |
+// @@replace with a string replacement argument (no named captures). |
+{ |
+ let re = /(.)(.)/u; |
+ assertEquals("$<snd>$<fst>cd", "abcd".replace(re, "$<snd>$<fst>")); |
+ assertEquals("bacd", "abcd".replace(re, "$2$1")); |
+ assertEquals("$<sndcd", "abcd".replace(re, "$<snd")); |
+ assertEquals("$<42a>cd", "abcd".replace(re, "$<42$1>")); |
+ assertEquals("$<thd>cd", "abcd".replace(re, "$<thd>")); |
+ assertEquals("$<a>cd", "abcd".replace(re, "$<$1>")); |
+} |
+ |
+// @@replace with a string replacement argument (global, named captures). |
+{ |
+ let re = /(?<fst>.)(?<snd>.)/gu; |
+ assertEquals("badc", "abcd".replace(re, "$<snd>$<fst>")); |
+ assertEquals("badc", "abcd".replace(re, "$2$1")); |
+ assertThrows(() => "abcd".replace(re, "$<snd"), SyntaxError); |
+ assertEquals("", "abcd".replace(re, "$<42$1>")); |
+ assertEquals("", "abcd".replace(re, "$<thd>")); |
+ assertEquals("", "abcd".replace(re, "$<$1>")); |
+} |
+ |
+// @@replace with a string replacement argument (non-global, named captures). |
+{ |
+ let re = /(?<fst>.)(?<snd>.)/u; |
+ assertEquals("bacd", "abcd".replace(re, "$<snd>$<fst>")); |
+ assertEquals("bacd", "abcd".replace(re, "$2$1")); |
+ assertThrows(() => "abcd".replace(re, "$<snd"), SyntaxError); |
+ assertEquals("cd", "abcd".replace(re, "$<42$1>")); |
+ assertEquals("cd", "abcd".replace(re, "$<thd>")); |
+ assertEquals("cd", "abcd".replace(re, "$<$1>")); |
+} |
+ |
+// @@replace with a string replacement argument (slow, global, named captures). |
+{ |
+ let re = toSlowMode(/(?<fst>.)(?<snd>.)/gu); |
+ assertEquals("badc", "abcd".replace(re, "$<snd>$<fst>")); |
+ assertEquals("badc", "abcd".replace(re, "$2$1")); |
+ assertThrows(() => "abcd".replace(re, "$<snd"), SyntaxError); |
+ assertEquals("", "abcd".replace(re, "$<42$1>")); |
+ assertEquals("", "abcd".replace(re, "$<thd>")); |
+ assertEquals("", "abcd".replace(re, "$<$1>")); |
+} |
+ |
+// @@replace with a string replacement argument (slow, non-global, |
+// named captures). |
+{ |
+ let re = toSlowMode(/(?<fst>.)(?<snd>.)/u); |
+ assertEquals("bacd", "abcd".replace(re, "$<snd>$<fst>")); |
+ assertEquals("bacd", "abcd".replace(re, "$2$1")); |
+ assertThrows(() => "abcd".replace(re, "$<snd"), SyntaxError); |
+ assertEquals("cd", "abcd".replace(re, "$<42$1>")); |
+ assertEquals("cd", "abcd".replace(re, "$<thd>")); |
+ assertEquals("cd", "abcd".replace(re, "$<$1>")); |
+} |