This repository has been archived by the owner on Nov 20, 2020. It is now read-only.
forked from ewmailing/lua-TestMore
-
Notifications
You must be signed in to change notification settings - Fork 2
/
204-grammar.t
executable file
·106 lines (89 loc) · 1.92 KB
/
204-grammar.t
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#! /usr/bin/lua
--
-- lua-TestMore : <http://fperrad.github.com/lua-TestMore/>
--
-- Copyright (C) 2010-2012, Perrad Francois
--
-- This code is licensed under the terms of the MIT/X11 license,
-- like Lua itself.
--
--[[
=head1 Lua Grammar
=head2 Synopsis
% prove 204-grammar.t
=head2 Description
See "Lua 5.2 Reference Manual", section 9 "The Complete Syntax of Lua",
L<http://www.lua.org/manual/5.2/manual.html#9>.
=cut
--]]
require 'Test.More'
plan(6)
--[[ empty statement ]]
f, msg = load [[; a = 1]]
type_ok(f, 'function', "empty statement")
--[[ orphan break ]]
f, msg = load [[
function f()
print "before"
do
print "inner"
break
end
print "after"
end
]]
if arg[-1] == 'luajit' then
like(msg, "^[^:]+:%d+: no loop to break", "orphan break")
else
like(msg, "^[^:]+:%d+: <break> at line 5 not inside a loop", "orphan break")
end
--[[ break anywhere ]]
lives_ok( [[
function f()
print "before"
while true do
print "inner"
break
print "break"
end
print "after"
end
]], "break anywhere")
--[[ goto ]]
f, msg = load [[
::label::
goto unknown
]]
if arg[-1] == 'luajit' then
like(msg, ":%d+: undefined label 'unknown'", "unknown goto")
else
like(msg, ":%d+: no visible label 'unknown' for <goto> at line %d+", "unknown goto")
end
f, msg = load [[
::label::
goto label
::label::
]]
if arg[-1] == 'luajit' then
like(msg, ":%d+: duplicate label 'label'", "duplicate label")
else
like(msg, ":%d+: label 'label' already defined on line %d+", "duplicate label")
end
f, msg = load [[
::e::
goto f
local x
::f::
goto e
]]
if arg[-1] == 'luajit' then
like(msg, ":%d+: <goto f> jumps into the scope of local 'x'", "bad goto")
else
like(msg, ":%d+: <goto f> at line %d+ jumps into the scope of local 'x'", "bad goto")
end
-- Local Variables:
-- mode: lua
-- lua-indent-level: 4
-- fill-column: 100
-- End:
-- vim: ft=lua expandtab shiftwidth=4: