issue #61 fix bug in compilation
parent
aca5b3ef86
commit
c4c8dad5b5
@ -0,0 +1,59 @@
|
||||
-- Test that compilation of invalid Ravi code fails correctly!
|
||||
-- All tests are negative tests here
|
||||
|
||||
-- =================== start copy from Lua testsuite ===============
|
||||
local function checkerr (msg, f, ...)
|
||||
local st, err = pcall(f, ...)
|
||||
assert(not st and string.find(err, msg))
|
||||
end
|
||||
|
||||
local function doit (s)
|
||||
local f, msg = load(s)
|
||||
if f == nil then return msg end
|
||||
local cond, msg = pcall(f)
|
||||
return (not cond) and msg
|
||||
end
|
||||
|
||||
local function checkmessage (prog, msg)
|
||||
local m = doit(prog)
|
||||
--if (not string.find(m, msg, 1, true)) then
|
||||
-- print(m)
|
||||
--end
|
||||
assert(string.find(m, msg, 1, true))
|
||||
end
|
||||
|
||||
local function checksyntax (prog, extra, token, line)
|
||||
local msg = doit(prog)
|
||||
if not string.find(token, "^<%a") and not string.find(token, "^char%(")
|
||||
then token = "'"..token.."'" end
|
||||
token = string.gsub(token, "(%p)", "%%%1")
|
||||
local pt = string.format([[^%%[string ".*"%%]:%d: .- near %s$]],
|
||||
line, token)
|
||||
assert(string.find(msg, pt))
|
||||
assert(string.find(msg, msg, 1, true))
|
||||
end
|
||||
-- =================== end copy from Lua testsuite ===============
|
||||
|
||||
checkmessage('local t: table = {}; local t2: table = {}; t=t2[1]', 'Invalid assignment: table expected')
|
||||
checkmessage('local t: table = {}; t=1', 'Invalid assignment: table expected')
|
||||
checkmessage('local t: table = {}; t=function() end', 'table expected')
|
||||
checkmessage('local t: table = {}; local t2: number[] = {}; t=t2', 'Invalid assignment: table expected')
|
||||
checkmessage('local t: table = {}; local t2: table = { data={} }; t=t2.data', 'Invalid assignment: table expected')
|
||||
checkmessage('local t: table = {}; local f=function() t = 1 end; f()', 'upvalue of table type, cannot be set to non table value')
|
||||
checkmessage('local t: table = {}; local x=function() return 0 end; local f=function() t = x() end; f()', 'upvalue of table type, cannot be set to non table value')
|
||||
checkmessage('local t: table = {}; local x=function() t[1] = 1; local f=function() t = 1 end; f(); end; x()', 'upvalue of table type, cannot be set to non table value')
|
||||
|
||||
checkmessage('local t: integer[] = {}; local t2: integer[] = {1}; t=t2[1]', 'Invalid assignment: integer[] expected')
|
||||
checkmessage('local t: integer[] = {}; t=1', 'Invalid assignment: integer[] expected')
|
||||
checkmessage('local t: integer[] = {}; t=function() end', 'integer[] expected')
|
||||
checkmessage('local t: integer[] = {}; local t2: number[] = {}; t=t2', 'Invalid assignment: integer[] expected')
|
||||
checkmessage('local t: integer[] = {}; local t2: table = {}; t=t2', 'Invalid assignment: integer[] expected')
|
||||
checkmessage('local t: integer[] = {}; local t2: table = {true}; t[1]=t2[1]', 'integer expected')
|
||||
checkmessage('local t: integer[] = {}; local t2: table = {"hi"}; t[1]=t2[1]', 'integer expected')
|
||||
checkmessage('local t: integer[] = {}; local t2: table = { data={} }; t=t2.data', 'Invalid assignment: integer[] expected')
|
||||
checkmessage('local t: integer[] = {}; local f=function() t = 1 end; f()', 'upvalue of integer[] type, cannot be set to non integer[] value')
|
||||
checkmessage('local t: integer[] = {}; local x=function() return 0 end; local f=function() t = x() end; f()', 'upvalue of integer[] type, cannot be set to non integer[] value')
|
||||
checkmessage('local t: integer[] = {}; local x=function() t[1] = 1; local f=function() t = 1 end; f(); end; x()', 'upvalue of integer[] type, cannot be set to non integer[] value')
|
||||
|
||||
|
||||
checkmessage('local t: number[] = {}; local t2: number[] = {1.0}; t=t2[1]', 'Invalid assignment: number[] expected')
|
Loading…
Reference in new issue