2020-01-18 03:09:18 +01:00
|
|
|
_G.core = {}
|
|
|
|
|
2020-03-05 22:03:04 +01:00
|
|
|
_G.setfenv = require 'busted.compatibility'.setfenv
|
2020-01-18 03:09:18 +01:00
|
|
|
|
|
|
|
dofile("builtin/common/serialize.lua")
|
|
|
|
|
|
|
|
describe("serialize", function()
|
|
|
|
it("works", function()
|
|
|
|
local test_in = {cat={sound="nyan", speed=400}, dog={sound="woof"}}
|
|
|
|
local test_out = core.deserialize(core.serialize(test_in))
|
|
|
|
|
|
|
|
assert.same(test_in, test_out)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("handles characters", function()
|
|
|
|
local test_in = {escape_chars="\n\r\t\v\\\"\'", non_european="θשׁ٩∂"}
|
|
|
|
local test_out = core.deserialize(core.serialize(test_in))
|
|
|
|
assert.same(test_in, test_out)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("handles recursive structures", function()
|
|
|
|
local test_in = { hello = "world" }
|
|
|
|
test_in.foo = test_in
|
|
|
|
|
|
|
|
local test_out = core.deserialize(core.serialize(test_in))
|
|
|
|
assert.same(test_in, test_out)
|
|
|
|
end)
|
2020-03-05 22:03:04 +01:00
|
|
|
|
|
|
|
it("strips functions in safe mode", function()
|
|
|
|
local test_in = {
|
|
|
|
func = function(a, b)
|
|
|
|
error("test")
|
|
|
|
end,
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
|
|
|
|
local str = core.serialize(test_in)
|
|
|
|
assert.not_nil(str:find("loadstring"))
|
|
|
|
|
|
|
|
local test_out = core.deserialize(str, true)
|
|
|
|
assert.is_nil(test_out.func)
|
|
|
|
assert.equals(test_out.foo, "bar")
|
|
|
|
end)
|
2020-01-18 03:09:18 +01:00
|
|
|
end)
|