mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
functests: Add some tests
This commit is contained in:
36
test/functional/lua/api_spec.lua
Normal file
36
test/functional/lua/api_spec.lua
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
-- Test suite for testing interactions with API bindings
|
||||||
|
local helpers = require('test.functional.helpers')(after_each)
|
||||||
|
|
||||||
|
local funcs = helpers.funcs
|
||||||
|
local clear = helpers.clear
|
||||||
|
local NIL = helpers.NIL
|
||||||
|
local eq = helpers.eq
|
||||||
|
|
||||||
|
before_each(clear)
|
||||||
|
|
||||||
|
describe('luaeval(vim.api.…)', function()
|
||||||
|
describe('with channel_id and buffer handle', function()
|
||||||
|
describe('nvim_buf_get_lines', function()
|
||||||
|
it('works', function()
|
||||||
|
funcs.setline(1, {"abc", "def", "a\nb", "ttt"})
|
||||||
|
eq({{_TYPE={}, _VAL={'a\nb'}}},
|
||||||
|
funcs.luaeval('vim.api.nvim_buf_get_lines(1, 2, 3, false)'))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
describe('nvim_buf_set_lines', function()
|
||||||
|
it('works', function()
|
||||||
|
funcs.setline(1, {"abc", "def", "a\nb", "ttt"})
|
||||||
|
eq(NIL, funcs.luaeval('vim.api.nvim_buf_set_lines(1, 1, 2, false, {"b\\0a"})'))
|
||||||
|
eq({'abc', {_TYPE={}, _VAL={'b\na'}}, {_TYPE={}, _VAL={'a\nb'}}, 'ttt'},
|
||||||
|
funcs.luaeval('vim.api.nvim_buf_get_lines(1, 0, 4, false)'))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
describe('with errors', function()
|
||||||
|
it('transforms API errors into lua errors', function()
|
||||||
|
funcs.setline(1, {"abc", "def", "a\nb", "ttt"})
|
||||||
|
eq({false, 'string cannot contain newlines'},
|
||||||
|
funcs.luaeval('{pcall(vim.api.nvim_buf_set_lines, 1, 1, 2, false, {"b\\na"})}'))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
end)
|
4
test/functional/lua/commands_spec.lua
Normal file
4
test/functional/lua/commands_spec.lua
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
-- Test suite for checking :lua* commands
|
||||||
|
local helpers = require('test.functional.helpers')(after_each)
|
||||||
|
|
||||||
|
local eq = helpers.eq
|
63
test/functional/lua/luaeval_spec.lua
Normal file
63
test/functional/lua/luaeval_spec.lua
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
-- Test suite for testing luaeval() function
|
||||||
|
local helpers = require('test.functional.helpers')(after_each)
|
||||||
|
|
||||||
|
local command = helpers.command
|
||||||
|
local meths = helpers.meths
|
||||||
|
local funcs = helpers.funcs
|
||||||
|
local clear = helpers.clear
|
||||||
|
local NIL = helpers.NIL
|
||||||
|
local eq = helpers.eq
|
||||||
|
|
||||||
|
before_each(clear)
|
||||||
|
|
||||||
|
describe('luaeval()', function()
|
||||||
|
describe('second argument', function()
|
||||||
|
it('is successfully received', function()
|
||||||
|
local t = {t=true, f=false, --[[n=NIL,]] d={l={'string', 42, 0.42}}}
|
||||||
|
eq(t, funcs.luaeval("_A", t))
|
||||||
|
-- Not tested: nil, funcrefs, returned object identity: behaviour will
|
||||||
|
-- most likely change.
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
describe('lua values', function()
|
||||||
|
it('are successfully transformed', function()
|
||||||
|
eq({n=1, f=1.5, s='string', l={4, 2}},
|
||||||
|
funcs.luaeval('{n=1, f=1.5, s="string", l={4, 2}}'))
|
||||||
|
-- Not tested: nil inside containers: behaviour will most likely change.
|
||||||
|
eq(NIL, funcs.luaeval('nil'))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
describe('recursive lua values', function()
|
||||||
|
it('are successfully transformed', function()
|
||||||
|
funcs.luaeval('rawset(_G, "d", {})')
|
||||||
|
funcs.luaeval('rawset(d, "d", d)')
|
||||||
|
eq('\n{\'d\': {...@0}}', funcs.execute('echo luaeval("d")'))
|
||||||
|
|
||||||
|
funcs.luaeval('rawset(_G, "l", {})')
|
||||||
|
funcs.luaeval('table.insert(l, l)')
|
||||||
|
eq('\n[[...@0]]', funcs.execute('echo luaeval("l")'))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
describe('strings', function()
|
||||||
|
it('are successfully converted to special dictionaries', function()
|
||||||
|
command([[let s = luaeval('"\0"')]])
|
||||||
|
eq({_TYPE={}, _VAL={'\n'}}, meths.get_var('s'))
|
||||||
|
eq(1, funcs.eval('s._TYPE is v:msgpack_types.binary'))
|
||||||
|
end)
|
||||||
|
it('are successfully converted to special dictionaries in table keys',
|
||||||
|
function()
|
||||||
|
command([[let d = luaeval('{["\0"]=1}')]])
|
||||||
|
eq({_TYPE={}, _VAL={{{_TYPE={}, _VAL={'\n'}}, 1}}}, meths.get_var('d'))
|
||||||
|
eq(1, funcs.eval('d._TYPE is v:msgpack_types.map'))
|
||||||
|
eq(1, funcs.eval('d._VAL[0][0]._TYPE is v:msgpack_types.string'))
|
||||||
|
end)
|
||||||
|
it('are successfully converted to special dictionaries from a list',
|
||||||
|
function()
|
||||||
|
command([[let l = luaeval('{"abc", "a\0b", "c\0d", "def"}')]])
|
||||||
|
eq({'abc', {_TYPE={}, _VAL={'a\nb'}}, {_TYPE={}, _VAL={'c\nd'}}, 'def'},
|
||||||
|
meths.get_var('l'))
|
||||||
|
eq(1, funcs.eval('l[1]._TYPE is v:msgpack_types.binary'))
|
||||||
|
eq(1, funcs.eval('l[2]._TYPE is v:msgpack_types.binary'))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
end)
|
@@ -225,6 +225,14 @@ local function which(exe)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function shallowcopy(orig)
|
||||||
|
local copy = {}
|
||||||
|
for orig_key, orig_value in pairs(orig) do
|
||||||
|
copy[orig_key] = orig_value
|
||||||
|
end
|
||||||
|
return copy
|
||||||
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
eq = eq,
|
eq = eq,
|
||||||
neq = neq,
|
neq = neq,
|
||||||
@@ -238,4 +246,5 @@ return {
|
|||||||
check_cores = check_cores,
|
check_cores = check_cores,
|
||||||
hasenv = hasenv,
|
hasenv = hasenv,
|
||||||
which = which,
|
which = which,
|
||||||
|
shallowcopy = shallowcopy,
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user