Limit cleanup() calls to once per scope

This commit is contained in:
Aaron Smith 2023-08-22 11:46:56 +01:00
parent 2aebaf5abb
commit 0105e33fac
5 changed files with 63 additions and 5 deletions

View file

@ -547,6 +547,26 @@ TEST("cleanup()", function()
CHECK(objB.cleaned == 2)
end
-- this is not allowed, test to verify behavior anyways
do CASE "multiple cleanup"
local state = source(1)
local queue = {}
watch(function()
state()
cleanup(function() table.insert(queue, 1) end)
cleanup(function() table.insert(queue, 2) end)
end)
CHECK(testkit.seq(queue, { 1 }))
state(2)
CHECK(testkit.seq(queue, { 1, 2, 1 }))
state(3)
CHECK(testkit.seq(queue, { 1, 2, 1, 2, 1 }))
end
--[[
do CASE "multiple cleanup"
local state = source(1)
@ -574,6 +594,7 @@ TEST("cleanup()", function()
--testkit.print2(queue)
--CHECK(testkit.seq(queue, { 1, 2, 1, 2, 1, 2 }))
end
]]
end)
TEST("create()", function()
@ -1308,6 +1329,7 @@ TEST("strict", function()
local derive = vide.derive
local watch = vide.watch
local indexes, values = vide.indexes, vide.values
local cleanup = vide.cleanup
do CASE "error on derived callback yield"
local state = source(1)
@ -1410,6 +1432,15 @@ TEST("strict", function()
CHECK(ok)
end
do CASE "multiple cleanup per scope"
local ok = pcall(function()
cleanup(function() end)
cleanup(function() end)
end)
CHECK(not ok)
end
end)
local ok = FINISH()