api: execute lua directly from the remote api

This commit is contained in:
Björn Linse
2017-05-09 08:55:04 +02:00
parent 12fb634fe6
commit f424189093
3 changed files with 112 additions and 0 deletions

View File

@@ -81,6 +81,36 @@ describe('api', function()
end)
end)
describe('nvim_execute_lua', function()
it('works', function()
meths.execute_lua('vim.api.nvim_set_var("test", 3)', {})
eq(3, meths.get_var('test'))
eq(17, meths.execute_lua('a, b = ...\nreturn a + b', {10,7}))
eq(NIL, meths.execute_lua('function xx(a,b)\nreturn a..b\nend',{}))
eq("xy", meths.execute_lua('return xx(...)', {'x','y'}))
end)
it('reports errors', function()
eq({false, 'Error loading lua: [string "<nvim>"]:1: '..
"'=' expected near '+'"},
meth_pcall(meths.execute_lua, 'a+*b', {}))
eq({false, 'Error loading lua: [string "<nvim>"]:1: '..
"unexpected symbol near '1'"},
meth_pcall(meths.execute_lua, '1+2', {}))
eq({false, 'Error loading lua: [string "<nvim>"]:1: '..
"unexpected symbol"},
meth_pcall(meths.execute_lua, 'aa=bb\0', {}))
eq({false, 'Error executing lua: [string "<nvim>"]:1: '..
"attempt to call global 'bork' (a nil value)"},
meth_pcall(meths.execute_lua, 'bork()', {}))
end)
end)
describe('nvim_input', function()
it("VimL error: does NOT fail, updates v:errmsg", function()
local status, _ = pcall(nvim, "input", ":call bogus_fn()<CR>")