1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 08:47:44 +00:00

LibJS: Implement String.prototype.replaceAll with UTF-16 code units

This commit is contained in:
Timothy Flynn 2021-07-19 17:02:44 -04:00 committed by Andreas Kling
parent 06208aaa15
commit 733a92820b
2 changed files with 33 additions and 12 deletions

View file

@ -143,3 +143,15 @@ test("search value is coerced to a string", () => {
expect(newString).toBe("abc");
expect(coerced).toBe("x");
});
test("UTF-16", () => {
expect("😀".replaceAll("😀", "")).toBe("");
expect("😀".replaceAll("\ud83d", "")).toBe("\ude00");
expect("😀".replaceAll("\ude00", "")).toBe("\ud83d");
expect("😀😀😀".replaceAll("\ud83d", "")).toBe("\ude00\ude00\ude00");
expect("😀😀😀".replaceAll("\ude00", "")).toBe("\ud83d\ud83d\ud83d");
// FIXME: RegExp.prototype [ @@replace ] also needs to support UTF-16.
// expect("😀".replaceAll(/\ud83d/g, "")).toBe("\ude00");
// expect("😀".replaceAll(/\ude00/g, "")).toBe("\ud83d");
});