44 lines
1.3 KiB
Lua
44 lines
1.3 KiB
Lua
|
|
package.path = "?.lua;src/test/errors/?.lua"
|
||
|
|
require 'args'
|
||
|
|
|
||
|
|
-- arg type tests for coroutine library functions
|
||
|
|
|
||
|
|
-- coroutine.create
|
||
|
|
banner('coroutine.create')
|
||
|
|
checkallpass('coroutine.create',{somefunction})
|
||
|
|
checkallerrors('coroutine.create',{notafunction},'bad argument')
|
||
|
|
|
||
|
|
-- coroutine.resume
|
||
|
|
banner('coroutine.resume')
|
||
|
|
local co = coroutine.create(function() while true do coroutine.yield() end end)
|
||
|
|
checkallpass('coroutine.resume',{{co},anylua})
|
||
|
|
checkallerrors('coroutine.resume',{anylua},'bad argument')
|
||
|
|
|
||
|
|
-- coroutine.running
|
||
|
|
banner('coroutine.running')
|
||
|
|
checkallpass('coroutine.running',{anylua})
|
||
|
|
|
||
|
|
-- coroutine.status
|
||
|
|
banner('coroutine.status')
|
||
|
|
checkallpass('coroutine.status',{{co}})
|
||
|
|
checkallerrors('coroutine.status',{anylua},'bad argument')
|
||
|
|
|
||
|
|
-- coroutine.wrap
|
||
|
|
banner('coroutine.wrap')
|
||
|
|
checkallpass('coroutine.wrap',{somefunction})
|
||
|
|
checkallerrors('coroutine.wrap',{notafunction},'bad argument')
|
||
|
|
|
||
|
|
-- coroutine.yield
|
||
|
|
banner('coroutine.yield')
|
||
|
|
local function f()
|
||
|
|
print( 'yield', coroutine.yield() )
|
||
|
|
print( 'yield', coroutine.yield(astring) )
|
||
|
|
print( 'yield', coroutine.yield(anumber) )
|
||
|
|
print( 'yield', coroutine.yield(aboolean) )
|
||
|
|
end
|
||
|
|
local co = coroutine.create( f )
|
||
|
|
repeat
|
||
|
|
print( 'resume', coroutine.resume(co,astring,anumber) )
|
||
|
|
until coroutine.status(co) ~= 'suspended'
|
||
|
|
|