2018-07-19 10:40:25 -06:00
|
|
|
local utils = require 'utils'
|
|
|
|
|
|
|
|
function test.OrderedTable()
|
|
|
|
local t = utils.OrderedTable()
|
|
|
|
local keys = {'a', 'c', 'e', 'd', 'b', 'q', 58, -1.2}
|
|
|
|
for i = 1, #keys do
|
|
|
|
t[keys[i]] = i
|
|
|
|
end
|
|
|
|
local i = 1
|
|
|
|
for k, v in pairs(t) do
|
|
|
|
expect.eq(k, keys[i], 'key order')
|
|
|
|
expect.eq(v, i, 'correct value')
|
|
|
|
i = i + 1
|
|
|
|
end
|
|
|
|
end
|
2020-04-05 20:58:51 -06:00
|
|
|
|
2021-06-29 13:22:05 -06:00
|
|
|
function test.normalizePath()
|
|
|
|
expect.eq('imapath/file.csv', utils.normalizePath('imapath/file.csv'))
|
|
|
|
expect.eq('/ima/path', utils.normalizePath('/ima/path'))
|
|
|
|
expect.eq('ima/path', utils.normalizePath('ima//path'))
|
|
|
|
|
|
|
|
expect.eq('imapath', utils.normalizePath('imapath'))
|
|
|
|
expect.eq('/imapath', utils.normalizePath('/imapath'))
|
|
|
|
expect.eq('/imapath', utils.normalizePath('//imapath'))
|
|
|
|
expect.eq('/imapath', utils.normalizePath('///imapath'))
|
|
|
|
|
|
|
|
expect.eq('imapath/', utils.normalizePath('imapath/'))
|
|
|
|
expect.eq('imapath/', utils.normalizePath('imapath//'))
|
|
|
|
end
|
|
|
|
|
2020-04-05 20:58:51 -06:00
|
|
|
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
|
2021-05-04 12:55:21 -06:00
|
|
|
|