mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-29 19:10:26 +00:00
LibJS: Add additional generic Array.prototype.slice tests
This commit is contained in:
parent
fc1168a3b3
commit
ae8b55a80a
Notes:
sideshowbarker
2024-07-18 12:16:05 +09:00
Author: https://github.com/davidot Commit: https://github.com/SerenityOS/serenity/commit/ae8b55a80a0 Pull-request: https://github.com/SerenityOS/serenity/pull/8025 Reviewed-by: https://github.com/linusg
1 changed files with 42 additions and 9 deletions
|
@ -40,15 +40,48 @@ describe("ability to work with generic non-array objects", () => {
|
|||
});
|
||||
|
||||
test("slice", () => {
|
||||
const o = { length: 3, 0: "hello", 2: "serenity" };
|
||||
const slice = Array.prototype.slice.call(o, 0, 2);
|
||||
expect(o).toHaveLength(3);
|
||||
expect(o[0]).toBe("hello");
|
||||
expect(o[1]).toBeUndefined();
|
||||
expect(o[2]).toBe("serenity");
|
||||
expect(slice).toHaveLength(2);
|
||||
expect(slice[0]).toBe("hello");
|
||||
expect(slice[1]).toBeUndefined();
|
||||
{
|
||||
const o = { length: 3, 0: "hello", 2: "serenity" };
|
||||
const slice = Array.prototype.slice.call(o, 0, 2);
|
||||
expect(o).toHaveLength(3);
|
||||
expect(o[0]).toBe("hello");
|
||||
expect(o[1]).toBeUndefined();
|
||||
expect(o[2]).toBe("serenity");
|
||||
expect(slice).toHaveLength(2);
|
||||
expect(slice[0]).toBe("hello");
|
||||
expect(slice[1]).toBeUndefined();
|
||||
}
|
||||
{
|
||||
const o = { length: 5, 0: "foo", 1: "bar", 3: "baz" };
|
||||
expect(Array.prototype.slice.call(o)).toEqual([
|
||||
"foo",
|
||||
"bar",
|
||||
undefined,
|
||||
"baz",
|
||||
undefined,
|
||||
]);
|
||||
expect(Array.prototype.slice.call(o, 0, 3)).toEqual(["foo", "bar", undefined]);
|
||||
expect(Array.prototype.slice.call(o, 0, 15)).toEqual([
|
||||
"foo",
|
||||
"bar",
|
||||
undefined,
|
||||
"baz",
|
||||
undefined,
|
||||
]);
|
||||
|
||||
expect(Array.prototype.slice.call(o, 1)).toEqual(["bar", undefined, "baz", undefined]);
|
||||
expect(Array.prototype.slice.call(o, 15)).toEqual([]);
|
||||
|
||||
expect(Array.prototype.slice.call(o, -1)).toEqual([undefined]);
|
||||
expect(Array.prototype.slice.call(o, -2)).toEqual(["baz", undefined]);
|
||||
|
||||
expect(Array.prototype.slice.call(o, 1, -1)).toEqual(["bar", undefined, "baz"]);
|
||||
expect(Array.prototype.slice.call(o, 2, -2)).toEqual([undefined]);
|
||||
|
||||
expect(Array.prototype.slice.call(o, 3, -3)).toEqual([]);
|
||||
expect(Array.prototype.slice.call(o, 0, 0)).toEqual([]);
|
||||
expect(Array.prototype.slice.call(o, 10, 10)).toEqual([]);
|
||||
}
|
||||
});
|
||||
|
||||
test("join", () => {
|
||||
|
|
Loading…
Reference in a new issue