mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-07 11:39:44 +03:00
LibJS: Implement tests for Array.prototype.flat
This commit is contained in:
parent
3940635ed3
commit
cfb0f3309d
Notes:
sideshowbarker
2024-07-18 22:10:11 +09:00
Author: https://github.com/brendalf 🔰 Commit: https://github.com/SerenityOS/serenity/commit/cfb0f3309d8 Pull-request: https://github.com/SerenityOS/serenity/pull/5381 Reviewed-by: https://github.com/linusg ✅
@ -0,0 +1,43 @@
|
||||
test("length is 0", () => {
|
||||
expect(Array.prototype.flat).toHaveLength(0);
|
||||
});
|
||||
|
||||
describe("normal behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
var array1 = [1, 2, [3, 4]];
|
||||
var array2 = [1, 2, [3, 4, [5, 6]]];
|
||||
var array3 = [1, 2, [3, 4, [5, 6]]];
|
||||
expect(array1.flat()).toEqual([1, 2, 3, 4]);
|
||||
expect(array2.flat()).toEqual([1, 2, 3, 4, [5, 6]]);
|
||||
expect(array3.flat(2)).toEqual([1, 2, 3, 4, 5, 6]);
|
||||
});
|
||||
|
||||
test("calls depth as infinity", () => {
|
||||
var array1 = [1, 2, [3, 4, [5, 6, [7, 8]]]];
|
||||
expect(array1.flat(Infinity)).toEqual([1, 2, 3, 4, 5, 6, 7, 8]);
|
||||
expect(array1.flat(-Infinity)).toEqual([1, 2, [3, 4, [5, 6, [7, 8]]]]);
|
||||
});
|
||||
|
||||
test("calls depth as undefined", () => {
|
||||
var array1 = [1, 2, [3, 4, [5, 6, [7, 8]]]];
|
||||
expect(array1.flat(undefined)).toEqual([1, 2, 3, 4, [5, 6, [7, 8]]]);
|
||||
});
|
||||
|
||||
test("calls depth as null", () => {
|
||||
var array1 = [1, 2, [3, 4, [5, 6, [7, 8]]]];
|
||||
expect(array1.flat(null)).toEqual([1, 2, [3, 4, [5, 6, [7, 8]]]]);
|
||||
expect(array1.flat(NaN)).toEqual([1, 2, [3, 4, [5, 6, [7, 8]]]]);
|
||||
});
|
||||
|
||||
test("calls depth as non integer", () => {
|
||||
var array1 = [1, 2, [3, 4, [5, 6, [7, 8]]]];
|
||||
expect(array1.flat("depth")).toEqual([1, 2, [3, 4, [5, 6, [7, 8]]]]);
|
||||
expect(array1.flat("2")).toEqual([1, 2, 3, 4, 5, 6, [7, 8]]);
|
||||
expect(array1.flat(2.1)).toEqual([1, 2, 3, 4, 5, 6, [7, 8]]);
|
||||
expect(array1.flat(0.7)).toEqual([1, 2, [3, 4, [5, 6, [7, 8]]]]);
|
||||
expect(array1.flat([2])).toEqual([1, 2, 3, 4, 5, 6, [7, 8]]);
|
||||
expect(array1.flat([2, 1])).toEqual([1, 2, [3, 4, [5, 6, [7, 8]]]]);
|
||||
expect(array1.flat({})).toEqual([1, 2, [3, 4, [5, 6, [7, 8]]]]);
|
||||
expect(array1.flat({ depth: 2 })).toEqual([1, 2, [3, 4, [5, 6, [7, 8]]]]);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user