mirror of
https://github.com/centau/vide.git
synced 2026-08-20 14:41:37 +00:00
Add tests for show() and read()
This commit is contained in:
parent
cc4b390d3d
commit
97096f8aff
1 changed files with 44 additions and 0 deletions
|
|
@ -920,6 +920,22 @@ TEST("create()", wrap_root(function()
|
||||||
end
|
end
|
||||||
end))
|
end))
|
||||||
|
|
||||||
|
TEST("show()", wrap_root(function()
|
||||||
|
-- uses switch() internally, more extensive testing of scoping not needed
|
||||||
|
local source = vide.source
|
||||||
|
local show = vide.show
|
||||||
|
|
||||||
|
local value = source("truey" :: unknown)
|
||||||
|
local function one() return 1 end
|
||||||
|
local function two() return 2 end
|
||||||
|
|
||||||
|
local output = show(value, one, two)
|
||||||
|
|
||||||
|
CHECK(output() == 1)
|
||||||
|
value(nil)
|
||||||
|
CHECK(output() == 2)
|
||||||
|
end))
|
||||||
|
|
||||||
TEST("switch()", wrap_root(function()
|
TEST("switch()", wrap_root(function()
|
||||||
local source = vide.source
|
local source = vide.source
|
||||||
local switch = vide.switch
|
local switch = vide.switch
|
||||||
|
|
@ -1646,6 +1662,34 @@ TEST("changed()", wrap_root(function()
|
||||||
end
|
end
|
||||||
end))
|
end))
|
||||||
|
|
||||||
|
TEST("read()", wrap_root(function()
|
||||||
|
local source = vide.source
|
||||||
|
local effect = vide.effect
|
||||||
|
local read = vide.read :: any -- todo
|
||||||
|
|
||||||
|
do CASE "read primitive"
|
||||||
|
CHECK(read(1) == 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
do CASE "read source"
|
||||||
|
local src = source(1) :: () -> number
|
||||||
|
CHECK(read(src) == 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
do CASE "track source"
|
||||||
|
local src = source(0)
|
||||||
|
|
||||||
|
local count = 0
|
||||||
|
effect(function()
|
||||||
|
read(src)
|
||||||
|
count += 1
|
||||||
|
end)
|
||||||
|
|
||||||
|
src(1)
|
||||||
|
CHECK(count == 2)
|
||||||
|
end
|
||||||
|
end))
|
||||||
|
|
||||||
vide.strict = true
|
vide.strict = true
|
||||||
|
|
||||||
TEST("strict", wrap_root(function()
|
TEST("strict", wrap_root(function()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue