/
continue_invalid.lua
76 lines (67 loc) · 1.54 KB
/
continue_invalid.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
local good = true
function expect_error(name, code, no_err)
local chunk, err = loadstring(code, "code")
if not err == not not no_err then
print(name .. ": Pass (" .. (err or "") .. ")")
else
print(name .. ": FAIL (" .. (err or "") .. ")")
good = false
end
end
function expect_noerror(name, code)
return expect_error(name, code, true)
end
-- If continue isn't a language construct, then this will fail (and everything else will pass)
expect_noerror("Simple continue usage", [[
while true do
continue
end
]])
expect_error("Invalid local usage in until clause", [[
repeat
local Q
if Q then
continue
end
local p = true
Q = not Q
until p
]])
expect_error("Invalid local usage as upvalue in until clause", [[
repeat
if Q then
continue
end
local p = true
Q = not Q
until F(function() return p end)
]])
expect_error("Continue must be last statement within a block", [[
repeat
continue
x = true
until Q
]])
expect_error("Invalid usage of actvar slot which was valid at the time of the continue", [[
repeat
do
local p = 1
continue
end
local q = 2
until q == 1
]])
expect_error("Multiple continue usage", [[
for i = 1, 10 do print(i) end -- Increment PC and line count a bit
repeat
if false then continue end
local AA
if false then continue end
until AA
]])
expect_error("Continue outside of a loop", [[
continue
]])
if not good then
print "At least one failure!"
end