70 lines
No EOL
1.4 KiB
Lua
70 lines
No EOL
1.4 KiB
Lua
require "utils"
|
|
require "testtools"
|
|
|
|
function test_difference()
|
|
t1 = { 0, 1, 2, 3 }
|
|
t2 = { 3, 1, 5 }
|
|
t3 = collect(difference(t1, t2))
|
|
check_tables({0, 2}, t3)
|
|
end
|
|
|
|
function test_copytable()
|
|
t1 = {a = 1, b = 2, c = 3}
|
|
t2 = copytable(t1)
|
|
t3 = copytable(t1)
|
|
check_tables(t1, t2)
|
|
check_tables(t2, t3)
|
|
assert(not rawequal(t1, t2))
|
|
assert(not rawequal(t2, t3))
|
|
end
|
|
|
|
function test_updatetable()
|
|
t1 = {a = 1, b = 2, c = 3}
|
|
t2 = {a = 3, d = 4}
|
|
updatetable(t1, t2)
|
|
check_tables({a = 3, b = 2, c = 3, d = 4}, t1)
|
|
check_tables({a = 3, d = 4}, t2)
|
|
end
|
|
|
|
function test_mergetables()
|
|
t1 = {a = 1, b = 2, c = 3}
|
|
t2 = {a = 3, d = 4}
|
|
t = mergetables(t1, t2)
|
|
check_tables({a = 3, b = 2, c = 3, d = 4}, t)
|
|
check_tables({a = 1, b = 2, c = 3}, t1)
|
|
check_tables({a = 3, d = 4}, t2)
|
|
end
|
|
|
|
function test_joinpath()
|
|
res = joinpath("a", "b/c", "d")
|
|
assert("a/b/c/d" == res)
|
|
end
|
|
|
|
function test_joindir()
|
|
res = joindir("a", "b/c", "d")
|
|
assert("a/b/c/d/" == res)
|
|
end
|
|
|
|
local T1 = {
|
|
a = 1,
|
|
b = 2
|
|
}
|
|
|
|
function T1:New(o)
|
|
o = o or {}
|
|
setmetatable(o, self)
|
|
self.__index = self
|
|
return o
|
|
end
|
|
|
|
local T2 = T1:New{
|
|
a = 3,
|
|
c = 4
|
|
}
|
|
|
|
function test_enumerate_members()
|
|
local t3 = T2:New{ d = 5 }
|
|
local members = collect(unique(enumerate_members(t3)))
|
|
table.sort(members)
|
|
check_tables({"New", "__index", "a", "b", "c", "d"}, members)
|
|
end |