|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
describe("Persist module", function()
|
|
|
|
|
local Persist
|
|
|
|
|
local sample
|
|
|
|
|
local bitserInstance, dumpInstance
|
|
|
|
|
local bitserInstance, luajitInstance, dumpInstance
|
|
|
|
|
local ser, deser, str, tab
|
|
|
|
|
local fail = { a = function() end, }
|
|
|
|
|
|
|
|
|
@ -29,12 +29,14 @@ describe("Persist module", function()
|
|
|
|
|
require("commonrequire")
|
|
|
|
|
Persist = require("persist")
|
|
|
|
|
bitserInstance = Persist:new{ path = "test.dat", codec = "bitser" }
|
|
|
|
|
luajitInstance = Persist:new{ path = "testj.dat", codec = "luajit" }
|
|
|
|
|
dumpInstance = Persist:new { path = "test.txt", codec = "dump" }
|
|
|
|
|
sample = arrayOf(1000)
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
it("should save a table to file", function()
|
|
|
|
|
assert.is_true(bitserInstance:save(sample))
|
|
|
|
|
assert.is_true(luajitInstance:save(sample))
|
|
|
|
|
assert.is_true(dumpInstance:save(sample))
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
@ -42,23 +44,30 @@ describe("Persist module", function()
|
|
|
|
|
assert.is_true(bitserInstance:exists())
|
|
|
|
|
assert.is_true(bitserInstance:size() > 0)
|
|
|
|
|
assert.is_true(type(bitserInstance:timestamp()) == "number")
|
|
|
|
|
|
|
|
|
|
assert.is_true(luajitInstance:exists())
|
|
|
|
|
assert.is_true(luajitInstance:size() > 0)
|
|
|
|
|
assert.is_true(type(luajitInstance:timestamp()) == "number")
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
it("should load a table from file", function()
|
|
|
|
|
assert.are.same(sample, bitserInstance:load())
|
|
|
|
|
assert.are.same(sample, luajitInstance:load())
|
|
|
|
|
assert.are.same(sample, dumpInstance:load())
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
it("should delete the file", function()
|
|
|
|
|
bitserInstance:delete()
|
|
|
|
|
luajitInstance:delete()
|
|
|
|
|
dumpInstance:delete()
|
|
|
|
|
assert.is_nil(bitserInstance:exists())
|
|
|
|
|
assert.is_nil(luajitInstance:exists())
|
|
|
|
|
assert.is_nil(dumpInstance:exists())
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
it("should return standalone serializers/deserializers", function()
|
|
|
|
|
tab = sample
|
|
|
|
|
for _, codec in ipairs({"dump", "bitser"}) do
|
|
|
|
|
for _, codec in ipairs({"dump", "bitser", "luajit"}) do
|
|
|
|
|
assert.is_true(Persist.getCodec(codec).id == codec)
|
|
|
|
|
ser = Persist.getCodec(codec).serialize
|
|
|
|
|
deser = Persist.getCodec(codec).deserialize
|
|
|
|
@ -69,15 +78,17 @@ describe("Persist module", function()
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
it("should work with huge tables", function()
|
|
|
|
|
tab = arrayOf(100000)
|
|
|
|
|
ser = Persist.getCodec("bitser").serialize
|
|
|
|
|
deser = Persist.getCodec("bitser").deserialize
|
|
|
|
|
str = ser(tab)
|
|
|
|
|
assert.are.same(deser(str), tab)
|
|
|
|
|
for _, codec in ipairs({"bitser", "luajit"}) do
|
|
|
|
|
tab = arrayOf(100000)
|
|
|
|
|
ser = Persist.getCodec(codec).serialize
|
|
|
|
|
deser = Persist.getCodec(codec).deserialize
|
|
|
|
|
str = ser(tab)
|
|
|
|
|
assert.are.same(deser(str), tab)
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
it ("should fail to serialize functions", function()
|
|
|
|
|
for _, codec in ipairs({"dump", "bitser"}) do
|
|
|
|
|
for _, codec in ipairs({"dump", "bitser", "luajit"}) do
|
|
|
|
|
assert.is_true(Persist.getCodec(codec).id == codec)
|
|
|
|
|
ser = Persist.getCodec(codec).serialize
|
|
|
|
|
deser = Persist.getCodec(codec).deserialize
|
|
|
|
|