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

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

This commit is contained in:
Timothy Flynn 2021-07-19 13:34:41 -04:00 committed by Andreas Kling
parent 60d8852fc2
commit 892bfdbbcf
2 changed files with 18 additions and 10 deletions

View file

@ -17,3 +17,14 @@ test("basic functionality", () => {
expect("hello friends".substr(-7)).toBe("friends");
expect("hello friends".substr(-3, -5)).toBe("");
});
test("UTF-16", () => {
var s = "😀";
expect(s).toHaveLength(2);
expect(s.substr()).toBe("😀");
expect(s.substr(0)).toBe("😀");
expect(s.substr(0, 2)).toBe("😀");
expect(s.substr(0, 1)).toBe("\ud83d");
expect(s.substr(1, 1)).toBe("\ude00");
expect(s.substr(2, 1)).toBe("");
});