Skip to content

Commit

Permalink
tests: adds extra test spec for testing the errors when calling after…
Browse files Browse the repository at this point in the history
… a newline

Also reworks test spec for this PR to be in more logical places.
  • Loading branch information
JR-Mitchell authored and hishamhm committed Dec 31, 2024
1 parent 8f87db7 commit 0110da7
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 46 deletions.
46 changes: 0 additions & 46 deletions spec/lang/call/function_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,52 +89,6 @@ describe("function call", function()
]]))
end)

describe("call the result of calling functions with string literals:", function()
it("with single quotes", util.check([[
local function f(a: string): function()
return function() end
end
f'hello'()
]]))

it("with double quotes", util.check([[
local function f(a: string): function()
return function() end
end
f"hello"()
]]))

it("with double square brackets", util.check([=[
local function f(a: string): function()
return function() end
end
f[[hello]]()
]=]))

it("with double square brackets across multiple lines", util.check_lua([=[
local function f(a: string): function()
return function() end
end
f[[hello
world]]()
]=]))

it("with double square brackets with equals", util.check([[
local function f(a: string): function()
return function() end
end
f[=[hello]=]()
]]))

it("with double square brackets with equals across multiple lines", util.check_lua([[
local function f(a: string): function()
return function() end
end
f[=[hello
world]=]()
]]))
end)

describe("check the arity of functions:", function()
it("when excessive", util.check_type_error([[
local function f(n: number, m: number): number
Expand Down
27 changes: 27 additions & 0 deletions spec/lang/parser/lua_parser_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
util = require("spec.util")

describe("lua next-line function calls", function()
it("allows calls on the next line in lua parsing mode", util.check_lua([=[
local function test(a)
end
test
("hello world")
]=]))

it("allows string literal calls on the next line in lua parsing mode", util.check_lua([=[
local function test(a)
end
test
"hello world"
]=]))

it("allows calls after multiline string literals in lua parsing mode", util.check_lua([=[
local function test(a): function()
return function() end
end
test[[hello
world]]()
]=]))
end)
22 changes: 22 additions & 0 deletions spec/lang/parser/syntax_errors_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,27 @@ describe("syntax errors", function()
{ y = 7, x = 6 + 6, msg = "syntax error, cannot perform an assignment here (did you mean '=='?)" },
}))

it("doesn't support function calls on new lines", util.check_syntax_error([=[
local function test(a: string): function()
end
test
("hello world")
]=], {
{ y = 4, x = 11, msg = "syntax error, expected '='" },
{ y = 5, msg = "syntax error" },
}))

it("doesn't support function calls after multiline string literals", util.check_syntax_error([=[
local function test(a: string): function()
return function() end
end
test[[hello
world]]()
]=], {
{ y = 5, x = 15, msg = "syntax error" },
{ y = 5, msg = "syntax error, expected ')'" },
}))

end)

0 comments on commit 0110da7

Please sign in to comment.