-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.lua
More file actions
83 lines (73 loc) · 1.86 KB
/
test.lua
File metadata and controls
83 lines (73 loc) · 1.86 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
local printf
if unpack ~= nil then
printf = function(fmt, ...)
io.stdout:write(string.format(fmt, unpack(arg)))
end
else
printf = function(fmt, ...)
io.stdout:write(string.format(fmt, ...))
end
end
package.cpath = "./?.so"
local shelve = assert(require("shelve"))
print("Opening 'db'")
os.remove("test.db")
local db = assert(shelve.open("test.db"))
local num_keys = 0
for key in db() do num_keys = num_keys + 1 end
assert(num_keys == 0)
a = "one"
b = "two"
c = "three"
db.num = 1234567890 -- a number
db.str = "a string" -- a string
db.t1 = {} -- an empty table
db.t2 = { s="S" } -- table with one element
db.t3 = { a,b,c } -- indexed table, multiple elements
for key in db() do num_keys = num_keys + 1 end
assert(num_keys == 5)
db.nested = -- nested tables
{
level = a,
nest = {
level = b,
nest = {
level = c,
nest = "nothing"
}
}
}
printf("Number encoding... ")
assert(type(db.num) == "number")
assert(db.num == 1234567890)
printf("ok\nString encoding... ")
assert(db.str == "a string")
printf("ok\nTable encoding... ")
assert(type(db.t1) == "table")
assert(type(db.t2) == "table")
assert(type(db.t3) == "table")
printf("ok\nData integrity... ")
assert(db.t2.s == "S")
assert(db.t3[1] == a)
assert(db.t3[2] == b)
assert(db.t3[3] == c)
t = db.nested
assert(type(t) == "table")
assert(t.level == a)
assert(type(t.nest) == "table")
assert(t.nest.level == b)
assert(type(t.nest.nest) == "table")
assert(t.nest.nest.level == c)
assert(type(t.nest.nest.nest) == "string")
assert(t.nest.nest.nest == "nothing")
printf("ok\nLarge file storing... ")
fd, err = io.open("LICENSE", "r")
if (not fd) then
print(err)
os.exit()
end
lgpl_license = fd:read("*a")
fd:close()
db.lic = lgpl_license
assert(db.lic == lgpl_license)
printf("ok\n... all tests successfully passed ...\n")