extend("test")
extend("array")
describe("array:init", () => {
it("returns all but the last for int arrays", () => {
expect_equal(array:init([1,2,3]), [1,2])
})
it("returns an empty int array when input has one element", () => {
expect_equal(array:init([7]), [])
})
it("returns all but the last for float arrays", () => {
expect_equal(array:init([1.1,2.2,3.3]), [1.1,2.2])
})
it("returns all but the last for string arrays", () => {
expect_equal(array:init(["a","b","c"]), ["a","b"])
})
it("returns all but the last for bool arrays", () => {
expect_equal(array:init([true,false,true]), [true,false])
})
it("returns all but the last for mixed arrays", () => {
expect_equal(array:init([1,"x",true]), [1,"x"])
})
it("returns an empty array when input is already empty", () => {
expect_equal(array:init([]), [])
})
it("errors on non-array input", () => {
test:expect_error(() => array:init(123))
})
})