mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 21:58:12 +00:00
LibJS: Report string properties using UTF-16 code units
String length is reported as the number of UTF-16 code units, and string indices are reported as the UTF-16 code units themselves.
This commit is contained in:
parent
0c42aece36
commit
2bba20d123
2 changed files with 33 additions and 7 deletions
|
@ -13,4 +13,30 @@ test("length", () => {
|
|||
expect(new String("a").length).toBe(1);
|
||||
expect(new String("\u180E").length).toBe(1);
|
||||
expect(new String("\uDBFF\uDFFF").length).toBe(2);
|
||||
|
||||
// Issue #2280
|
||||
expect("⛳".length).toBe(1);
|
||||
expect("🔥".length).toBe(2);
|
||||
expect("🔥🔥🔥".length).toBe(6);
|
||||
expect("👨👩👦".length).toBe(8);
|
||||
expect("👩❤️💋👩".length).toBe(11);
|
||||
});
|
||||
|
||||
test("indices", () => {
|
||||
expect("abc"[0]).toBe("a");
|
||||
expect("abc"[1]).toBe("b");
|
||||
expect("abc"[2]).toBe("c");
|
||||
expect("abc"[3]).toBeUndefined();
|
||||
|
||||
expect("😀"[0]).toBe("\ud83d");
|
||||
expect("😀"[1]).toBe("\ude00");
|
||||
expect("😀"[2]).toBeUndefined();
|
||||
});
|
||||
|
||||
test("properties", () => {
|
||||
expect(Object.getOwnPropertyNames("")).toEqual(["length"]);
|
||||
expect(Object.getOwnPropertyNames("a")).toEqual(["0", "length"]);
|
||||
expect(Object.getOwnPropertyNames("ab")).toEqual(["0", "1", "length"]);
|
||||
expect(Object.getOwnPropertyNames("abc")).toEqual(["0", "1", "2", "length"]);
|
||||
expect(Object.getOwnPropertyNames("😀")).toEqual(["0", "1", "length"]);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue