1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:57:45 +00:00

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

This also implements String.prototype.slice more closely to the spec
(such as handling indices equivalent to Infinity).
This commit is contained in:
Timothy Flynn 2021-07-19 14:57:07 -04:00 committed by Andreas Kling
parent eaa1360eee
commit 5ac964d841
2 changed files with 34 additions and 30 deletions

View file

@ -15,3 +15,13 @@ test("basic functionality", () => {
expect("hello friends".slice(1000)).toBe("");
expect("hello friends".slice(-1000)).toBe("hello friends");
});
test("UTF-16", () => {
var s = "😀";
expect(s).toHaveLength(2);
expect(s.slice()).toBe("😀");
expect(s.slice(0)).toBe("😀");
expect(s.slice(1)).toBe("\ude00");
expect(s.slice(0, 1)).toBe("\ud83d");
expect(s.slice(0, 2)).toBe("😀");
});