1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 03:47:34 +00:00

LibJS: Add a basic implementation of String.prototype.substr()

This commit is contained in:
Andreas Kling 2020-11-29 20:28:10 +01:00
parent 5c911ad4b1
commit 2d9d883274
4 changed files with 54 additions and 1 deletions

View file

@ -0,0 +1,16 @@
test("basic functionality", () => {
expect(String.prototype.substr).toHaveLength(2);
expect("hello friends".substr()).toBe("hello friends");
expect("hello friends".substr(1)).toBe("ello friends");
expect("hello friends".substr(0, 5)).toBe("hello");
expect("hello friends".substr(5, 6)).toBe(" frien");
expect("hello friends".substr("", 5)).toBe("hello");
expect("hello friends".substr(3, 3)).toBe("lo ");
expect("hello friends".substr(-1, 13)).toBe("s");
expect("hello friends".substr(0, 50)).toBe("hello friends");
expect("hello friends".substr(0, "5")).toBe("hello");
expect("hello friends".substr("2", "2")).toBe("ll");
expect("hello friends".substr(-7)).toBe("friends");
expect("hello friends".substr(-3, -5)).toBe("");
});