Skip to content

Commit

Permalink
Move a couple of Lua 5.1-specific syntax errors
Browse files Browse the repository at this point in the history
  • Loading branch information
SquidDev committed Nov 1, 2023
1 parent 90be182 commit dc245ed
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
9 changes: 0 additions & 9 deletions src/test/resources/assert/lua5.1/errors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,8 @@ assert(doit("unpack({}, 1, n=2^30)"))
assert(doit("a=math.sin()"))
assert(not doit("tostring(1)") and doit("tostring()"))
assert(doit "tonumber()")
assert(doit "repeat until 1; a")
--checksyntax("break label", "", "label", 1)
assert(doit ";")
assert(doit "a=1;;")
assert(doit "return;;")
assert(doit "assert(false)")
assert(doit "assert(nil)")
assert(doit "a=math.sin\n(3)")
assert(doit("function a (... , ...) end"))
assert(doit("function a (, ...) end"))

--[=[
checksyntax([[
local a = {4
Expand Down
27 changes: 27 additions & 0 deletions src/test/resources/spec/parser_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,31 @@ describe("The Lua lexer/parser", function()
expect(x):eq(20)
end)
end)

describe("parse errors", function()
local function it_error(name, code, msg)
it(name, function()
local fn, err = (loadstring or load)(code)
expect(fn):eq(nil)
if msg then expect(err):str_match(msg) end
end)
end

local function it_lua51(name, code, msg)
it_error(name .. " :lua==5.1", code, msg)
it(name .. ":lua~=5.1 :!cobalt", function()
local fn, err = load(code)
if not fn then fail(err) end
end)
end

it_error("break with no scope", "break label()", "loop")
it_lua51("bare semicolon", ";")
it_lua51("multiple semicolons", "a=1;;")
it_error("multiple semicolons after return", "return;;")
it_lua51("ambiguous call syntax", "a=math.sin\n(3)")
it_error("bare variable after repeat", "repeat until 1; a")
it_error("multiple varargs", "function a (... , ...) end")
it_error("comma after varargs", "function a (, ...) end")
end)
end)

0 comments on commit dc245ed

Please sign in to comment.