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

LibJS: Add UTF-16 tests to String.prototype methods that already work

These methods did not require UTF-16 views, so just add test cases to
ensure they remain correct.

This also adds a couple of FIXME comments on tests that will fail even
with UTF-16 String.prototype support (for reasons such as lack of UTF-16
support in RegExp.prototype and Unicode case folding).
This commit is contained in:
Timothy Flynn 2021-07-19 17:24:23 -04:00 committed by Andreas Kling
parent 9b83cd1abf
commit 0e25d2393f
6 changed files with 32 additions and 0 deletions

View file

@ -15,3 +15,10 @@ test("basic functionality", () => {
expect("".concat(1, {})).toBe("1[object Object]");
expect("".concat(1, {}, false)).toBe("1[object Object]false");
});
test("UTF-16", () => {
expect("😀".concat()).toBe("😀");
expect("😀".concat("a")).toBe("😀a");
expect("😀".concat("a", 4)).toBe("😀a4");
expect("😀".concat("a", "😀")).toBe("😀a😀");
});

View file

@ -23,3 +23,9 @@ test("throws correct range errors", () => {
"foo".repeat(Infinity);
}).toThrowWithMessage(RangeError, "repeat count must be a finite number");
});
test("UTF-16", () => {
expect("😀".repeat(0)).toBe("");
expect("😀".repeat(1)).toBe("😀");
expect("😀".repeat(10)).toBe("😀😀😀😀😀😀😀😀😀😀");
});

View file

@ -45,3 +45,11 @@ test("override exec with non-function", () => {
re.exec = 3;
expect("test".search(re)).toBe(0);
});
// FIXME: RegExp.prototype [ @@search ] needs to support UTF-16.
// test("UTF-16", () => {
// var s = "😀";
// expect(s.search("😀")).toBe(0);
// expect(s.search("\ud83d")).toBe(0);
// expect(s.search("\ude00")).toBe(1);
// });

View file

@ -4,3 +4,8 @@ test("basic functionality", () => {
expect("".toString()).toBe("");
expect("hello friends".toString()).toBe("hello friends");
});
test("UTF-16", () => {
expect("😀".toString()).toBe("😀");
expect("😀😀😀".toString()).toBe("😀😀😀");
});

View file

@ -61,4 +61,8 @@ test("multi-byte code point", () => {
expect("_\u180E".trim()).toBe("_\u180E");
expect("\u180E".trim()).toBe("\u180E");
expect("\u180E_".trim()).toBe("\u180E_");
expect("_😀".trim()).toBe("_😀");
expect("😀".trim()).toBe("😀");
expect("😀_".trim()).toBe("😀_");
});