|
|
@ -13,3 +13,30 @@ function test.OrderedTable()
|
|
|
|
i = i + 1
|
|
|
|
i = i + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function test.invert()
|
|
|
|
|
|
|
|
local t = {}
|
|
|
|
|
|
|
|
local i = utils.invert{'a', 4.4, false, true, 5, t}
|
|
|
|
|
|
|
|
expect.eq(i.a, 1)
|
|
|
|
|
|
|
|
expect.eq(i[4.4], 2)
|
|
|
|
|
|
|
|
expect.eq(i[false], 3)
|
|
|
|
|
|
|
|
expect.eq(i[true], 4)
|
|
|
|
|
|
|
|
expect.eq(i[5], 5)
|
|
|
|
|
|
|
|
expect.eq(i[t], 6)
|
|
|
|
|
|
|
|
expect.eq(i[700], nil)
|
|
|
|
|
|
|
|
expect.eq(i.foo, nil)
|
|
|
|
|
|
|
|
expect.eq(i[{}], nil)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function test.invert_nil()
|
|
|
|
|
|
|
|
local i = utils.invert{'a', nil, 'b'}
|
|
|
|
|
|
|
|
expect.eq(i.a, 1)
|
|
|
|
|
|
|
|
expect.eq(i[nil], nil)
|
|
|
|
|
|
|
|
expect.eq(i.b, 3)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function test.invert_overwrite()
|
|
|
|
|
|
|
|
local i = utils.invert{'a', 'b', 'a'}
|
|
|
|
|
|
|
|
expect.eq(i.b, 2)
|
|
|
|
|
|
|
|
expect.eq(i.a, 3)
|
|
|
|
|
|
|
|
end
|
|
|
|