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

LibJS: Add String.prototype.slice

This commit is contained in:
Kesse Jones 2020-04-29 08:42:00 -03:00 committed by Andreas Kling
parent bf727eb44c
commit 58f6f50de4
3 changed files with 65 additions and 0 deletions

View file

@ -0,0 +1,22 @@
load("test-common.js");
try {
assert(String.prototype.slice.length === 2);
assert("hello friends".slice() === "hello friends");
assert("hello friends".slice(1) === "ello friends");
assert("hello friends".slice(0, 5) === "hello");
assert("hello friends".slice(13, 6) === "");
assert("hello friends".slice('', 5) === "hello");
assert("hello friends".slice(3, 3) === "");
assert("hello friends".slice(-1, 13) === "s");
assert("hello friends".slice(0, 50) === "hello friends");
assert("hello friends".slice(0, "5") === "hello");
assert("hello friends".slice("6", "13") === "friends");
assert("hello friends".slice(-7) === "friends");
assert("hello friends".slice(1000) === "");
assert("hello friends".slice(-1000) === "hello friends");
console.log("PASS");
} catch (err) {
console.log("FAIL: " + err);
}