Improve argument type checking.
This commit is contained in:
@@ -152,13 +152,16 @@ local function subbanner(name)
|
||||
print( '--- '..tostring(name) )
|
||||
end
|
||||
|
||||
local function pack(s,...)
|
||||
return s,{...}
|
||||
end
|
||||
|
||||
-- check that all combinations of arguments pass
|
||||
function checkallpass( name, typesets, typesonly )
|
||||
subbanner('checkallpass')
|
||||
for i,v in arglists(typesets) do
|
||||
local sig = signature(name,v)
|
||||
local r = { invoke( name, v ) }
|
||||
local s = table.remove( r, 1 )
|
||||
local s,r = pack( invoke( name, v ) )
|
||||
if s then
|
||||
if typesonly then
|
||||
print( ok, sig, types(r) )
|
||||
|
||||
@@ -59,7 +59,7 @@ checkallerrors('loadfile', {nonstring}, 'bad argument #1')
|
||||
banner('loadstring')
|
||||
checkallpass('loadstring', {{'return'}})
|
||||
checkallpass('loadstring', {{'return'},{'mychunk'}})
|
||||
checkallpass('loadstring', {{'return a ... b'},{'mychunk'}})
|
||||
checkallpass('loadstring', {{'return a ... b'},{'mychunk'}},true)
|
||||
checkallerrors('loadstring', {{'return a ... b'},{'mychunk'}},'hello')
|
||||
checkallerrors('loadstring', {notastring,{nil,astring,anumber}}, 'bad argument #1')
|
||||
checkallerrors('loadstring', {{'return'},{afunction,atable}}, 'bad argument #2')
|
||||
|
||||
@@ -8,20 +8,20 @@ local notanumber = {nil,astring,aboolean,afunction,atable,athread}
|
||||
local nonnumber = {astring,aboolean,afunction,atable}
|
||||
|
||||
local singleargfunctions = {
|
||||
'abs', 'acos', 'asin', 'atan', 'ceil', 'cos', 'cosh', 'deg', 'exp', 'floor',
|
||||
'abs', 'acos', 'asin', 'atan', 'cos', 'cosh', 'deg', 'exp', 'floor',
|
||||
'rad', 'randomseed', 'sin', 'sinh', 'tan', 'tanh', 'frexp',
|
||||
}
|
||||
|
||||
local singleargposdomain = {
|
||||
'log', 'log10', 'sqrt',
|
||||
'log', 'log10', 'sqrt', 'ceil',
|
||||
}
|
||||
|
||||
local twoargfunctions = {
|
||||
'atan2', 'fmod',
|
||||
'atan2',
|
||||
}
|
||||
|
||||
local twoargsposdomain = {
|
||||
'pow',
|
||||
'pow', 'fmod',
|
||||
}
|
||||
|
||||
-- single argument tests
|
||||
|
||||
Reference in New Issue
Block a user