Improve argument type check tests.
This commit is contained in:
@@ -1,5 +1,10 @@
|
|||||||
-- utilities to check that args of various types pass or fail
|
-- utilities to check that args of various types pass or fail
|
||||||
-- argument type checking
|
-- argument type checking
|
||||||
|
local ok = '-\t'
|
||||||
|
local fail = 'fail '
|
||||||
|
local needcheck = 'needcheck '
|
||||||
|
local badmsg = 'badmsg '
|
||||||
|
|
||||||
|
|
||||||
akey = 'aa'
|
akey = 'aa'
|
||||||
astring = 'abc'
|
astring = 'abc'
|
||||||
@@ -11,12 +16,12 @@ aboolean = true
|
|||||||
atable = {[akey]=456}
|
atable = {[akey]=456}
|
||||||
afunction = function() end
|
afunction = function() end
|
||||||
anil = nil
|
anil = nil
|
||||||
|
athread = coroutine.create(afunction)
|
||||||
|
|
||||||
anylua = { anil, astring, anumber, aboolean, atable, afunction }
|
anylua = { nil, astring, anumber, aboolean, atable, afunction, athread }
|
||||||
|
|
||||||
somestring = { astring }
|
somestring = { astring, anumber }
|
||||||
somenumber = { anumber }
|
somenumber = { anumber, astrnum }
|
||||||
somestrnum = { anumber, astrnum }
|
|
||||||
someboolean = { aboolean }
|
someboolean = { aboolean }
|
||||||
sometable = { atable }
|
sometable = { atable }
|
||||||
somefunction = { afunction }
|
somefunction = { afunction }
|
||||||
@@ -24,36 +29,21 @@ somenil = { anil }
|
|||||||
somekey = { akey }
|
somekey = { akey }
|
||||||
notakey = { astring, anumber, aboolean, atable, afunction }
|
notakey = { astring, anumber, aboolean, atable, afunction }
|
||||||
|
|
||||||
local function contains(set,val)
|
notastring = { nil, aboolean, atable, afunction, athread }
|
||||||
local m = #set
|
notanumber = { nil, astring, aboolean, atable, afunction, athread }
|
||||||
for i=1,m do
|
notaboolean = { nil, astring, anumber, atable, afunction, athread }
|
||||||
if set[i] == val then
|
notatable = { nil, astring, anumber, aboolean, afunction, athread }
|
||||||
return true
|
notafunction = { nil, astring, anumber, aboolean, atable, athread }
|
||||||
end
|
notathread = { nil, astring, anumber, aboolean, atable, afunction }
|
||||||
end
|
notanil = { astring, anumber, aboolean, atable, afunction, athread }
|
||||||
return val == nil
|
|
||||||
end
|
|
||||||
|
|
||||||
local function except(some)
|
nonstring = { aboolean, atable, afunction, athread }
|
||||||
local n = #anylua
|
nonnumber = { astring, aboolean, atable, afunction, athread }
|
||||||
local z = {}
|
nonboolean = { astring, anumber, atable, afunction, athread }
|
||||||
local j = 1
|
nontable = { astring, anumber, aboolean, afunction, athread }
|
||||||
for i=1,n do
|
nonfunction = { astring, anumber, aboolean, atable, athread }
|
||||||
if not contains(some, anylua[i]) then
|
nonthread = { astring, anumber, aboolean, atable, afunction }
|
||||||
z[j] = anylua[i]
|
nonkey = { astring, anumber, aboolean, atable, afunction }
|
||||||
j = j + 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return z
|
|
||||||
end
|
|
||||||
|
|
||||||
notastring = except(somestring)
|
|
||||||
notanumber = except(somenumber)
|
|
||||||
notastrnum = except(somestrnum)
|
|
||||||
notaboolean = except(someboolean)
|
|
||||||
notatable = except(sometable)
|
|
||||||
notafunction = except(somefunction)
|
|
||||||
notanil = except(somenil)
|
|
||||||
|
|
||||||
local structtypes = {
|
local structtypes = {
|
||||||
['table']='<table>',
|
['table']='<table>',
|
||||||
@@ -108,33 +98,6 @@ local function arglists(typesets)
|
|||||||
return ipairs(argsets)
|
return ipairs(argsets)
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
|
||||||
local function expand(arglists,fixed,varying,...)
|
|
||||||
for i=1,#varying do
|
|
||||||
local f = dup(fixed)
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function arglists(typesets)
|
|
||||||
local argsets = {}
|
|
||||||
local args={}
|
|
||||||
local n = typesets and #typesets or 0
|
|
||||||
if n == 0 then
|
|
||||||
table.insert( argsets, args )
|
|
||||||
end
|
|
||||||
for i=1,n do
|
|
||||||
local t = typesets[i]
|
|
||||||
for j=1,#t do
|
|
||||||
args[i] = t[j]
|
|
||||||
if i == n then
|
|
||||||
table.insert( argsets, duptable(args) )
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return ipairs(argsets)
|
|
||||||
end
|
|
||||||
--]]
|
|
||||||
|
|
||||||
local function lookup( name )
|
local function lookup( name )
|
||||||
return loadstring('return '..name)()
|
return loadstring('return '..name)()
|
||||||
@@ -155,11 +118,6 @@ local function subbanner(name)
|
|||||||
print( '--- '..tostring(name) )
|
print( '--- '..tostring(name) )
|
||||||
end
|
end
|
||||||
|
|
||||||
local ok = 'ok '
|
|
||||||
local fail = 'fail '
|
|
||||||
local needcheck = 'needcheck '
|
|
||||||
local badmsg = 'badmsg '
|
|
||||||
|
|
||||||
-- check that all combinations of arguments pass
|
-- check that all combinations of arguments pass
|
||||||
function checkallpass( name, typesets )
|
function checkallpass( name, typesets )
|
||||||
subbanner('checkallpass')
|
subbanner('checkallpass')
|
||||||
@@ -174,21 +132,6 @@ function checkallpass( name, typesets )
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- check that all combinations of arguments fail in some way,
|
|
||||||
-- ignore error messages
|
|
||||||
function checkallfail( name, typesets )
|
|
||||||
subbanner('checkallfail')
|
|
||||||
for i,v in arglists(typesets) do
|
|
||||||
local sig = signature(name,v)
|
|
||||||
local s,e = invoke( name, v )
|
|
||||||
if not s then
|
|
||||||
print( ok, sig )
|
|
||||||
else
|
|
||||||
print( needcheck, sig, e )
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- check that all combinations of arguments fail in some way,
|
-- check that all combinations of arguments fail in some way,
|
||||||
-- ignore error messages
|
-- ignore error messages
|
||||||
function checkallerrors( name, typesets, template )
|
function checkallerrors( name, typesets, template )
|
||||||
|
|||||||
@@ -3,136 +3,138 @@ require 'args'
|
|||||||
|
|
||||||
|
|
||||||
-- arg types for basic library functions
|
-- arg types for basic library functions
|
||||||
local somestrnumnil={anil,astring,anumber}
|
|
||||||
local notastrnumnil={aboolean,atable,afunction}
|
|
||||||
|
|
||||||
-- assert
|
-- assert
|
||||||
banner('assert')
|
banner('assert')
|
||||||
checkallpass('assert',{{true,123},anylua})
|
checkallpass('assert',{{true,123},anylua})
|
||||||
checkallfail('assert',{{nil,false},{nil,'message'}})
|
|
||||||
checkallerrors('assert',{{nil,false},{nil}},'assertion failed')
|
checkallerrors('assert',{{nil,false},{nil}},'assertion failed')
|
||||||
checkallerrors('assert',{{nil,false},{'message'}},'message')
|
checkallerrors('assert',{{nil,false},{'message'}},'message')
|
||||||
|
|
||||||
-- collectgarbage
|
-- collectgarbage
|
||||||
banner('collectgarbage')
|
banner('collectgarbage')
|
||||||
checkallpass('collectgarbage',{{'collect','count'}})
|
checkallpass('collectgarbage',{{'collect','count'}})
|
||||||
checkallerrors('collectgarbage',{notanil},'bad argument')
|
checkallerrors('collectgarbage',{notanil},'bad argument #1')
|
||||||
|
|
||||||
-- dofila
|
-- dofile
|
||||||
banner('dofile')
|
banner('dofile')
|
||||||
checkallpass('dofile', {{nil,'src/test/errors/args.lua','args.lua'}})
|
checkallpass('dofile', {{nil,'src/test/errors/args.lua'}})
|
||||||
checkallerrors('dofile', {notastrnumnil}, 'bad argument')
|
checkallerrors('dofile', {{'args.lua'}}, 'cannot open args.lua')
|
||||||
|
checkallerrors('dofile', {nonstring}, 'bad argument #1')
|
||||||
|
|
||||||
-- error
|
-- error
|
||||||
banner('error')
|
banner('error')
|
||||||
checkallfail('error', {anylua,{nil,0,1,2}})
|
checkallerrors('error', {{'message'},{nil,0,1,2}}, 'message')
|
||||||
checkallerrors('dofile', {{'message'},{nil,0,1,2}}, 'message')
|
checkallerrors('error', {{123},{nil,1,2}}, 123)
|
||||||
checkallerrors('dofile', {{123},{nil,1,2}}, 123)
|
|
||||||
|
|
||||||
-- getfenv
|
-- getfenv
|
||||||
banner('getfenv')
|
banner('getfenv')
|
||||||
checkallpass('getfenv', {{nil,print,function()end,0,1,2}})
|
checkallpass('getfenv', {{nil,print,function()end,0,1,2}})
|
||||||
checkallerrors('getfenv', {{true,{},'abc'}}, 'bad argument')
|
checkallerrors('getfenv', {{true,{},'abc'}}, 'bad argument #1')
|
||||||
|
|
||||||
-- getmetatable
|
-- getmetatable
|
||||||
banner('getmetatable')
|
banner('getmetatable')
|
||||||
checkallpass('getmetatable', {notanil})
|
checkallpass('getmetatable', {notanil})
|
||||||
checkallerrors('getmetatable',{},'bad argument')
|
checkallerrors('getmetatable',{},'bad argument #1')
|
||||||
|
|
||||||
-- ipairs
|
-- ipairs
|
||||||
banner('ipairs')
|
banner('ipairs')
|
||||||
checkallpass('ipairs', {sometable})
|
checkallpass('ipairs', {sometable})
|
||||||
checkallerrors('ipairs', {notatable}, 'bad argument')
|
checkallerrors('ipairs', {notatable}, 'bad argument #1')
|
||||||
|
|
||||||
-- load
|
-- load
|
||||||
banner('load')
|
banner('load')
|
||||||
checkallpass('load', {somefunction,{anil,astring}})
|
checkallpass('load', {somefunction,{nil,astring}})
|
||||||
checkallerrors('load', {notafunction,{anil,astring,anumber}}, 'bad argument')
|
checkallerrors('load', {notafunction,{nil,astring,anumber}}, 'bad argument #1')
|
||||||
checkallerrors('load', {somefunction,{afunction,atable}}, 'bad argument')
|
checkallerrors('load', {somefunction,{afunction,atable}}, 'bad argument #2')
|
||||||
|
|
||||||
-- loadfile
|
-- loadfile
|
||||||
banner('loadfile')
|
banner('loadfile')
|
||||||
checkallerrors('loadfile', {notastring}, 'bad argument')
|
checkallpass('loadfile', {})
|
||||||
|
checkallerrors('loadfile', {nonstring}, 'bad argument #1')
|
||||||
|
|
||||||
-- loadstring
|
-- loadstring
|
||||||
banner('loadstring')
|
banner('loadstring')
|
||||||
checkallpass('loadstring', {{'return'},{anil,astring}})
|
checkallpass('loadstring', {{'return'},{nil,astring}})
|
||||||
checkallerrors('loadstring', {notastring,{anil,astring,anumber}}, 'bad argument')
|
checkallerrors('loadstring', {notastring,{nil,astring,anumber}}, 'bad argument #1')
|
||||||
checkallerrors('loadstring', {{'return'},{afunction,atable}}, 'bad argument')
|
checkallerrors('loadstring', {{'return'},{afunction,atable}}, 'bad argument #2')
|
||||||
|
|
||||||
-- next
|
-- next
|
||||||
banner('next')
|
banner('next')
|
||||||
-- checkallpass('next', {{{aa=11}},{nil,'aa'}})
|
|
||||||
checkallpass('next', {sometable,somekey})
|
checkallpass('next', {sometable,somekey})
|
||||||
checkallerrors('next', {notatable,{nil,1}}, 'bad argument')
|
checkallerrors('next', {notatable,{nil,1}}, 'bad argument #1')
|
||||||
checkallerrors('next', {sometable,notakey}, 'invalid key')
|
checkallerrors('next', {sometable,nonkey}, 'invalid key')
|
||||||
|
|
||||||
-- pairs
|
-- pairs
|
||||||
banner('pairs')
|
banner('pairs')
|
||||||
checkallpass('pairs', {sometable})
|
checkallpass('pairs', {sometable})
|
||||||
checkallerrors('pairs', {notatable}, 'bad argument')
|
checkallerrors('pairs', {notatable}, 'bad argument #1')
|
||||||
|
|
||||||
-- pcall
|
-- pcall
|
||||||
banner('pcall')
|
banner('pcall')
|
||||||
checkallpass('pcall', {notanil,anylua})
|
checkallpass('pcall', {notanil,anylua})
|
||||||
checkallerrors('pcall',{},'bad argument')
|
checkallerrors('pcall',{},'bad argument #1')
|
||||||
|
|
||||||
-- print
|
-- print
|
||||||
banner('print')
|
banner('print')
|
||||||
checkallpass('print', {})
|
checkallpass('print', {})
|
||||||
checkallpass('print', {{anil,astring,anumber,aboolean}})
|
checkallpass('print', {{nil,astring,anumber,aboolean}})
|
||||||
|
|
||||||
-- rawequal
|
-- rawequal
|
||||||
banner('rawequal')
|
banner('rawequal')
|
||||||
checkallpass('rawequal', {notanil,notanil})
|
checkallpass('rawequal', {notanil,notanil})
|
||||||
checkallerrors('rawequal', {notanil}, 'bad argument')
|
checkallerrors('rawequal', {}, 'bad argument #1')
|
||||||
checkallerrors('rawequal', {}, 'bad argument')
|
checkallerrors('rawequal', {notanil}, 'bad argument #2')
|
||||||
|
|
||||||
-- rawget
|
-- rawget
|
||||||
banner('rawget')
|
banner('rawget')
|
||||||
checkallpass('rawget', {sometable,somekey})
|
checkallpass('rawget', {sometable,somekey})
|
||||||
checkallpass('rawget', {sometable,notakey})
|
checkallpass('rawget', {sometable,nonkey})
|
||||||
checkallerrors('rawget', {notatable,notakey}, 'bad argument')
|
checkallerrors('rawget', {sometable,somenil},'bad argument #2')
|
||||||
checkallerrors('rawget', {}, 'bad argument')
|
checkallerrors('rawget', {notatable,notakey}, 'bad argument #1')
|
||||||
|
checkallerrors('rawget', {}, 'bad argument #1')
|
||||||
|
|
||||||
-- rawset
|
-- rawset
|
||||||
banner('rawset')
|
banner('rawset')
|
||||||
checkallpass('rawset', {sometable,somekey,notanil})
|
checkallpass('rawset', {sometable,somekey,notanil})
|
||||||
checkallpass('rawset', {sometable,notakey,notanil})
|
checkallpass('rawset', {sometable,nonkey,notanil})
|
||||||
checkallerrors('rawset', {sometable,somekey}, 'bad argument')
|
checkallerrors('rawset', {sometable,somenil},'table index is nil')
|
||||||
checkallerrors('rawset', {notatable,somestring,somestring}, 'bad argument')
|
checkallerrors('rawset', {}, 'bad argument #1')
|
||||||
checkallerrors('rawset', {}, 'bad argument')
|
checkallerrors('rawset', {notatable,somestring,somestring}, 'bad argument #1')
|
||||||
|
checkallerrors('rawset', {sometable,somekey}, 'bad argument #3')
|
||||||
|
|
||||||
-- select
|
-- select
|
||||||
banner('select')
|
banner('select')
|
||||||
checkallpass('select', {{anumber,'#'},anylua})
|
checkallpass('select', {{anumber,'#'},anylua})
|
||||||
checkallerrors('select', {notanumber}, 'bad argument')
|
checkallerrors('select', {notanumber}, 'bad argument #1')
|
||||||
|
|
||||||
-- setfenv
|
-- setfenv
|
||||||
banner('setfenv')
|
banner('setfenv')
|
||||||
checkallpass('setfenv', {{function()end},sometable})
|
checkallpass('setfenv', {{function()end},sometable})
|
||||||
checkallerrors('setfenv', {{function()end}}, 'bad argument')
|
checkallerrors('setfenv', {{1.23, '1.33'},{getfenv()}}, 'cannot change environment of given object')
|
||||||
checkallerrors('setfenv', {{function()end},notatable}, 'bad argument')
|
checkallerrors('setfenv', {{atable,athread,aboolean,astring},sometable}, 'bad argument #1')
|
||||||
|
checkallerrors('setfenv', {notafunction}, 'bad argument #2')
|
||||||
|
checkallerrors('setfenv', {anylua}, 'bad argument #2')
|
||||||
|
checkallerrors('setfenv', {{function()end},notatable}, 'bad argument #2')
|
||||||
|
|
||||||
-- setmetatable
|
-- setmetatable
|
||||||
banner('setmetatable')
|
banner('setmetatable')
|
||||||
checkallpass('setmetatable', {sometable,sometable})
|
checkallpass('setmetatable', {sometable,sometable})
|
||||||
checkallpass('setmetatable', {sometable,{anil,atable},{'anchor'}})
|
checkallpass('setmetatable', {sometable,{nil,atable},{'anchor'}})
|
||||||
checkallerrors('setmetatable',{notatable,sometable},'bad argument')
|
checkallerrors('setmetatable',{notatable,sometable},'bad argument #1')
|
||||||
checkallerrors('setmetatable',{sometable,notatable},'bad argument')
|
checkallerrors('setmetatable',{sometable,notatable},'bad argument #2')
|
||||||
|
|
||||||
-- tonumber
|
-- tonumber
|
||||||
banner('tonumber')
|
banner('tonumber')
|
||||||
checkallpass('tonumber',{somestrnum,{nil,2,10,36}})
|
checkallpass('tonumber',{somenumber,{nil,2,10,36}})
|
||||||
checkallpass('tonumber',{notastrnum,{nil,10}})
|
checkallpass('tonumber',{notanil,{nil,10}})
|
||||||
checkallerrors('tonumber',{notastrnum,{2,9,11,36}},'bad argument')
|
checkallerrors('tonumber',{{nil,afunction,atable},{2,9,11,36}},'bad argument #1')
|
||||||
checkallerrors('tonumber',{somestrnum,{1,37,atable,afunction,aboolean}},'bad argument')
|
checkallerrors('tonumber',{somenumber,{1,37,atable,afunction,aboolean}},'bad argument #2')
|
||||||
|
|
||||||
-- tostring
|
-- tostring
|
||||||
banner('tostring')
|
banner('tostring')
|
||||||
checkallpass('tostring',{notanil})
|
checkallpass('tostring',{notanil})
|
||||||
checkallpass('tostring',{anylua,{'anchor'}})
|
checkallpass('tostring',{anylua,{'anchor'}})
|
||||||
checkallerrors('tostring',{},'bad argument')
|
checkallerrors('tostring',{},'bad argument #1')
|
||||||
|
|
||||||
-- type
|
-- type
|
||||||
banner('type')
|
banner('type')
|
||||||
@@ -142,12 +144,16 @@ checkallerrors('type',{},'bad argument')
|
|||||||
|
|
||||||
-- unpack
|
-- unpack
|
||||||
banner('unpack')
|
banner('unpack')
|
||||||
checkallpass('unpack',{sometable,{nil,anumber,astrnum},{nil,anumber,astrnum}})
|
checkallpass('unpack',{sometable})
|
||||||
checkallerrors('unpack',{notatable,{nil,anumber,astrnum},{nil,anumber,astrnum}},'bad argument')
|
checkallpass('unpack',{sometable,somenumber})
|
||||||
|
checkallpass('unpack',{sometable,somenumber,somenumber})
|
||||||
|
checkallerrors('unpack',{notatable,somenumber,somenumber},'bad argument #1')
|
||||||
|
checkallerrors('unpack',{sometable,nonnumber,somenumber},'bad argument #2')
|
||||||
|
checkallerrors('unpack',{sometable,somenumber,nonnumber},'bad argument #3')
|
||||||
|
|
||||||
-- xpcall
|
-- xpcall
|
||||||
banner('xpcall')
|
banner('xpcall')
|
||||||
checkallpass('xpcall', {notanil,notanil})
|
checkallpass('xpcall', {notanil,notanil})
|
||||||
checkallerrors('xpcall',{},'bad argument')
|
checkallerrors('xpcall',{anylua},'bad argument #2')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ checkallerrors('coroutine.create',{notafunction},'bad argument')
|
|||||||
banner('coroutine.resume')
|
banner('coroutine.resume')
|
||||||
local co = coroutine.create(function() while true do coroutine.yield() end end)
|
local co = coroutine.create(function() while true do coroutine.yield() end end)
|
||||||
checkallpass('coroutine.resume',{{co},anylua})
|
checkallpass('coroutine.resume',{{co},anylua})
|
||||||
checkallerrors('coroutine.resume',{anylua},'bad argument')
|
checkallerrors('coroutine.resume',{notathread},'bad argument #1')
|
||||||
|
|
||||||
-- coroutine.running
|
-- coroutine.running
|
||||||
banner('coroutine.running')
|
banner('coroutine.running')
|
||||||
@@ -21,12 +21,12 @@ checkallpass('coroutine.running',{anylua})
|
|||||||
-- coroutine.status
|
-- coroutine.status
|
||||||
banner('coroutine.status')
|
banner('coroutine.status')
|
||||||
checkallpass('coroutine.status',{{co}})
|
checkallpass('coroutine.status',{{co}})
|
||||||
checkallerrors('coroutine.status',{anylua},'bad argument')
|
checkallerrors('coroutine.status',{notathread},'bad argument #1')
|
||||||
|
|
||||||
-- coroutine.wrap
|
-- coroutine.wrap
|
||||||
banner('coroutine.wrap')
|
banner('coroutine.wrap')
|
||||||
checkallpass('coroutine.wrap',{somefunction})
|
checkallpass('coroutine.wrap',{somefunction})
|
||||||
checkallerrors('coroutine.wrap',{notafunction},'bad argument')
|
checkallerrors('coroutine.wrap',{notafunction},'bad argument #1')
|
||||||
|
|
||||||
-- coroutine.yield
|
-- coroutine.yield
|
||||||
banner('coroutine.yield')
|
banner('coroutine.yield')
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ require 'args'
|
|||||||
|
|
||||||
-- arg type tests for math library functions
|
-- arg type tests for math library functions
|
||||||
local somenumber = {23,45.67,'-12','-345.678'}
|
local somenumber = {23,45.67,'-12','-345.678'}
|
||||||
local notanumber = {nil,astring,aboolean,afunction,atable}
|
local notanumber = {nil,astring,aboolean,afunction,atable,athread}
|
||||||
local nonnumber = {astring,aboolean,afunction,atable}
|
local nonnumber = {astring,aboolean,afunction,atable}
|
||||||
|
|
||||||
local singleargfunctions = {
|
local singleargfunctions = {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ checkallerrors('package.seeall',{notatable},'bad argument')
|
|||||||
-- module (last because it pretty much breaks this chunk)
|
-- module (last because it pretty much breaks this chunk)
|
||||||
print( pcall( function()
|
print( pcall( function()
|
||||||
banner('module')
|
banner('module')
|
||||||
checkallpass('module',{somestrnum,{package.seeall},{nil,afunction}})
|
checkallpass('module',{somenumber,{package.seeall},{nil,afunction}})
|
||||||
checkallerrors('module',{{aboolean,atable,afunction}},'bad argument')
|
checkallerrors('module',{{aboolean,atable,afunction}},'bad argument')
|
||||||
checkallerrors('module',{{aboolean,atable,afunction},{package.seeall}},'bad argument')
|
checkallerrors('module',{{aboolean,atable,afunction},{package.seeall}},'bad argument')
|
||||||
checkallerrors('module',{somestring,{astring,anumber,aboolean,atable}},'attempt to call a')
|
checkallerrors('module',{somestring,{astring,anumber,aboolean,atable}},'attempt to call a')
|
||||||
|
|||||||
@@ -2,10 +2,6 @@ package.path = "?.lua;src/test/errors/?.lua"
|
|||||||
require 'args'
|
require 'args'
|
||||||
|
|
||||||
-- arg type tests for string library functions
|
-- arg type tests for string library functions
|
||||||
local somestring = {astring,anumber}
|
|
||||||
local notastring = {nil,aboolean,afunction,atable}
|
|
||||||
local somenumber = {ainteger,adouble,tostring(ainteger),tostring(adouble)}
|
|
||||||
local notanumber = {nil,astring,aboolean,afunction,atable}
|
|
||||||
|
|
||||||
-- string.byte
|
-- string.byte
|
||||||
banner('string.byte')
|
banner('string.byte')
|
||||||
@@ -17,8 +13,10 @@ checkallerrors('string.byte',{notastring,{nil,111}},'bad argument')
|
|||||||
banner('string.char')
|
banner('string.char')
|
||||||
checkallpass('string.char',{{nil,0,1,40,127,128,255,'0','1','255','1.2',1.2}})
|
checkallpass('string.char',{{nil,0,1,40,127,128,255,'0','1','255','1.2',1.2}})
|
||||||
checkallpass('string.char',{{0,127,255},{0,127,255}})
|
checkallpass('string.char',{{0,127,255},{0,127,255}})
|
||||||
checkallerrors('string.char',{{-1,256}},'bad argument')
|
checkallpass('string.char',{})
|
||||||
checkallerrors('string.char',{notanumber,notanumber},'bad argument')
|
checkallerrors('string.char',{{-1,256}},'bad argument #1')
|
||||||
|
checkallerrors('string.char',{notanumber,{23,'45',6.7}},'bad argument #1')
|
||||||
|
checkallerrors('string.char',{{23,'45',6.7},nonnumber},'bad argument #2')
|
||||||
|
|
||||||
-- string.dump
|
-- string.dump
|
||||||
banner('string.dump')
|
banner('string.dump')
|
||||||
@@ -30,74 +28,74 @@ banner('string.find')
|
|||||||
checkallpass('string.find',{somestring,somestring})
|
checkallpass('string.find',{somestring,somestring})
|
||||||
checkallpass('string.find',{somestring,somestring,{nil,-3,3}})
|
checkallpass('string.find',{somestring,somestring,{nil,-3,3}})
|
||||||
checkallpass('string.find',{somestring,somestring,somenumber,anylua})
|
checkallpass('string.find',{somestring,somestring,somenumber,anylua})
|
||||||
checkallerrors('string.find',{somestring,notastring},'bad argument')
|
checkallerrors('string.find',{notastring,somestring},'bad argument #1')
|
||||||
checkallerrors('string.find',{notastring,somestring},'bad argument')
|
checkallerrors('string.find',{somestring,notastring},'bad argument #2')
|
||||||
checkallerrors('string.find',{somestring,somestring,notanumber},'bad argument')
|
checkallerrors('string.find',{somestring,somestring,nonnumber},'bad argument #3')
|
||||||
|
|
||||||
-- string.format
|
-- string.format
|
||||||
local numfmts = {'%c','%d','%E','%e','%f','%g','%G','%i','%o','%u','%X','%x'}
|
local numfmts = {'%c','%d','%E','%e','%f','%g','%G','%i','%o','%u','%X','%x'}
|
||||||
local strfmts = {'%q','%s'}
|
local strfmts = {'%q','%s'}
|
||||||
banner('string.format')
|
banner('string.format')
|
||||||
checkallpass('string.format',{somestring,anylua})
|
checkallpass('string.format',{somestring,anylua})
|
||||||
checkallpass('string.format',{numfmts,{ainteger,adouble,astrnum}})
|
checkallpass('string.format',{numfmts,somenumber})
|
||||||
checkallpass('string.format',{strfmts,{astring,ainteger,adouble,astrnum}})
|
checkallpass('string.format',{strfmts,somestring})
|
||||||
checkallerrors('string.format',{numfmts,notastring},'bad argument')
|
checkallerrors('string.format',{numfmts,notanumber},'bad argument #2')
|
||||||
checkallerrors('string.format',{strfmts,notastring},'bad argument')
|
checkallerrors('string.format',{strfmts,notastring},'bad argument #2')
|
||||||
|
|
||||||
-- string.gmatch
|
-- string.gmatch
|
||||||
banner('string.gmatch')
|
banner('string.gmatch')
|
||||||
checkallpass('string.gmatch',{somestring,somestring})
|
checkallpass('string.gmatch',{somestring,somestring})
|
||||||
checkallerrors('string.gmatch',{somestring,notastring},'bad argument')
|
checkallerrors('string.gmatch',{notastring,somestring},'bad argument #1')
|
||||||
checkallerrors('string.gmatch',{notastring,somestring},'bad argument')
|
checkallerrors('string.gmatch',{somestring,notastring},'bad argument #2')
|
||||||
|
|
||||||
-- string.gsub
|
-- string.gsub
|
||||||
local somerepl = {astring,atable,afunction}
|
local somerepl = {astring,atable,afunction}
|
||||||
local notarepl = {nil,aboolean}
|
local notarepl = {nil,aboolean}
|
||||||
banner('string.gsub')
|
banner('string.gsub')
|
||||||
checkallpass('string.gsub',{somestring,somestring,somerepl,{nil,-1}})
|
checkallpass('string.gsub',{somestring,somestring,somerepl,{nil,-1}})
|
||||||
checkallerrors('string.gsub',{notastring,somestring,somerepl},'bad argument')
|
checkallerrors('string.gsub',{notastring,somestring,somerepl},'bad argument #1')
|
||||||
checkallerrors('string.gsub',{somestring,notastring,somerepl},'bad argument')
|
checkallerrors('string.gsub',{somestring,notastring,somerepl},'bad argument #2')
|
||||||
checkallerrors('string.gsub',{{astring},{astring},notarepl},'bad argument')
|
checkallerrors('string.gsub',{{astring},{astring},notarepl},'bad argument #3')
|
||||||
checkallerrors('string.gsub',{{astring},{astring},somerepl,notanumber},'bad argument')
|
checkallerrors('string.gsub',{{astring},{astring},somerepl,nonnumber},'bad argument #4')
|
||||||
|
|
||||||
-- string.len
|
-- string.len
|
||||||
banner('string.len')
|
banner('string.len')
|
||||||
checkallpass('string.len',{somestring})
|
checkallpass('string.len',{somestring})
|
||||||
checkallerrors('string.len',{notastring},'bad argument')
|
checkallerrors('string.len',{notastring},'bad argument #1')
|
||||||
|
|
||||||
-- string.lower
|
-- string.lower
|
||||||
banner('string.lower')
|
banner('string.lower')
|
||||||
checkallpass('string.lower',{somestring})
|
checkallpass('string.lower',{somestring})
|
||||||
checkallerrors('string.lower',{notastring},'bad argument')
|
checkallerrors('string.lower',{notastring},'bad argument #1')
|
||||||
|
|
||||||
-- string.match
|
-- string.match
|
||||||
banner('string.match')
|
banner('string.match')
|
||||||
checkallpass('string.match',{somestring,somestring})
|
checkallpass('string.match',{somestring,somestring})
|
||||||
checkallpass('string.match',{somestring,somestring,{nil,-3,3}})
|
checkallpass('string.match',{somestring,somestring,{nil,-3,3}})
|
||||||
checkallerrors('string.match',{somestring,notastring},'bad argument')
|
checkallerrors('string.match',{notastring,somestring},'bad argument #1')
|
||||||
checkallerrors('string.match',{notastring,somestring},'bad argument')
|
checkallerrors('string.match',{somestring,notastring},'bad argument #2')
|
||||||
checkallerrors('string.match',{somestring,somestring,notanumber},'bad argument')
|
checkallerrors('string.match',{somestring,somestring,notanumber},'bad argument #3')
|
||||||
|
|
||||||
-- string.reverse
|
-- string.reverse
|
||||||
banner('string.reverse')
|
banner('string.reverse')
|
||||||
checkallpass('string.reverse',{somestring})
|
checkallpass('string.reverse',{somestring})
|
||||||
checkallerrors('string.reverse',{notastring},'bad argument')
|
checkallerrors('string.reverse',{notastring},'bad argument #1')
|
||||||
|
|
||||||
-- string.rep
|
-- string.rep
|
||||||
banner('string.rep')
|
banner('string.rep')
|
||||||
checkallpass('string.rep',{somestring,somenumber})
|
checkallpass('string.rep',{somestring,somenumber})
|
||||||
checkallerrors('string.rep',{notastring,somenumber},'bad argument')
|
checkallerrors('string.rep',{notastring,somenumber},'bad argument #1')
|
||||||
checkallerrors('string.rep',{somestring,notanumber},'bad argument')
|
checkallerrors('string.rep',{somestring,notanumber},'bad argument #2')
|
||||||
|
|
||||||
-- string.sub
|
-- string.sub
|
||||||
banner('string.sub')
|
banner('string.sub')
|
||||||
checkallpass('string.sub',{somestring,somenumber,somenumber})
|
checkallpass('string.sub',{somestring,somenumber,somenumber})
|
||||||
checkallerrors('string.sub',{notastring,somenumber,somenumber},'bad argument')
|
checkallerrors('string.sub',{notastring,somenumber,somenumber},'bad argument #1')
|
||||||
checkallerrors('string.sub',{somestring,notanumber,somenumber},'bad argument')
|
checkallerrors('string.sub',{somestring,notanumber,somenumber},'bad argument #2')
|
||||||
checkallerrors('string.sub',{somestring,somenumber,notanumber},'bad argument')
|
checkallerrors('string.sub',{somestring,somenumber,nonnumber},'bad argument #3')
|
||||||
|
|
||||||
-- string.upper
|
-- string.upper
|
||||||
banner('string.upper')
|
banner('string.upper')
|
||||||
checkallpass('string.upper',{somestring})
|
checkallpass('string.upper',{somestring})
|
||||||
checkallerrors('string.upper',{notastring},'bad argument')
|
checkallerrors('string.upper',{notastring},'bad argument #1')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user