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

LibJS: Implement normative change in String.prototype.substr

And add spec comments while we're in the neighborhood.
This commit is contained in:
davidot 2022-09-20 23:59:11 +02:00 committed by Linus Groh
parent 60a6bae53d
commit 446a10a1ac
2 changed files with 35 additions and 3 deletions

View file

@ -21,6 +21,24 @@ test("basic functionality", () => {
expect("hello friends".substr(-3, -5)).toBe("");
});
test("Non numeric values", () => {
expect("a".substr(0, Infinity)).toBe("a");
expect("a".substr(0, -Infinity)).toBe("");
expect("abc".substr(0, Infinity)).toBe("abc");
expect("abc".substr(0, -Infinity)).toBe("");
expect("abc".substr(Infinity, Infinity)).toBe("");
expect("abc".substr(Infinity)).toBe("");
expect("abc".substr(-Infinity)).toBe("abc");
expect("abc".substr(-Infinity, 1)).toBe("a");
expect("abc".substr(-Infinity, Infinity)).toBe("abc");
expect("abc".substr(NaN)).toBe("abc");
expect("abc".substr(NaN, NaN)).toBe("");
expect("abc".substr(0, NaN)).toBe("");
expect("abc".substr(NaN, Infinity)).toBe("abc");
expect("abc".substr(NaN, -Infinity)).toBe("");
});
test("UTF-16", () => {
var s = "😀";
expect(s).toHaveLength(2);