mirror of
https://github.com/lune-org/lune.git
synced 2024-12-12 13:00:37 +00:00
Update unit tests & typedefs
This commit is contained in:
parent
ee3403d44d
commit
af8eb08433
5 changed files with 29 additions and 15 deletions
|
@ -53,19 +53,19 @@ declare process: {
|
||||||
}
|
}
|
||||||
|
|
||||||
declare task: {
|
declare task: {
|
||||||
cancel: (t: thread) -> (),
|
cancel: (thread: thread) -> (),
|
||||||
defer: (f: thread | (...any) -> (...any)) -> thread,
|
defer: (functionOrThread: thread | (...any) -> (...any)) -> thread,
|
||||||
delay: (duration: number?, f: thread | (...any) -> (...any)) -> thread,
|
delay: (duration: number?, functionOrThread: thread | (...any) -> (...any)) -> thread,
|
||||||
spawn: (f: thread | (...any) -> (...any)) -> thread,
|
spawn: (functionOrThread: thread | (...any) -> (...any)) -> thread,
|
||||||
wait: (duration: number?) -> (number),
|
wait: (duration: number?) -> (number),
|
||||||
}
|
}
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
declare task: {
|
declare task: {
|
||||||
cancel: (t: thread) -> (),
|
cancel: (thread: thread) -> (),
|
||||||
defer: <T...>(f: thread | (T...) -> (...any), T...) -> thread,
|
defer: <T...>(functionOrThread: thread | (T...) -> (...any), T...) -> thread,
|
||||||
delay: <T...>(duration: number?, f: thread | (T...) -> (...any), T...) -> thread,
|
delay: <T...>(duration: number?, functionOrThread: thread | (T...) -> (...any), T...) -> thread,
|
||||||
spawn: <T...>(f: thread | (T...) -> (...any), T...) -> thread,
|
spawn: <T...>(functionOrThread: thread | (T...) -> (...any), T...) -> thread,
|
||||||
wait: (duration: number?) -> (number),
|
wait: (duration: number?) -> (number),
|
||||||
}
|
}
|
||||||
]]
|
]]
|
||||||
|
|
|
@ -2,14 +2,16 @@
|
||||||
|
|
||||||
local flag: boolean = false
|
local flag: boolean = false
|
||||||
local thread = task.defer(function()
|
local thread = task.defer(function()
|
||||||
|
task.wait(0.1)
|
||||||
flag = true
|
flag = true
|
||||||
end)
|
end)
|
||||||
local thread2 = task.delay(0, function()
|
local thread2 = task.delay(0, function()
|
||||||
|
task.wait(0.1)
|
||||||
flag = true
|
flag = true
|
||||||
end)
|
end)
|
||||||
task.cancel(thread)
|
task.cancel(thread)
|
||||||
task.cancel(thread2)
|
task.cancel(thread2)
|
||||||
task.wait(0.1)
|
task.wait(0.2)
|
||||||
assert(not flag, "Cancel should handle non-immediate threads")
|
assert(not flag, "Cancel should handle non-immediate threads")
|
||||||
|
|
||||||
-- Cancellation should be as immediate as possible
|
-- Cancellation should be as immediate as possible
|
||||||
|
|
|
@ -40,6 +40,8 @@ assert(not flag2, "Defer should run after spawned threads")
|
||||||
|
|
||||||
-- Varargs should get passed correctly
|
-- Varargs should get passed correctly
|
||||||
|
|
||||||
|
-- TODO: Uncomment when vararg support is added
|
||||||
|
--[[
|
||||||
local function f(arg1: string, arg2: number, f2: (...any) -> ...any)
|
local function f(arg1: string, arg2: number, f2: (...any) -> ...any)
|
||||||
assert(type(arg1) == "string", "Invalid arg 1 passed to function")
|
assert(type(arg1) == "string", "Invalid arg 1 passed to function")
|
||||||
assert(type(arg2) == "number", "Invalid arg 2 passed to function")
|
assert(type(arg2) == "number", "Invalid arg 2 passed to function")
|
||||||
|
@ -49,5 +51,4 @@ end
|
||||||
task.defer(f, "", 1, f)
|
task.defer(f, "", 1, f)
|
||||||
task.defer(f, "inf", math.huge, f)
|
task.defer(f, "inf", math.huge, f)
|
||||||
task.defer(f, "NaN", 0 / 0, f)
|
task.defer(f, "NaN", 0 / 0, f)
|
||||||
|
]]
|
||||||
task.wait(0.1)
|
|
||||||
|
|
|
@ -28,6 +28,8 @@ assert(not flag2, "Delay should work with yielding (2)")
|
||||||
|
|
||||||
-- Varargs should get passed correctly
|
-- Varargs should get passed correctly
|
||||||
|
|
||||||
|
-- TODO: Uncomment when vararg support is added
|
||||||
|
--[[
|
||||||
local function f(arg1: string, arg2: number, f2: (...any) -> ...any)
|
local function f(arg1: string, arg2: number, f2: (...any) -> ...any)
|
||||||
assert(type(arg1) == "string", "Invalid arg 1 passed to function")
|
assert(type(arg1) == "string", "Invalid arg 1 passed to function")
|
||||||
assert(type(arg2) == "number", "Invalid arg 2 passed to function")
|
assert(type(arg2) == "number", "Invalid arg 2 passed to function")
|
||||||
|
@ -37,5 +39,4 @@ end
|
||||||
task.delay(0, f, "", 1, f)
|
task.delay(0, f, "", 1, f)
|
||||||
task.delay(0, f, "inf", math.huge, f)
|
task.delay(0, f, "inf", math.huge, f)
|
||||||
task.delay(0, f, "NaN", 0 / 0, f)
|
task.delay(0, f, "NaN", 0 / 0, f)
|
||||||
|
]]
|
||||||
task.wait(0.1)
|
|
||||||
|
|
|
@ -22,8 +22,19 @@ assert(not flag2, "Spawn should work with yielding (1)")
|
||||||
task.wait(0.2)
|
task.wait(0.2)
|
||||||
assert(flag2, "Spawn should work with yielding (2)")
|
assert(flag2, "Spawn should work with yielding (2)")
|
||||||
|
|
||||||
|
-- Spawned functions should be able to run threads created with the coroutine global
|
||||||
|
|
||||||
|
local flag3: boolean = false
|
||||||
|
local thread2 = coroutine.create(function()
|
||||||
|
flag3 = true
|
||||||
|
end)
|
||||||
|
task.spawn(thread2)
|
||||||
|
assert(flag3, "Spawn should run threads made from coroutine.create")
|
||||||
|
|
||||||
-- Varargs should get passed correctly
|
-- Varargs should get passed correctly
|
||||||
|
|
||||||
|
-- TODO: Uncomment when vararg support is added
|
||||||
|
--[[
|
||||||
local function f(arg1: string, arg2: number, f2: (...any) -> ...any)
|
local function f(arg1: string, arg2: number, f2: (...any) -> ...any)
|
||||||
assert(type(arg1) == "string", "Invalid arg 1 passed to function")
|
assert(type(arg1) == "string", "Invalid arg 1 passed to function")
|
||||||
assert(type(arg2) == "number", "Invalid arg 2 passed to function")
|
assert(type(arg2) == "number", "Invalid arg 2 passed to function")
|
||||||
|
@ -33,5 +44,4 @@ end
|
||||||
task.spawn(f, "", 1, f)
|
task.spawn(f, "", 1, f)
|
||||||
task.spawn(f, "inf", math.huge, f)
|
task.spawn(f, "inf", math.huge, f)
|
||||||
task.spawn(f, "NaN", 0 / 0, f)
|
task.spawn(f, "NaN", 0 / 0, f)
|
||||||
|
]]
|
||||||
task.wait(0.1)
|
|
||||||
|
|
Loading…
Reference in a new issue