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

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

This commit is contained in:
Timothy Flynn 2021-07-19 13:15:30 -04:00 committed by Andreas Kling
parent 767700d8a1
commit 60d8852fc2
2 changed files with 23 additions and 21 deletions

View file

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