mirror of
https://github.com/centau/vide.git
synced 2026-08-20 14:41:37 +00:00
Limit cleanup() calls to once per scope
This commit is contained in:
parent
2aebaf5abb
commit
0105e33fac
5 changed files with 63 additions and 5 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue