Update indexes() test

This commit is contained in:
Aaron Smith 2023-09-19 12:20:03 +01:00
parent 250c13e7b8
commit 520b0cca32

View file

@ -1031,6 +1031,7 @@ end))
TEST("indexes()", wrap_root(function()
local create = vide.create
local source = vide.source
local effect = vide.effect
local indexes = vide.indexes
local cleanup = vide.cleanup
@ -1166,6 +1167,42 @@ TEST("indexes()", wrap_root(function()
CHECK(n0 == n1)
end
-- practical example based on the graph - recursive update test
do CASE "recursive update"
local items = source { 1 }
local updated = table.create(100, 0)
local elements = indexes(items, function(item)
effect(function()
item()
updated[1] += 1
end)
effect(function()
item()
updated[2] += 1
end)
end)
effect(function()
items()
updated[3] += 1
end)
effect(function()
items()
updated[4] += 1
end)
items { 2 }
CHECK(updated[1] == 2)
CHECK(updated[2] == 2)
CHECK(updated[3] == 2)
CHECK(updated[4] == 2)
end
end))
TEST("values()", wrap_root(function()