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
commit 60d8852fc2
Notes: sideshowbarker 2024-07-18 08:35:49 +09:00
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("");
});