mirror of
https://github.com/centau/vide.git
synced 2026-10-23 14:21:38 +00:00
Merge branch 'main' into fix-strict-non-string-error
This commit is contained in:
commit
e0e9db253f
8 changed files with 236 additions and 49 deletions
164
test/tests.luau
164
test/tests.luau
|
|
@ -633,6 +633,25 @@ TEST("effect()", wrap_root(function()
|
|||
|
||||
CHECK(count == 2)
|
||||
end
|
||||
|
||||
do CASE "error does not stop other effects"
|
||||
local src = source(0)
|
||||
|
||||
local count = 0
|
||||
effect(function()
|
||||
if src() == 1 then error("effect error") end
|
||||
end)
|
||||
effect(function()
|
||||
src()
|
||||
count += 1
|
||||
end)
|
||||
|
||||
CHECK(count == 1)
|
||||
CHECK(not pcall(src, 1))
|
||||
CHECK(count == 2)
|
||||
src(2)
|
||||
CHECK(count == 3)
|
||||
end
|
||||
end))
|
||||
|
||||
TEST("cleanup()", wrap_root(function()
|
||||
|
|
@ -709,6 +728,46 @@ TEST("cleanup()", wrap_root(function()
|
|||
CHECK(ran.destroy)
|
||||
CHECK(ran.Destroy)
|
||||
end
|
||||
|
||||
do CASE "error does not stop destruction"
|
||||
local src = source(0)
|
||||
|
||||
local cleaned = false
|
||||
local count = 0
|
||||
|
||||
local destroy = root(function()
|
||||
cleanup(function() error("cleanup error") end)
|
||||
cleanup(function() cleaned = true end)
|
||||
effect(function()
|
||||
src()
|
||||
count += 1
|
||||
end)
|
||||
end)
|
||||
|
||||
CHECK(not pcall(destroy))
|
||||
CHECK(cleaned)
|
||||
src(1)
|
||||
CHECK(count == 1)
|
||||
end
|
||||
|
||||
do CASE "error on rerun does not stop updates"
|
||||
local src = source(0)
|
||||
|
||||
local count = 0
|
||||
effect(function()
|
||||
src()
|
||||
cleanup(function() if src() == 1 then error("cleanup error") end end)
|
||||
end)
|
||||
effect(function()
|
||||
src()
|
||||
count += 1
|
||||
end)
|
||||
|
||||
CHECK(not pcall(src, 1))
|
||||
CHECK(count == 2)
|
||||
src(2)
|
||||
CHECK(count == 3)
|
||||
end
|
||||
end))
|
||||
|
||||
TEST("create()", wrap_root(function()
|
||||
|
|
@ -1050,6 +1109,33 @@ TEST("create()", wrap_root(function()
|
|||
CHECK(parent:FindFirstChild "c")
|
||||
end
|
||||
|
||||
do CASE "children moved to another parent"
|
||||
local other = create "Frame" {}
|
||||
|
||||
local child = create "Frame" {}
|
||||
local children_a = source { child }
|
||||
local children_b = source {}
|
||||
create "Frame" { children_a }
|
||||
local parent_b = create "Frame" { children_b }
|
||||
|
||||
children_b { child }
|
||||
children_a {}
|
||||
CHECK(child.Parent == parent_b)
|
||||
|
||||
local a = create "Frame" {}
|
||||
local b = create "Frame" {}
|
||||
local destroy = root(function()
|
||||
create "Frame" { function() return a end }
|
||||
create "Frame" { function() return { function() return b end } end }
|
||||
end)
|
||||
|
||||
a.Parent = other
|
||||
b.Parent = other
|
||||
destroy()
|
||||
CHECK(a.Parent == other)
|
||||
CHECK(b.Parent == other)
|
||||
end
|
||||
|
||||
do CASE "garbage collection test"
|
||||
local wref
|
||||
|
||||
|
|
@ -1539,6 +1625,25 @@ TEST("switch()", wrap_root(function()
|
|||
do CASE "delay"
|
||||
-- probably unneeded because show() uses switch() internally
|
||||
end
|
||||
|
||||
do CASE "delay with cleanup error"
|
||||
local input = source(1)
|
||||
local errored = false
|
||||
|
||||
local output = switch(input) {
|
||||
[1] = function()
|
||||
cleanup(function()
|
||||
if not errored then errored = true; error("cleanup error") end
|
||||
end)
|
||||
return 1, 1
|
||||
end,
|
||||
[2] = function() return 2 end
|
||||
}
|
||||
|
||||
input(2)
|
||||
CHECK(not pcall(step, 1 + 0.01))
|
||||
CHECK(output() == 2)
|
||||
end
|
||||
end))
|
||||
|
||||
TEST("indexes()", wrap_root(function()
|
||||
|
|
@ -1809,6 +1914,23 @@ TEST("indexes()", wrap_root(function()
|
|||
CHECK(cleaned_counts[2] == 1)
|
||||
end
|
||||
end
|
||||
|
||||
do CASE "delay with cleanup error"
|
||||
local input = source { 1 }
|
||||
local errored = false
|
||||
|
||||
local output = indexes(input, function()
|
||||
cleanup(function()
|
||||
if not errored then errored = true; error("cleanup error") end
|
||||
end)
|
||||
return {}, 1
|
||||
end)
|
||||
|
||||
input {}
|
||||
CHECK(#output() == 1)
|
||||
CHECK(not pcall(step, 1 + 0.01))
|
||||
CHECK(#output() == 0)
|
||||
end
|
||||
end))
|
||||
|
||||
TEST("values()", wrap_root(function()
|
||||
|
|
@ -2024,6 +2146,23 @@ TEST("values()", wrap_root(function()
|
|||
--CHECK(count == 3)
|
||||
CHECK(count == 5)
|
||||
end
|
||||
|
||||
do CASE "delay with cleanup error"
|
||||
local input = source { 1 }
|
||||
local errored = false
|
||||
|
||||
local output = values(input, function()
|
||||
cleanup(function()
|
||||
if not errored then errored = true; error("cleanup error") end
|
||||
end)
|
||||
return {}, 1
|
||||
end)
|
||||
|
||||
input {}
|
||||
CHECK(#output() == 1)
|
||||
CHECK(not pcall(step, 1 + 0.01))
|
||||
CHECK(#output() == 0)
|
||||
end
|
||||
end))
|
||||
|
||||
TEST("spring()", wrap_root(function()
|
||||
|
|
@ -2769,6 +2908,16 @@ TEST("context()", function()
|
|||
end)
|
||||
end)
|
||||
end
|
||||
|
||||
do CASE "get context without default"
|
||||
local ctx = context()
|
||||
|
||||
CHECK(not pcall(ctx))
|
||||
|
||||
root(function()
|
||||
CHECK(not pcall(ctx))
|
||||
end)
|
||||
end
|
||||
end)
|
||||
|
||||
TEST("nested effects cases", function()
|
||||
|
|
@ -3121,6 +3270,21 @@ TEST("strict", wrap_root(function()
|
|||
CHECK(count == 4)
|
||||
end
|
||||
|
||||
do CASE "effect updating its own source"
|
||||
local src = source(0)
|
||||
local count = 0
|
||||
|
||||
effect(function()
|
||||
count += 1
|
||||
if count > 100 then return end
|
||||
local v = src()
|
||||
if v > 0 then src(v + 1) end
|
||||
end)
|
||||
|
||||
CHECK(not pcall(src, 1))
|
||||
CHECK(count < 100)
|
||||
end
|
||||
|
||||
do CASE "destruction of active scope"
|
||||
local src = source(false)
|
||||
local count = 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue