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

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

Issue 2776263003: [regexp] Handle unmatched groups in callable replacers (Closed)
Patch Set: Rebase 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 | « src/runtime/runtime-regexp.cc ('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 0e256ec67d739c2f31dd3c9da9bf5d0c3b7476f8..e4de7b00c8db9ea7f63d14f8fb4c5dc86e8b220c 100644
--- a/test/mjsunit/harmony/regexp-named-captures.js
+++ b/test/mjsunit/harmony/regexp-named-captures.js
@@ -108,6 +108,9 @@ assertEquals("a", /(?<__proto__>a)/u.exec("a").groups.__proto__);
return `${snd}${fst}`;
});
assertEquals("bacd", result);
+
+ assertEquals("undefinedbcd", "abcd".replace(/(.)|(.)/u,
+ (match, fst, snd, offset, str) => snd));
}
// @@replace with a callable replacement argument (global, named captures).
@@ -138,6 +141,10 @@ assertEquals("a", /(?<__proto__>a)/u.exec("a").groups.__proto__);
return `${groups.snd}${groups.fst}`;
});
assertEquals("badc", result);
+
+ assertEquals("undefinedundefinedundefinedundefined",
+ "abcd".replace(/(?<fst>.)|(?<snd>.)/gu,
+ (match, fst, snd, offset, str, groups) => groups.snd));
}
// @@replace with a callable replacement argument (non-global, named captures).
@@ -154,6 +161,10 @@ assertEquals("a", /(?<__proto__>a)/u.exec("a").groups.__proto__);
return `${groups.snd}${groups.fst}`;
});
assertEquals("bacd", result);
+
+ assertEquals("undefinedbcd",
+ "abcd".replace(/(?<fst>.)|(?<snd>.)/u,
+ (match, fst, snd, offset, str, groups) => groups.snd));
}
function toSlowMode(re) {
@@ -190,6 +201,10 @@ function toSlowMode(re) {
return `${groups.snd}${groups.fst}`;
});
assertEquals("badc", result);
+
+ assertEquals("undefinedundefinedundefinedundefined",
+ "abcd".replace(toSlowMode(/(?<fst>.)|(?<snd>.)/gu),
+ (match, fst, snd, offset, str, groups) => groups.snd));
}
// @@replace with a callable replacement argument (slow, non-global,
@@ -207,6 +222,10 @@ function toSlowMode(re) {
return `${groups.snd}${groups.fst}`;
});
assertEquals("bacd", result);
+
+ assertEquals("undefinedbcd",
+ "abcd".replace(toSlowMode(/(?<fst>.)|(?<snd>.)/u),
+ (match, fst, snd, offset, str, groups) => groups.snd));
}
// @@replace with a string replacement argument (no named captures).
« no previous file with comments | « src/runtime/runtime-regexp.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698