-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathtest_serialization.lua
More file actions
67 lines (58 loc) · 1.49 KB
/
Copy pathtest_serialization.lua
File metadata and controls
67 lines (58 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
local lt = require "ltest"
local seri = require "bee.serialization"
local function TestEq(...)
lt.assertEquals(
table.pack(seri.unpack(seri.pack(...))),
table.pack(...)
)
lt.assertEquals(
table.pack(seri.unpack(seri.packstring(...))),
table.pack(...)
)
end
local function TestErr(msg, ...)
lt.assertErrorMsgEquals(msg, seri.pack, ...)
lt.assertErrorMsgEquals(msg, seri.packstring, ...)
end
local test_seri = lt.test "serialization"
function test_seri:test_ok_1()
TestEq(1)
TestEq(0.0001)
TestEq("TEST")
TestEq(true)
TestEq(false)
TestEq({})
TestEq({ 1, 2 })
TestEq(1, { 1, 2 })
TestEq(1, 2, { A = { B = { C = "D" } } })
TestEq(1, nil, 2)
end
function test_seri:test_err_1()
TestErr("Only light C function can be serialized", function () end)
TestErr("Only light C function can be serialized", require)
TestEq(os.clock)
end
function test_seri:test_err_2()
TestErr("Unsupport type thread to serialize", coroutine.create(function () end))
end
function test_seri:test_err_3()
TestErr("Unsupport type userdata to serialize", io.stdout)
end
function test_seri:test_ref()
local N <const> = 10
local t = {}
for i = 1, N do
t[i] = {}
end
for i = 1, N do
for j = 1, N do
t[i][j] = t[j]
end
end
local newt = seri.unpack(seri.pack(t))
for i = 1, N do
for j = 1, N do
lt.assertEquals(newt[i][j], newt[j])
end
end
end