aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/lua')
-rw-r--r--test/functional/lua/commands_spec.lua2
-rw-r--r--test/functional/lua/luaeval_spec.lua4
-rw-r--r--test/functional/lua/treesitter_spec.lua102
-rw-r--r--test/functional/lua/vim_spec.lua207
4 files changed, 231 insertions, 84 deletions
diff --git a/test/functional/lua/commands_spec.lua b/test/functional/lua/commands_spec.lua
index cbc3aee557..f2a1b7dede 100644
--- a/test/functional/lua/commands_spec.lua
+++ b/test/functional/lua/commands_spec.lua
@@ -43,7 +43,7 @@ describe(':lua command', function()
eq({'', 'ETTS', 'TTSE', 'STTE'}, curbufmeths.get_lines(0, 100, false))
end)
it('throws catchable errors', function()
- eq([[Vim(lua):E5107: Error loading lua [string ":lua"]:1: unexpected symbol near ')']],
+ eq([[Vim(lua):E5107: Error loading lua [string ":lua"]:0: unexpected symbol near ')']],
pcall_err(command, 'lua ()'))
eq([[Vim(lua):E5108: Error executing lua [string ":lua"]:1: TEST]],
exc_exec('lua error("TEST")'))
diff --git a/test/functional/lua/luaeval_spec.lua b/test/functional/lua/luaeval_spec.lua
index 75966393b1..2ec48777fd 100644
--- a/test/functional/lua/luaeval_spec.lua
+++ b/test/functional/lua/luaeval_spec.lua
@@ -477,14 +477,14 @@ describe('v:lua', function()
eq(NIL, eval('v:lua.mymod.noisy("eval")'))
eq("hey eval", meths.get_current_line())
- eq("Vim:E5108: Error executing lua [string \"<nvim>\"]:10: attempt to call global 'nonexistent' (a nil value)",
+ eq("Vim:E5108: Error executing lua [string \"<nvim>\"]:0: attempt to call global 'nonexistent' (a nil value)",
pcall_err(eval, 'v:lua.mymod.crashy()'))
end)
it('works in :call', function()
command(":call v:lua.mymod.noisy('command')")
eq("hey command", meths.get_current_line())
- eq("Vim(call):E5108: Error executing lua [string \"<nvim>\"]:10: attempt to call global 'nonexistent' (a nil value)",
+ eq("Vim(call):E5108: Error executing lua [string \"<nvim>\"]:0: attempt to call global 'nonexistent' (a nil value)",
pcall_err(command, 'call v:lua.mymod.crashy()'))
end)
diff --git a/test/functional/lua/treesitter_spec.lua b/test/functional/lua/treesitter_spec.lua
index 74ae6cde2b..3526b64395 100644
--- a/test/functional/lua/treesitter_spec.lua
+++ b/test/functional/lua/treesitter_spec.lua
@@ -15,17 +15,16 @@ before_each(clear)
describe('treesitter API', function()
-- error tests not requiring a parser library
it('handles missing language', function()
- eq("Error executing lua: .../language.lua: no parser for 'borklang' language, see :help treesitter-parsers",
+ eq("Error executing lua: .../language.lua:0: no parser for 'borklang' language, see :help treesitter-parsers",
pcall_err(exec_lua, "parser = vim.treesitter.get_parser(0, 'borklang')"))
-- actual message depends on platform
matches("Error executing lua: Failed to load parser: uv_dlopen: .+",
pcall_err(exec_lua, "parser = vim.treesitter.require_language('borklang', 'borkbork.so')"))
- eq("Error executing lua: .../language.lua: no parser for 'borklang' language, see :help treesitter-parsers",
+ eq("Error executing lua: .../language.lua:0: no parser for 'borklang' language, see :help treesitter-parsers",
pcall_err(exec_lua, "parser = vim.treesitter.inspect_language('borklang')"))
end)
-
end)
describe('treesitter API with C parser', function()
@@ -186,6 +185,16 @@ void ui_refresh(void)
(field_expression argument: (identifier) @fieldarg)
]]
+ it("supports runtime queries", function()
+ if not check_parser() then return end
+
+ local ret = exec_lua [[
+ return require"vim.treesitter.query".get_query("c", "highlights").captures[1]
+ ]]
+
+ eq('variable', ret)
+ end)
+
it('support query and iter by capture', function()
if not check_parser() then return end
@@ -420,9 +429,10 @@ static int nlua_schedule(lua_State *const lstate)
]]}
exec_lua([[
+ local parser = vim.treesitter.get_parser(0, "c")
local highlighter = vim.treesitter.highlighter
local query = ...
- test_hl = highlighter.new(query, 0, "c")
+ test_hl = highlighter.new(parser, query)
]], hl_query)
screen:expect{grid=[[
{2:/// Schedule Lua callback on main loop's event queue} |
@@ -559,6 +569,72 @@ static int nlua_schedule(lua_State *const lstate)
]]}
end)
+ it("supports highlighting with custom parser", function()
+ if not check_parser() then return end
+
+ local screen = Screen.new(65, 18)
+ screen:attach()
+ screen:set_default_attr_ids({ {bold = true, foreground = Screen.colors.SeaGreen4} })
+
+ insert(test_text)
+
+ screen:expect{ grid= [[
+ int width = INT_MAX, height = INT_MAX; |
+ bool ext_widgets[kUIExtCount]; |
+ for (UIExtension i = 0; (int)i < kUIExtCount; i++) { |
+ ext_widgets[i] = true; |
+ } |
+ |
+ bool inclusive = ui_override(); |
+ for (size_t i = 0; i < ui_count; i++) { |
+ UI *ui = uis[i]; |
+ width = MIN(ui->width, width); |
+ height = MIN(ui->height, height); |
+ foo = BAR(ui->bazaar, bazaar); |
+ for (UIExtension j = 0; (int)j < kUIExtCount; j++) { |
+ ext_widgets[j] &= (ui->ui_ext[j] || inclusive); |
+ } |
+ } |
+ ^} |
+ |
+ ]] }
+
+ exec_lua([[
+ parser = vim.treesitter.get_parser(0, "c")
+ query = vim.treesitter.parse_query("c", "(declaration) @decl")
+
+ local nodes = {}
+ for _, node in query:iter_captures(parser:parse():root(), 0, 0, 19) do
+ table.insert(nodes, node)
+ end
+
+ parser:set_included_ranges(nodes)
+
+ local hl = vim.treesitter.highlighter.new(parser, "(identifier) @type")
+ ]])
+
+ screen:expect{ grid = [[
+ int {1:width} = {1:INT_MAX}, {1:height} = {1:INT_MAX}; |
+ bool {1:ext_widgets}[{1:kUIExtCount}]; |
+ for (UIExtension {1:i} = 0; (int)i < kUIExtCount; i++) { |
+ ext_widgets[i] = true; |
+ } |
+ |
+ bool {1:inclusive} = {1:ui_override}(); |
+ for (size_t {1:i} = 0; i < ui_count; i++) { |
+ UI *{1:ui} = {1:uis}[{1:i}]; |
+ width = MIN(ui->width, width); |
+ height = MIN(ui->height, height); |
+ foo = BAR(ui->bazaar, bazaar); |
+ for (UIExtension {1:j} = 0; (int)j < kUIExtCount; j++) { |
+ ext_widgets[j] &= (ui->ui_ext[j] || inclusive); |
+ } |
+ } |
+ ^} |
+ |
+ ]] }
+ end)
+
it('inspects language', function()
if not check_parser() then return end
@@ -604,23 +680,29 @@ static int nlua_schedule(lua_State *const lstate)
insert(test_text)
- local res = exec_lua([[
+ local res = exec_lua [[
parser = vim.treesitter.get_parser(0, "c")
return { parser:parse():root():range() }
- ]])
+ ]]
eq({0, 0, 19, 0}, res)
-- The following sets the included ranges for the current parser
-- As stated here, this only includes the function (thus the whole buffer, without the last line)
- local res2 = exec_lua([[
+ local res2 = exec_lua [[
local root = parser:parse():root()
parser:set_included_ranges({root:child(0)})
parser.valid = false
return { parser:parse():root():range() }
- ]])
+ ]]
eq({0, 0, 18, 1}, res2)
+
+ local range = exec_lua [[
+ return parser:included_ranges()
+ ]]
+
+ eq(range, { { 0, 0, 18, 1 } })
end)
it("allows to set complex ranges", function()
if not check_parser() then return end
@@ -628,7 +710,7 @@ static int nlua_schedule(lua_State *const lstate)
insert(test_text)
- local res = exec_lua([[
+ local res = exec_lua [[
parser = vim.treesitter.get_parser(0, "c")
query = vim.treesitter.parse_query("c", "(declaration) @decl")
@@ -646,7 +728,7 @@ static int nlua_schedule(lua_State *const lstate)
table.insert(res, { root:named_child(i):range() })
end
return res
- ]])
+ ]]
eq({
{ 2, 2, 2, 40 },
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua
index 63e48a18ca..1cbf6b21e3 100644
--- a/test/functional/lua/vim_spec.lua
+++ b/test/functional/lua/vim_spec.lua
@@ -4,13 +4,14 @@ local Screen = require('test.functional.ui.screen')
local funcs = helpers.funcs
local meths = helpers.meths
+local dedent = helpers.dedent
local command = helpers.command
local clear = helpers.clear
local eq = helpers.eq
local ok = helpers.ok
local eval = helpers.eval
local feed = helpers.feed
-local pcall_err = helpers.pcall_err
+local pcall_err_withfile = helpers.pcall_err_withfile
local exec_lua = helpers.exec_lua
local matches = helpers.matches
local source = helpers.source
@@ -128,8 +129,8 @@ describe('lua stdlib', function()
eq(false, funcs.luaeval('vim.startswith("123", "2")'))
eq(false, funcs.luaeval('vim.startswith("123", "1234")'))
- eq("string", type(pcall_err(funcs.luaeval, 'vim.startswith("123", nil)')))
- eq("string", type(pcall_err(funcs.luaeval, 'vim.startswith(nil, "123")')))
+ eq("string", type(pcall_err_withfile(funcs.luaeval, 'vim.startswith("123", nil)')))
+ eq("string", type(pcall_err_withfile(funcs.luaeval, 'vim.startswith(nil, "123")')))
end)
it('vim.endswith', function()
@@ -142,8 +143,8 @@ describe('lua stdlib', function()
eq(false, funcs.luaeval('vim.endswith("123", "2")'))
eq(false, funcs.luaeval('vim.endswith("123", "1234")'))
- eq("string", type(pcall_err(funcs.luaeval, 'vim.endswith("123", nil)')))
- eq("string", type(pcall_err(funcs.luaeval, 'vim.endswith(nil, "123")')))
+ eq("string", type(pcall_err_withfile(funcs.luaeval, 'vim.endswith("123", nil)')))
+ eq("string", type(pcall_err_withfile(funcs.luaeval, 'vim.endswith(nil, "123")')))
end)
it("vim.str_utfindex/str_byteindex", function()
@@ -182,10 +183,10 @@ describe('lua stdlib', function()
eq({"yy","xx"}, exec_lua("return test_table"))
-- Validates args.
- eq('Error executing lua: vim.schedule: expected function',
- pcall_err(exec_lua, "vim.schedule('stringly')"))
- eq('Error executing lua: vim.schedule: expected function',
- pcall_err(exec_lua, "vim.schedule()"))
+ eq('.../helpers.lua:0: Error executing lua: vim.schedule: expected function',
+ pcall_err_withfile(exec_lua, "vim.schedule('stringly')"))
+ eq('.../helpers.lua:0: Error executing lua: vim.schedule: expected function',
+ pcall_err_withfile(exec_lua, "vim.schedule()"))
exec_lua([[
vim.schedule(function()
@@ -257,17 +258,29 @@ describe('lua stdlib', function()
}
for _, t in ipairs(loops) do
- matches(".*Infinite loop detected", pcall_err(split, t[1], t[2]))
+ matches(".*Infinite loop detected", pcall_err_withfile(split, t[1], t[2]))
end
-- Validates args.
eq(true, pcall(split, 'string', 'string'))
- eq('Error executing lua: .../shared.lua: s: expected string, got number',
- pcall_err(split, 1, 'string'))
- eq('Error executing lua: .../shared.lua: sep: expected string, got number',
- pcall_err(split, 'string', 1))
- eq('Error executing lua: .../shared.lua: plain: expected boolean, got number',
- pcall_err(split, 'string', 'string', 1))
+ eq(dedent([[
+ .../helpers.lua:0: Error executing lua: shared.lua:0: s: expected string, got number
+ stack traceback:
+ shared.lua:0: in function 'gsplit'
+ shared.lua:0: in function <shared.lua:0>]]),
+ pcall_err_withfile(split, 1, 'string'))
+ eq(dedent([[
+ .../helpers.lua:0: Error executing lua: shared.lua:0: sep: expected string, got number
+ stack traceback:
+ shared.lua:0: in function 'gsplit'
+ shared.lua:0: in function <shared.lua:0>]]),
+ pcall_err_withfile(split, 'string', 1))
+ eq(dedent([[
+ .../helpers.lua:0: Error executing lua: shared.lua:0: plain: expected boolean, got number
+ stack traceback:
+ shared.lua:0: in function 'gsplit'
+ shared.lua:0: in function <shared.lua:0>]]),
+ pcall_err_withfile(split, 'string', 'string', 1))
end)
it('vim.trim', function()
@@ -287,8 +300,11 @@ describe('lua stdlib', function()
end
-- Validates args.
- eq('Error executing lua: .../shared.lua: s: expected string, got number',
- pcall_err(trim, 2))
+ eq(dedent([[
+ .../helpers.lua:0: Error executing lua: shared.lua:0: s: expected string, got number
+ stack traceback:
+ shared.lua:0: in function <shared.lua:0>]]),
+ pcall_err_withfile(trim, 2))
end)
it('vim.inspect', function()
@@ -353,8 +369,8 @@ describe('lua stdlib', function()
return t1.f() ~= t2.f()
]]))
- eq('Error executing lua: .../shared.lua: Cannot deepcopy object of type thread',
- pcall_err(exec_lua, [[
+ eq('.../helpers.lua:0: Error executing lua: shared.lua:0: Cannot deepcopy object of type thread',
+ pcall_err_withfile(exec_lua, [[
local thread = coroutine.create(function () return 0 end)
local t = {thr = thread}
vim.deepcopy(t)
@@ -366,8 +382,11 @@ describe('lua stdlib', function()
eq('foo%%%-bar', exec_lua([[return vim.pesc(vim.pesc('foo-bar'))]]))
-- Validates args.
- eq('Error executing lua: .../shared.lua: s: expected string, got number',
- pcall_err(exec_lua, [[return vim.pesc(2)]]))
+ eq(dedent([[
+ .../helpers.lua:0: Error executing lua: shared.lua:0: s: expected string, got number
+ stack traceback:
+ shared.lua:0: in function <shared.lua:0>]]),
+ pcall_err_withfile(exec_lua, [[return vim.pesc(2)]]))
end)
it('vim.tbl_keys', function()
@@ -491,20 +510,20 @@ describe('lua stdlib', function()
return c.x.a == 1 and c.x.b == 2 and c.x.c == nil and count == 1
]]))
- eq('Error executing lua: .../shared.lua: invalid "behavior": nil',
- pcall_err(exec_lua, [[
+ eq('.../helpers.lua:0: Error executing lua: shared.lua:0: invalid "behavior": nil',
+ pcall_err_withfile(exec_lua, [[
return vim.tbl_extend()
]])
)
- eq('Error executing lua: .../shared.lua: wrong number of arguments (given 1, expected at least 3)',
- pcall_err(exec_lua, [[
+ eq('.../helpers.lua:0: Error executing lua: shared.lua:0: wrong number of arguments (given 1, expected at least 3)',
+ pcall_err_withfile(exec_lua, [[
return vim.tbl_extend("keep")
]])
)
- eq('Error executing lua: .../shared.lua: wrong number of arguments (given 2, expected at least 3)',
- pcall_err(exec_lua, [[
+ eq('.../helpers.lua:0: Error executing lua: shared.lua:0: wrong number of arguments (given 2, expected at least 3)',
+ pcall_err_withfile(exec_lua, [[
return vim.tbl_extend("keep", {})
]])
)
@@ -579,20 +598,20 @@ describe('lua stdlib', function()
return vim.tbl_islist(c) and count == 0
]]))
- eq('Error executing lua: .../shared.lua: invalid "behavior": nil',
- pcall_err(exec_lua, [[
+ eq('.../helpers.lua:0: Error executing lua: shared.lua:0: invalid "behavior": nil',
+ pcall_err_withfile(exec_lua, [[
return vim.tbl_deep_extend()
]])
)
- eq('Error executing lua: .../shared.lua: wrong number of arguments (given 1, expected at least 3)',
- pcall_err(exec_lua, [[
+ eq('.../helpers.lua:0: Error executing lua: shared.lua:0: wrong number of arguments (given 1, expected at least 3)',
+ pcall_err_withfile(exec_lua, [[
return vim.tbl_deep_extend("keep")
]])
)
- eq('Error executing lua: .../shared.lua: wrong number of arguments (given 2, expected at least 3)',
- pcall_err(exec_lua, [[
+ eq('.../helpers.lua:0: Error executing lua: shared.lua:0: wrong number of arguments (given 2, expected at least 3)',
+ pcall_err_withfile(exec_lua, [[
return vim.tbl_deep_extend("keep", {})
]])
)
@@ -624,8 +643,11 @@ describe('lua stdlib', function()
it('vim.list_extend', function()
eq({1,2,3}, exec_lua [[ return vim.list_extend({1}, {2,3}) ]])
- eq('Error executing lua: .../shared.lua: src: expected table, got nil',
- pcall_err(exec_lua, [[ return vim.list_extend({1}, nil) ]]))
+ eq(dedent([[
+ .../helpers.lua:0: Error executing lua: shared.lua:0: src: expected table, got nil
+ stack traceback:
+ shared.lua:0: in function <shared.lua:0>]]),
+ pcall_err_withfile(exec_lua, [[ return vim.list_extend({1}, nil) ]]))
eq({1,2}, exec_lua [[ return vim.list_extend({1}, {2;a=1}) ]])
eq(true, exec_lua [[ local a = {1} return vim.list_extend(a, {2;a=1}) == a ]])
eq({2}, exec_lua [[ return vim.list_extend({}, {2;a=1}, 1) ]])
@@ -648,8 +670,8 @@ describe('lua stdlib', function()
assert(vim.deep_equal(a, { A = 1; [1] = 'A'; }))
vim.tbl_add_reverse_lookup(a)
]]
- matches('Error executing lua: .../shared.lua: The reverse lookup found an existing value for "[1A]" while processing key "[1A]"',
- pcall_err(exec_lua, code))
+ matches('.../helpers.lua:0: Error executing lua: shared.lua:0: The reverse lookup found an existing value for "[1A]" while processing key "[1A]"',
+ pcall_err_withfile(exec_lua, code))
end)
it('vim.call, vim.fn', function()
@@ -820,34 +842,77 @@ describe('lua stdlib', function()
exec_lua("vim.validate{arg1={{}, 't' }, arg2={ 'foo', 's' }}")
exec_lua("vim.validate{arg1={2, function(a) return (a % 2) == 0 end, 'even number' }}")
- eq("Error executing lua: .../shared.lua: 1: expected table, got number",
- pcall_err(exec_lua, "vim.validate{ 1, 'x' }"))
- eq("Error executing lua: .../shared.lua: invalid type name: x",
- pcall_err(exec_lua, "vim.validate{ arg1={ 1, 'x' }}"))
- eq("Error executing lua: .../shared.lua: invalid type name: 1",
- pcall_err(exec_lua, "vim.validate{ arg1={ 1, 1 }}"))
- eq("Error executing lua: .../shared.lua: invalid type name: nil",
- pcall_err(exec_lua, "vim.validate{ arg1={ 1 }}"))
+ eq(dedent([[
+ .../helpers.lua:0: Error executing lua: [string "<nvim>"]:0: opt[1]: expected table, got number
+ stack traceback:
+ [string "<nvim>"]:0: in main chunk]]),
+ pcall_err_withfile(exec_lua, "vim.validate{ 1, 'x' }"))
+ eq(dedent([[
+ .../helpers.lua:0: Error executing lua: [string "<nvim>"]:0: invalid type name: x
+ stack traceback:
+ [string "<nvim>"]:0: in main chunk]]),
+ pcall_err_withfile(exec_lua, "vim.validate{ arg1={ 1, 'x' }}"))
+ eq(dedent([[
+ .../helpers.lua:0: Error executing lua: [string "<nvim>"]:0: invalid type name: 1
+ stack traceback:
+ [string "<nvim>"]:0: in main chunk]]),
+ pcall_err_withfile(exec_lua, "vim.validate{ arg1={ 1, 1 }}"))
+ eq(dedent([[
+ .../helpers.lua:0: Error executing lua: [string "<nvim>"]:0: invalid type name: nil
+ stack traceback:
+ [string "<nvim>"]:0: in main chunk]]),
+ pcall_err_withfile(exec_lua, "vim.validate{ arg1={ 1 }}"))
-- Validated parameters are required by default.
- eq("Error executing lua: .../shared.lua: arg1: expected string, got nil",
- pcall_err(exec_lua, "vim.validate{ arg1={ nil, 's' }}"))
+ eq(dedent([[
+ .../helpers.lua:0: Error executing lua: [string "<nvim>"]:0: arg1: expected string, got nil
+ stack traceback:
+ [string "<nvim>"]:0: in main chunk]]),
+ pcall_err_withfile(exec_lua, "vim.validate{ arg1={ nil, 's' }}"))
-- Explicitly required.
- eq("Error executing lua: .../shared.lua: arg1: expected string, got nil",
- pcall_err(exec_lua, "vim.validate{ arg1={ nil, 's', false }}"))
-
- eq("Error executing lua: .../shared.lua: arg1: expected table, got number",
- pcall_err(exec_lua, "vim.validate{arg1={1, 't'}}"))
- eq("Error executing lua: .../shared.lua: arg2: expected string, got number",
- pcall_err(exec_lua, "vim.validate{arg1={{}, 't'}, arg2={1, 's'}}"))
- eq("Error executing lua: .../shared.lua: arg2: expected string, got nil",
- pcall_err(exec_lua, "vim.validate{arg1={{}, 't'}, arg2={nil, 's'}}"))
- eq("Error executing lua: .../shared.lua: arg2: expected string, got nil",
- pcall_err(exec_lua, "vim.validate{arg1={{}, 't'}, arg2={nil, 's'}}"))
- eq("Error executing lua: .../shared.lua: arg1: expected even number, got 3",
- pcall_err(exec_lua, "vim.validate{arg1={3, function(a) return a == 1 end, 'even number'}}"))
- eq("Error executing lua: .../shared.lua: arg1: expected ?, got 3",
- pcall_err(exec_lua, "vim.validate{arg1={3, function(a) return a == 1 end}}"))
+ eq(dedent([[
+ .../helpers.lua:0: Error executing lua: [string "<nvim>"]:0: arg1: expected string, got nil
+ stack traceback:
+ [string "<nvim>"]:0: in main chunk]]),
+ pcall_err_withfile(exec_lua, "vim.validate{ arg1={ nil, 's', false }}"))
+
+ eq(dedent([[
+ .../helpers.lua:0: Error executing lua: [string "<nvim>"]:0: arg1: expected table, got number
+ stack traceback:
+ [string "<nvim>"]:0: in main chunk]]),
+ pcall_err_withfile(exec_lua, "vim.validate{arg1={1, 't'}}"))
+ eq(dedent([[
+ .../helpers.lua:0: Error executing lua: [string "<nvim>"]:0: arg2: expected string, got number
+ stack traceback:
+ [string "<nvim>"]:0: in main chunk]]),
+ pcall_err_withfile(exec_lua, "vim.validate{arg1={{}, 't'}, arg2={1, 's'}}"))
+ eq(dedent([[
+ .../helpers.lua:0: Error executing lua: [string "<nvim>"]:0: arg2: expected string, got nil
+ stack traceback:
+ [string "<nvim>"]:0: in main chunk]]),
+ pcall_err_withfile(exec_lua, "vim.validate{arg1={{}, 't'}, arg2={nil, 's'}}"))
+ eq(dedent([[
+ .../helpers.lua:0: Error executing lua: [string "<nvim>"]:0: arg2: expected string, got nil
+ stack traceback:
+ [string "<nvim>"]:0: in main chunk]]),
+ pcall_err_withfile(exec_lua, "vim.validate{arg1={{}, 't'}, arg2={nil, 's'}}"))
+ eq(dedent([[
+ .../helpers.lua:0: Error executing lua: [string "<nvim>"]:0: arg1: expected even number, got 3
+ stack traceback:
+ [string "<nvim>"]:0: in main chunk]]),
+ pcall_err_withfile(exec_lua, "vim.validate{arg1={3, function(a) return a == 1 end, 'even number'}}"))
+ eq(dedent([[
+ .../helpers.lua:0: Error executing lua: [string "<nvim>"]:0: arg1: expected ?, got 3
+ stack traceback:
+ [string "<nvim>"]:0: in main chunk]]),
+ pcall_err_withfile(exec_lua, "vim.validate{arg1={3, function(a) return a == 1 end}}"))
+
+ -- Pass an additional message back.
+ eq(dedent([[
+ .../helpers.lua:0: Error executing lua: [string "<nvim>"]:0: arg1: expected ?, got 3. Info: TEST_MSG
+ stack traceback:
+ [string "<nvim>"]:0: in main chunk]]),
+ pcall_err_withfile(exec_lua, "vim.validate{arg1={3, function(a) return a == 1, 'TEST_MSG' end}}"))
end)
it('vim.is_callable', function()
@@ -992,10 +1057,10 @@ describe('lua stdlib', function()
]]
eq('', funcs.luaeval "vim.bo.filetype")
eq(true, funcs.luaeval "vim.bo[BUF].modifiable")
- matches("^Error executing lua: .*: Invalid option name: 'nosuchopt'$",
- pcall_err(exec_lua, 'return vim.bo.nosuchopt'))
- matches("^Error executing lua: .*: Expected lua string$",
- pcall_err(exec_lua, 'return vim.bo[0][0].autoread'))
+ matches("^.../helpers.lua:0: Error executing lua: .*: Invalid option name: 'nosuchopt'$",
+ pcall_err_withfile(exec_lua, 'return vim.bo.nosuchopt'))
+ matches("^.../helpers.lua:0: Error executing lua: .*: Expected lua string$",
+ pcall_err_withfile(exec_lua, 'return vim.bo[0][0].autoread'))
end)
it('vim.wo', function()
@@ -1011,10 +1076,10 @@ describe('lua stdlib', function()
eq(0, funcs.luaeval "vim.wo.cole")
eq(0, funcs.luaeval "vim.wo[0].cole")
eq(0, funcs.luaeval "vim.wo[1001].cole")
- matches("^Error executing lua: .*: Invalid option name: 'notanopt'$",
- pcall_err(exec_lua, 'return vim.wo.notanopt'))
- matches("^Error executing lua: .*: Expected lua string$",
- pcall_err(exec_lua, 'return vim.wo[0][0].list'))
+ matches("^.../helpers.lua:0: Error executing lua: .*: Invalid option name: 'notanopt'$",
+ pcall_err_withfile(exec_lua, 'return vim.wo.notanopt'))
+ matches("^.../helpers.lua:0: Error executing lua: .*: Expected lua string$",
+ pcall_err_withfile(exec_lua, 'return vim.wo[0][0].list'))
eq(2, funcs.luaeval "vim.wo[1000].cole")
exec_lua [[
vim.wo[1000].cole = 0