Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Unified Diff: test/mjsunit/harmony/regexp-named-captures.js

Issue 2775303002: [regexp] Named capture support for string replacements (Closed)
Patch Set: Only cast if not undefined Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/cctest/interpreter/bytecode_expectations/Generators.golden ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>"));
+}
« no previous file with comments | « test/cctest/interpreter/bytecode_expectations/Generators.golden ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698