Add a test for recursive instances

Currently they are not supported (previously they would silently give potentially wrong output)
This commit is contained in:
Jasmijn Wellner 2024-12-29 17:29:36 +01:00
parent 8bfdf3a961
commit 608c1c4792

View File

@ -328,6 +328,21 @@ describe("bitser", function()
bitser.unregisterClass("class")
end)
it("cannot deserialize an instance nested within itself", function()
local class = {}
local instance = setmetatable({}, class)
local deserialize = function(_, _)
return instance
end
instance.myself = {instance}
bitser.registerClass("class", class, nil, deserialize)
assert.has_error(function() serdeser(instance) end, "trying to deserialize a value that has not yet been initialized")
bitser.unregisterClass("class")
end)
it("provides a simple extension mechanism", function()
local MATCH_CALLS = 0
local LOAD_CALLS = 0