extend("test")
describe("2D array auto-upcast and MixedArray logic", () => {
it("should parse a purely int 2D array => int2d_array", () => {
arr = [[1,2],[3,4]]
expect_equal(type(arr), "int2d_array")
expect_equal(arr, [[1,2],[3,4]])
})
it("should parse a mixed int+float 2D => float2d_array with all floats", () => {
arr2 = [[12,13],[4,2.2]]
expect_equal(type(arr2), "float2d_array")
expect_equal(arr2, [[12.0,13.0],[4.0,2.2]])
})
it("should parse a 2D array with a string row as mixed_array", () => {
arr3 = [[1,2],[3,"x"]]
expect_equal(type(arr3), "mixed_array")
# The first row is [1,2] (int), second row is [3,"x"] (mixed)
# The array itself becomes MixedArray, so type(arr3) == "mixed_array"
})
it("should parse a 2D array with inconsistent row lengths as mixed_array", () => {
arr4 = [[1,2],[3]]
expect_equal(type(arr4), "mixed_array")
# 2D numeric arrays must have same-length rows for int2d/float2d; else, MixedArray
})
it("should parse a 2D array with rows of differing types as mixed_array", () => {
arr5 = [[1,2],[true,false]]
expect_equal(type(arr5), "mixed_array")
})
it("should parse a nested keyed array as a mixed_array", () => {
arr6 = [[1,2],[a:10, b:20]]
expect_equal(type(arr6), "mixed_array")
})
it("should parse a 2D array with an empty row as mixed_array", () => {
arr7 = [[1,2],[]]
expect_equal(type(arr7), "mixed_array")
})
it("should parse an all-float 2D array as float2d_array", () => {
arr8 = [[1.1, 2.2], [3.3, 4.4]]
expect_equal(type(arr8), "float2d_array")
expect_equal(arr8, [[1.1,2.2],[3.3,4.4]])
})
it("should parse a 2D array with bools as mixed_array", () => {
arr9 = [[true, false],[1,2]]
expect_equal(type(arr9), "mixed_array")
})
it("should treat a 2D array with all string rows as mixed_array", () => {
arr10 = [["foo","bar"],["baz","qux"]]
expect_equal(type(arr10), "mixed_array")
})
it("should parse a 2D array with nested arrays as mixed_array", () => {
arr11 = [[1,2],[3,[4,5]]]
expect_equal(type(arr11), "mixed_array")
})
})