local function errmsg(code, m)
local st, msg = load(code)
assert(not st and string.find(msg, m))
end
errmsg([[ goto l1; do ::l1:: end ]], "label 'l1'")
errmsg([[ do ::l1:: end goto l1; ]], "label 'l1'")
errmsg([[ ::l1:: ::l1:: ]], "label 'l1'")
errmsg([[ goto l1; local aa ::l1:: ::l2:: print(3) ]], "local 'aa'")
errmsg([[
do local bb, cc; end
local aa
print(3)
]], "local 'aa'")
errmsg([[ do ::l1:: end goto l1 ]], "label 'l1'")
errmsg([[ goto l1 do ::l1:: end ]], "label 'l1'")
errmsg([[
repeat
if x then end
local xuxu = 10
until xuxu < x
]], "local 'xuxu'")
local x
do
local y = 12
x = x + 1;
x = y;
end
assert(x == 13)
do
local prog = [[
do
local a = 1
a = a + 1
a = a + 10
a = a + 2
a = a + 20
return a
end
]]
local label = string.rep("0123456789", 40)
prog = string.format(prog, label, label, label, label)
assert(assert(load(prog))() == 31)
end
do
end
do
local a = 23
x = a
;
end
while true do
local x = 45
;;;
end
assert(x == 13)
if print then
error("should not be here")
local x
;
;;
else
end
local function foo()
local a = {}
a[#a + 1] = 1;
a[#a + 1] = 2;
a[#a + 1] = 3;
a[#a + 1] = 4;
a[#a + 1] = 5;
assert(a[1] == 3 and a[2] == 1 and a[3] == 2 and
a[4] == 5 and a[5] == 4)
if not a[6] then
a[6] = true;
end end
foo()
local function foo()
local a = {}
do
local i = 1
local k = 0
a[0] = function(y) k = y end
do
local x
if i > 2 then end
a[i] = function(y) if y then x = y else return x + k end end
i = i + 1
end
end
return a
end
local a = foo()
a[1](10); a[2](20)
assert(a[1]() == 10 and a[2]() == 20 and a[3] == nil)
a[0](13)
assert(a[1]() == 23 and a[2]() == 33)
local function testG(a)
if a == 1 then
error("should never be here!")
elseif a == 2 then
elseif a == 3 then
elseif a == 4 then
error("should never be here!")
a = a + 1 else
a = a * 2;
error("should never be here!")
error("should never be here!")
end
do return a end
do return "2" end
do return "3" end
return "1"
end
assert(testG(1) == "1")
assert(testG(2) == "2")
assert(testG(3) == "3")
assert(testG(4) == 5)
assert(testG(5) == 10)
print 'OK'