aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api/vim_spec.lua
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2024-01-12 12:44:54 +0000
committerLewis Russell <lewis6991@gmail.com>2024-01-12 13:01:06 +0000
commitc30f2e3182e3b50e7c03932027ac55edfc8ada4a (patch)
treeedf0a76dba282d946f67fe70fff8c6cbe28e7a82 /test/functional/api/vim_spec.lua
parent284e0ad26dd9de90c3a813dd1b357a425eca6bad (diff)
downloadrneovim-c30f2e3182e3b50e7c03932027ac55edfc8ada4a.tar.gz
rneovim-c30f2e3182e3b50e7c03932027ac55edfc8ada4a.tar.bz2
rneovim-c30f2e3182e3b50e7c03932027ac55edfc8ada4a.zip
test: typing for helpers.meths
Diffstat (limited to 'test/functional/api/vim_spec.lua')
-rw-r--r--test/functional/api/vim_spec.lua913
1 files changed, 478 insertions, 435 deletions
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index 13b80f4486..3fd1cdab1e 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -70,7 +70,7 @@ describe('API', function()
end)
it('handles errors in async requests', function()
- local error_types = meths.get_api_info()[2].error_types
+ local error_types = meths.nvim_get_api_info()[2].error_types
nvim_async('bogus')
eq({
'notification',
@@ -82,7 +82,7 @@ describe('API', function()
end)
it('failed async request emits nvim_error_event', function()
- local error_types = meths.get_api_info()[2].error_types
+ local error_types = meths.nvim_get_api_info()[2].error_types
nvim_async('command', 'bogus')
eq({
'notification',
@@ -326,7 +326,7 @@ describe('API', function()
write_file(fname, 'echo "hello"\n')
local sourcing_fname = tmpname()
write_file(sourcing_fname, 'call nvim_exec2("source ' .. fname .. '", {"output": v:false})\n')
- meths.exec2('set verbose=2', { output = false })
+ meths.nvim_exec2('set verbose=2', { output = false })
local traceback_output = dedent([[
line 0: sourcing "%s"
line 0: sourcing "%s"
@@ -343,7 +343,7 @@ describe('API', function()
)
eq(
{ output = traceback_output },
- meths.exec2(
+ meths.nvim_exec2(
'call nvim_exec2("source ' .. sourcing_fname .. '", {"output": v:false})',
{ output = true }
)
@@ -367,7 +367,7 @@ describe('API', function()
screen:set_default_attr_ids({
[0] = { bold = true, foreground = Screen.colors.Blue },
})
- meths.exec2("echo 'hello'", { output = false })
+ meths.nvim_exec2("echo 'hello'", { output = false })
screen:expect {
grid = [[
^ |
@@ -383,7 +383,7 @@ describe('API', function()
screen:set_default_attr_ids({
[0] = { bold = true, foreground = Screen.colors.Blue },
})
- meths.exec2("echo 'hello'", { output = true })
+ meths.nvim_exec2("echo 'hello'", { output = true })
screen:expect {
grid = [[
^ |
@@ -694,12 +694,12 @@ describe('API', function()
end)
it('works', function()
- meths.set_current_dir('Xtestdir')
+ meths.nvim_set_current_dir('Xtestdir')
eq(funcs.getcwd(), start_dir .. helpers.get_pathsep() .. 'Xtestdir')
end)
it('sets previous directory', function()
- meths.set_current_dir('Xtestdir')
+ meths.nvim_set_current_dir('Xtestdir')
command('cd -')
eq(funcs.getcwd(), start_dir)
end)
@@ -707,48 +707,51 @@ describe('API', function()
describe('nvim_exec_lua', function()
it('works', function()
- meths.exec_lua('vim.api.nvim_set_var("test", 3)', {})
- eq(3, meths.get_var('test'))
+ meths.nvim_exec_lua('vim.api.nvim_set_var("test", 3)', {})
+ eq(3, meths.nvim_get_var('test'))
- eq(17, meths.exec_lua('a, b = ...\nreturn a + b', { 10, 7 }))
+ eq(17, meths.nvim_exec_lua('a, b = ...\nreturn a + b', { 10, 7 }))
- eq(NIL, meths.exec_lua('function xx(a,b)\nreturn a..b\nend', {}))
- eq('xy', meths.exec_lua('return xx(...)', { 'x', 'y' }))
+ eq(NIL, meths.nvim_exec_lua('function xx(a,b)\nreturn a..b\nend', {}))
+ eq('xy', meths.nvim_exec_lua('return xx(...)', { 'x', 'y' }))
-- Deprecated name: nvim_execute_lua.
- eq('xy', meths.execute_lua('return xx(...)', { 'x', 'y' }))
+ eq('xy', meths.nvim_execute_lua('return xx(...)', { 'x', 'y' }))
end)
it('reports errors', function()
eq(
[[Error loading lua: [string "<nvim>"]:0: '=' expected near '+']],
- pcall_err(meths.exec_lua, 'a+*b', {})
+ pcall_err(meths.nvim_exec_lua, 'a+*b', {})
)
eq(
[[Error loading lua: [string "<nvim>"]:0: unexpected symbol near '1']],
- pcall_err(meths.exec_lua, '1+2', {})
+ pcall_err(meths.nvim_exec_lua, '1+2', {})
)
eq(
[[Error loading lua: [string "<nvim>"]:0: unexpected symbol]],
- pcall_err(meths.exec_lua, 'aa=bb\0', {})
+ pcall_err(meths.nvim_exec_lua, 'aa=bb\0', {})
)
- eq([[attempt to call global 'bork' (a nil value)]], pcall_err(meths.exec_lua, 'bork()', {}))
+ eq(
+ [[attempt to call global 'bork' (a nil value)]],
+ pcall_err(meths.nvim_exec_lua, 'bork()', {})
+ )
- eq('did\nthe\nfail', pcall_err(meths.exec_lua, 'error("did\\nthe\\nfail")', {}))
+ eq('did\nthe\nfail', pcall_err(meths.nvim_exec_lua, 'error("did\\nthe\\nfail")', {}))
end)
it('uses native float values', function()
- eq(2.5, meths.exec_lua('return select(1, ...)', { 2.5 }))
- eq('2.5', meths.exec_lua('return vim.inspect(...)', { 2.5 }))
+ eq(2.5, meths.nvim_exec_lua('return select(1, ...)', { 2.5 }))
+ eq('2.5', meths.nvim_exec_lua('return vim.inspect(...)', { 2.5 }))
-- "special" float values are still accepted as return values.
- eq(2.5, meths.exec_lua("return vim.api.nvim_eval('2.5')", {}))
+ eq(2.5, meths.nvim_exec_lua("return vim.api.nvim_eval('2.5')", {}))
eq(
'{\n [false] = 2.5,\n [true] = 3\n}',
- meths.exec_lua("return vim.inspect(vim.api.nvim_eval('2.5'))", {})
+ meths.nvim_exec_lua("return vim.inspect(vim.api.nvim_eval('2.5'))", {})
)
end)
end)
@@ -760,7 +763,7 @@ describe('API', function()
it('can be overridden', function()
command('lua vim.notify = function(...) return 42 end')
- eq(42, meths.exec_lua("return vim.notify('Hello world')", {}))
+ eq(42, meths.nvim_exec_lua("return vim.notify('Hello world')", {}))
nvim('notify', 'hello world', 4, {})
end)
end)
@@ -1368,7 +1371,7 @@ describe('API', function()
it('allows block width', function()
-- behave consistently with setreg(); support "\022{NUM}" return by getregtype()
- meths.put({ 'line 1', 'line 2', 'line 3' }, 'l', false, false)
+ meths.nvim_put({ 'line 1', 'line 2', 'line 3' }, 'l', false, false)
expect([[
line 1
line 2
@@ -1376,21 +1379,21 @@ describe('API', function()
]])
-- larger width create spaces
- meths.put({ 'a', 'bc' }, 'b3', false, false)
+ meths.nvim_put({ 'a', 'bc' }, 'b3', false, false)
expect([[
a line 1
bc line 2
line 3
]])
-- smaller width is ignored
- meths.put({ 'xxx', 'yyy' }, '\0221', false, true)
+ meths.nvim_put({ 'xxx', 'yyy' }, '\0221', false, true)
expect([[
xxxa line 1
yyybc line 2
line 3
]])
- eq("Invalid 'type': 'bx'", pcall_err(meths.put, { 'xxx', 'yyy' }, 'bx', false, true))
- eq("Invalid 'type': 'b3x'", pcall_err(meths.put, { 'xxx', 'yyy' }, 'b3x', false, true))
+ eq("Invalid 'type': 'bx'", pcall_err(meths.nvim_put, { 'xxx', 'yyy' }, 'bx', false, true))
+ eq("Invalid 'type': 'b3x'", pcall_err(meths.nvim_put, { 'xxx', 'yyy' }, 'b3x', false, true))
end)
end)
@@ -1417,8 +1420,8 @@ describe('API', function()
describe('set/get/del variables', function()
it('validation', function()
- eq('Key not found: bogus', pcall_err(meths.get_var, 'bogus'))
- eq('Key not found: bogus', pcall_err(meths.del_var, 'bogus'))
+ eq('Key not found: bogus', pcall_err(meths.nvim_get_var, 'bogus'))
+ eq('Key not found: bogus', pcall_err(meths.nvim_del_var, 'bogus'))
end)
it('nvim_get_var, nvim_set_var, nvim_del_var', function()
@@ -1426,10 +1429,10 @@ describe('API', function()
eq({ 1, 2, { ['3'] = 1 } }, nvim('get_var', 'lua'))
eq({ 1, 2, { ['3'] = 1 } }, nvim('eval', 'g:lua'))
eq(1, funcs.exists('g:lua'))
- meths.del_var('lua')
+ meths.nvim_del_var('lua')
eq(0, funcs.exists('g:lua'))
- eq('Key not found: lua', pcall_err(meths.del_var, 'lua'))
- meths.set_var('lua', 1)
+ eq('Key not found: lua', pcall_err(meths.nvim_del_var, 'lua'))
+ meths.nvim_set_var('lua', 1)
-- Empty keys are allowed in Vim dicts (and msgpack).
nvim('set_var', 'dict_empty_key', { [''] = 'empty key' })
@@ -1437,8 +1440,8 @@ describe('API', function()
-- Set locked g: var.
command('lockvar lua')
- eq('Key is locked: lua', pcall_err(meths.del_var, 'lua'))
- eq('Key is locked: lua', pcall_err(meths.set_var, 'lua', 1))
+ eq('Key is locked: lua', pcall_err(meths.nvim_del_var, 'lua'))
+ eq('Key is locked: lua', pcall_err(meths.nvim_set_var, 'lua', 1))
exec([[
function Test()
@@ -1448,8 +1451,8 @@ describe('API', function()
let g:Unknown_func = function('Test')
let g:Unknown_script_func = function('s:Test')
]])
- eq(NIL, meths.get_var('Unknown_func'))
- eq(NIL, meths.get_var('Unknown_script_func'))
+ eq(NIL, meths.nvim_get_var('Unknown_func'))
+ eq(NIL, meths.nvim_get_var('Unknown_script_func'))
-- Check if autoload works properly
local pathsep = helpers.get_pathsep()
@@ -1461,37 +1464,40 @@ describe('API', function()
write_file(autoload_file, [[let testload#value = 2]])
clear { args_rm = { '-u' }, env = { XDG_CONFIG_HOME = xconfig, XDG_DATA_HOME = xdata } }
- eq(2, meths.get_var('testload#value'))
+ eq(2, meths.nvim_get_var('testload#value'))
rmdir('Xhome')
end)
it('nvim_get_vvar, nvim_set_vvar', function()
eq('Key is read-only: count', pcall_err(request, 'nvim_set_vvar', 'count', 42))
eq('Dictionary is locked', pcall_err(request, 'nvim_set_vvar', 'nosuchvar', 42))
- meths.set_vvar('errmsg', 'set by API')
- eq('set by API', meths.get_vvar('errmsg'))
- meths.set_vvar('errmsg', 42)
+ meths.nvim_set_vvar('errmsg', 'set by API')
+ eq('set by API', meths.nvim_get_vvar('errmsg'))
+ meths.nvim_set_vvar('errmsg', 42)
eq('42', eval('v:errmsg'))
- meths.set_vvar('oldfiles', { 'one', 'two' })
+ meths.nvim_set_vvar('oldfiles', { 'one', 'two' })
eq({ 'one', 'two' }, eval('v:oldfiles'))
- meths.set_vvar('oldfiles', {})
+ meths.nvim_set_vvar('oldfiles', {})
eq({}, eval('v:oldfiles'))
- eq('Setting v:oldfiles to value with wrong type', pcall_err(meths.set_vvar, 'oldfiles', 'a'))
+ eq(
+ 'Setting v:oldfiles to value with wrong type',
+ pcall_err(meths.nvim_set_vvar, 'oldfiles', 'a')
+ )
eq({}, eval('v:oldfiles'))
feed('i foo foo foo<Esc>0/foo<CR>')
- eq({ 1, 1 }, meths.win_get_cursor(0))
+ eq({ 1, 1 }, meths.nvim_win_get_cursor(0))
eq(1, eval('v:searchforward'))
feed('n')
- eq({ 1, 5 }, meths.win_get_cursor(0))
- meths.set_vvar('searchforward', 0)
+ eq({ 1, 5 }, meths.nvim_win_get_cursor(0))
+ meths.nvim_set_vvar('searchforward', 0)
eq(0, eval('v:searchforward'))
feed('n')
- eq({ 1, 1 }, meths.win_get_cursor(0))
- meths.set_vvar('searchforward', 1)
+ eq({ 1, 1 }, meths.nvim_win_get_cursor(0))
+ meths.nvim_set_vvar('searchforward', 1)
eq(1, eval('v:searchforward'))
feed('n')
- eq({ 1, 5 }, meths.win_get_cursor(0))
+ eq({ 1, 5 }, meths.nvim_win_get_cursor(0))
local screen = Screen.new(60, 3)
screen:set_default_attr_ids({
@@ -1507,7 +1513,7 @@ describe('API', function()
|
]],
}
- meths.set_vvar('hlsearch', 0)
+ meths.nvim_set_vvar('hlsearch', 0)
eq(0, eval('v:hlsearch'))
screen:expect {
grid = [[
@@ -1516,7 +1522,7 @@ describe('API', function()
|
]],
}
- meths.set_vvar('hlsearch', 1)
+ meths.nvim_set_vvar('hlsearch', 1)
eq(1, eval('v:hlsearch'))
screen:expect {
grid = [[
@@ -1900,7 +1906,7 @@ describe('API', function()
1,
},
NIL,
- }, meths.call_atomic(req))
+ }, meths.nvim_call_atomic(req))
eq({ mode = 'r', blocking = true }, nvim('get_mode'))
end)
it('during insert-mode map-pending, returns blocking=true #6166', function()
@@ -2004,24 +2010,24 @@ describe('API', function()
it('does not interrupt Insert mode i_CTRL-O #10035', function()
feed('iHello World<c-o>')
- eq({ mode = 'niI', blocking = false }, meths.get_mode()) -- fast event
+ eq({ mode = 'niI', blocking = false }, meths.nvim_get_mode()) -- fast event
eq(2, eval('1+1')) -- causes K_EVENT key
- eq({ mode = 'niI', blocking = false }, meths.get_mode()) -- still in ctrl-o mode
+ eq({ mode = 'niI', blocking = false }, meths.nvim_get_mode()) -- still in ctrl-o mode
feed('dd')
- eq({ mode = 'i', blocking = false }, meths.get_mode()) -- left ctrl-o mode
+ eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) -- left ctrl-o mode
expect('') -- executed the command
end)
it('does not interrupt Select mode v_CTRL-O #15688', function()
feed('iHello World<esc>gh<c-o>')
- eq({ mode = 'vs', blocking = false }, meths.get_mode()) -- fast event
- eq({ mode = 'vs', blocking = false }, meths.get_mode()) -- again #15288
+ eq({ mode = 'vs', blocking = false }, meths.nvim_get_mode()) -- fast event
+ eq({ mode = 'vs', blocking = false }, meths.nvim_get_mode()) -- again #15288
eq(2, eval('1+1')) -- causes K_EVENT key
- eq({ mode = 'vs', blocking = false }, meths.get_mode()) -- still in ctrl-o mode
+ eq({ mode = 'vs', blocking = false }, meths.nvim_get_mode()) -- still in ctrl-o mode
feed('^')
- eq({ mode = 's', blocking = false }, meths.get_mode()) -- left ctrl-o mode
+ eq({ mode = 's', blocking = false }, meths.nvim_get_mode()) -- left ctrl-o mode
feed('h')
- eq({ mode = 'i', blocking = false }, meths.get_mode()) -- entered insert mode
+ eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) -- entered insert mode
expect('h') -- selection is the whole line and is replaced
end)
@@ -2176,13 +2182,13 @@ describe('API', function()
-- then `return str` in vim_replace_termcodes body will make Neovim free
-- `str.data` twice: once when freeing arguments, then when freeing return
-- value.
- eq('', meths.replace_termcodes('', true, true, true))
+ eq('', meths.nvim_replace_termcodes('', true, true, true))
end)
-- Not exactly the case, as nvim_replace_termcodes() escapes K_SPECIAL in Unicode
it('translates the result of keytrans() on string with 0x80 byte back', function()
local s = 'ff\128\253\097tt'
- eq(s, meths.replace_termcodes(funcs.keytrans(s), true, true, true))
+ eq(s, meths.nvim_replace_termcodes(funcs.keytrans(s), true, true, true))
end)
end)
@@ -2244,7 +2250,7 @@ describe('API', function()
silent! call nvim_out_write("\n")
redir END
]])
- eq('\naaa\n' .. ('a'):rep(5002) .. '\naaa', meths.get_var('out'))
+ eq('\naaa\n' .. ('a'):rep(5002) .. '\naaa', meths.nvim_get_var('out'))
end)
it('blank line in message', function()
@@ -2430,18 +2436,18 @@ describe('API', function()
}
it('returns {} for invalid channel', function()
- eq({}, meths.get_chan_info(0))
- eq({}, meths.get_chan_info(-1))
+ eq({}, meths.nvim_get_chan_info(0))
+ eq({}, meths.nvim_get_chan_info(-1))
-- more preallocated numbers might be added, try something high
- eq({}, meths.get_chan_info(10))
+ eq({}, meths.nvim_get_chan_info(10))
end)
it('stream=stdio channel', function()
- eq({ [1] = testinfo, [2] = stderr }, meths.list_chans())
- eq(testinfo, meths.get_chan_info(1))
- eq(stderr, meths.get_chan_info(2))
+ eq({ [1] = testinfo, [2] = stderr }, meths.nvim_list_chans())
+ eq(testinfo, meths.nvim_get_chan_info(1))
+ eq(stderr, meths.nvim_get_chan_info(2))
- meths.set_client_info(
+ meths.nvim_set_client_info(
'functionaltests',
{ major = 0, minor = 3, patch = 17 },
'ui',
@@ -2460,9 +2466,9 @@ describe('API', function()
attributes = { license = 'Apache2' },
},
}
- eq({ info = info }, meths.get_var('info_event'))
- eq({ [1] = info, [2] = stderr }, meths.list_chans())
- eq(info, meths.get_chan_info(1))
+ eq({ info = info }, meths.nvim_get_var('info_event'))
+ eq({ [1] = info, [2] = stderr }, meths.nvim_list_chans())
+ eq(info, meths.nvim_get_chan_info(1))
end)
it('stream=job channel', function()
@@ -2475,9 +2481,9 @@ describe('API', function()
mode = 'rpc',
client = {},
}
- eq({ info = info }, meths.get_var('opened_event'))
- eq({ [1] = testinfo, [2] = stderr, [3] = info }, meths.list_chans())
- eq(info, meths.get_chan_info(3))
+ eq({ info = info }, meths.nvim_get_var('opened_event'))
+ eq({ [1] = testinfo, [2] = stderr, [3] = info }, meths.nvim_list_chans())
+ eq(info, meths.nvim_get_chan_info(3))
eval(
'rpcrequest(3, "nvim_set_client_info", "amazing-cat", {}, "remote",'
.. '{"nvim_command":{"n_args":1}},' -- and so on
@@ -2496,8 +2502,8 @@ describe('API', function()
attributes = { description = 'The Amazing Cat' },
},
}
- eq({ info = info }, meths.get_var('info_event'))
- eq({ [1] = testinfo, [2] = stderr, [3] = info }, meths.list_chans())
+ eq({ info = info }, meths.nvim_get_var('info_event'))
+ eq({ [1] = testinfo, [2] = stderr, [3] = info }, meths.nvim_list_chans())
eq(
"Vim:Error invoking 'nvim_set_current_buf' on channel 3 (amazing-cat):\nWrong type for argument 1 when calling nvim_set_current_buf, expecting Buffer",
@@ -2507,8 +2513,8 @@ describe('API', function()
it('stream=job :terminal channel', function()
command(':terminal')
- eq({ id = 1 }, meths.get_current_buf())
- eq(3, meths.get_option_value('channel', { buf = 1 }))
+ eq({ id = 1 }, meths.nvim_get_current_buf())
+ eq(3, meths.nvim_get_option_value('channel', { buf = 1 }))
local info = {
stream = 'job',
@@ -2518,15 +2524,15 @@ describe('API', function()
buffer = 1,
pty = '?',
}
- local event = meths.get_var('opened_event')
+ local event = meths.nvim_get_var('opened_event')
if not is_os('win') then
info.pty = event.info.pty
neq(nil, string.match(info.pty, '^/dev/'))
end
eq({ info = info }, event)
info.buffer = { id = 1 }
- eq({ [1] = testinfo, [2] = stderr, [3] = info }, meths.list_chans())
- eq(info, meths.get_chan_info(3))
+ eq({ [1] = testinfo, [2] = stderr, [3] = info }, meths.nvim_list_chans())
+ eq(info, meths.nvim_get_chan_info(3))
-- :terminal with args + running process.
command('enew')
@@ -2566,13 +2572,13 @@ describe('API', function()
describe('nvim_call_atomic', function()
it('works', function()
- meths.buf_set_lines(0, 0, -1, true, { 'first' })
+ meths.nvim_buf_set_lines(0, 0, -1, true, { 'first' })
local req = {
{ 'nvim_get_current_line', {} },
{ 'nvim_set_current_line', { 'second' } },
}
- eq({ { 'first', NIL }, NIL }, meths.call_atomic(req))
- eq({ 'second' }, meths.buf_get_lines(0, 0, -1, true))
+ eq({ { 'first', NIL }, NIL }, meths.nvim_call_atomic(req))
+ eq({ 'second' }, meths.nvim_buf_get_lines(0, 0, -1, true))
end)
it('allows multiple return values', function()
@@ -2582,11 +2588,11 @@ describe('API', function()
{ 'nvim_get_var', { 'avar' } },
{ 'nvim_get_var', { 'bvar' } },
}
- eq({ { NIL, NIL, true, 'string' }, NIL }, meths.call_atomic(req))
+ eq({ { NIL, NIL, true, 'string' }, NIL }, meths.nvim_call_atomic(req))
end)
it('is aborted by errors in call', function()
- local error_types = meths.get_api_info()[2].error_types
+ local error_types = meths.nvim_get_api_info()[2].error_types
local req = {
{ 'nvim_set_var', { 'one', 1 } },
{ 'nvim_buf_set_lines', {} },
@@ -2599,9 +2605,9 @@ describe('API', function()
error_types.Exception.id,
'Wrong number of arguments: expecting 5 but got 0',
},
- }, meths.call_atomic(req))
- eq(1, meths.get_var('one'))
- eq(false, pcall(meths.get_var, 'two'))
+ }, meths.nvim_call_atomic(req))
+ eq(1, meths.nvim_get_var('one'))
+ eq(false, pcall(meths.nvim_get_var, 'two'))
-- still returns all previous successful calls
req = {
@@ -2613,7 +2619,7 @@ describe('API', function()
}
eq(
{ { NIL, NIL, 5 }, { 3, error_types.Validation.id, 'Index out of bounds' } },
- meths.call_atomic(req)
+ meths.nvim_call_atomic(req)
)
req = {
@@ -2622,9 +2628,9 @@ describe('API', function()
}
eq(
{ {}, { 0, error_types.Exception.id, 'Invalid method: i_am_not_a_method' } },
- meths.call_atomic(req)
+ meths.nvim_call_atomic(req)
)
- eq(5, meths.get_var('avar'))
+ eq(5, meths.nvim_get_var('avar'))
end)
it('validation', function()
@@ -2633,25 +2639,28 @@ describe('API', function()
{ 'nvim_set_var' },
{ 'nvim_set_var', { 'avar', 2 } },
}
- eq("Invalid 'calls' item: expected 2-item Array", pcall_err(meths.call_atomic, req))
+ eq("Invalid 'calls' item: expected 2-item Array", pcall_err(meths.nvim_call_atomic, req))
-- call before was done, but not after
- eq(1, meths.get_var('avar'))
+ eq(1, meths.nvim_get_var('avar'))
req = {
{ 'nvim_set_var', { 'bvar', { 2, 3 } } },
12,
}
- eq("Invalid 'calls' item: expected Array, got Integer", pcall_err(meths.call_atomic, req))
- eq({ 2, 3 }, meths.get_var('bvar'))
+ eq(
+ "Invalid 'calls' item: expected Array, got Integer",
+ pcall_err(meths.nvim_call_atomic, req)
+ )
+ eq({ 2, 3 }, meths.nvim_get_var('bvar'))
req = {
{ 'nvim_set_current_line', 'little line' },
{ 'nvim_set_var', { 'avar', 3 } },
}
- eq('Invalid call args: expected Array, got String', pcall_err(meths.call_atomic, req))
+ eq('Invalid call args: expected Array, got String', pcall_err(meths.nvim_call_atomic, req))
-- call before was done, but not after
- eq(1, meths.get_var('avar'))
- eq({ '' }, meths.buf_get_lines(0, 0, -1, true))
+ eq(1, meths.nvim_get_var('avar'))
+ eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, true))
end)
end)
@@ -2665,36 +2674,36 @@ describe('API', function()
rmdir 'Xtest'
end)
before_each(function()
- meths.set_current_dir 'Xtest'
+ meths.nvim_set_current_dir 'Xtest'
end)
it('returns nothing with empty &runtimepath', function()
- meths.set_option_value('runtimepath', '', {})
- eq({}, meths.list_runtime_paths())
+ meths.nvim_set_option_value('runtimepath', '', {})
+ eq({}, meths.nvim_list_runtime_paths())
end)
it('returns single runtimepath', function()
- meths.set_option_value('runtimepath', 'a', {})
- eq({ 'a' }, meths.list_runtime_paths())
+ meths.nvim_set_option_value('runtimepath', 'a', {})
+ eq({ 'a' }, meths.nvim_list_runtime_paths())
end)
it('returns two runtimepaths', function()
- meths.set_option_value('runtimepath', 'a,b', {})
- eq({ 'a', 'b' }, meths.list_runtime_paths())
+ meths.nvim_set_option_value('runtimepath', 'a,b', {})
+ eq({ 'a', 'b' }, meths.nvim_list_runtime_paths())
end)
it('returns empty strings when appropriate', function()
- meths.set_option_value('runtimepath', 'a,,b', {})
- eq({ 'a', '', 'b' }, meths.list_runtime_paths())
- meths.set_option_value('runtimepath', ',a,b', {})
- eq({ '', 'a', 'b' }, meths.list_runtime_paths())
+ meths.nvim_set_option_value('runtimepath', 'a,,b', {})
+ eq({ 'a', '', 'b' }, meths.nvim_list_runtime_paths())
+ meths.nvim_set_option_value('runtimepath', ',a,b', {})
+ eq({ '', 'a', 'b' }, meths.nvim_list_runtime_paths())
-- Trailing "," is ignored. Use ",," if you really really want CWD.
- meths.set_option_value('runtimepath', 'a,b,', {})
- eq({ 'a', 'b' }, meths.list_runtime_paths())
- meths.set_option_value('runtimepath', 'a,b,,', {})
- eq({ 'a', 'b', '' }, meths.list_runtime_paths())
+ meths.nvim_set_option_value('runtimepath', 'a,b,', {})
+ eq({ 'a', 'b' }, meths.nvim_list_runtime_paths())
+ meths.nvim_set_option_value('runtimepath', 'a,b,,', {})
+ eq({ 'a', 'b', '' }, meths.nvim_list_runtime_paths())
end)
it('truncates too long paths', function()
local long_path = ('/a'):rep(8192)
- meths.set_option_value('runtimepath', long_path, {})
- local paths_list = meths.list_runtime_paths()
+ meths.nvim_set_option_value('runtimepath', long_path, {})
+ local paths_list = meths.nvim_list_runtime_paths()
eq({}, paths_list)
end)
end)
@@ -2723,7 +2732,7 @@ describe('API', function()
describe('nvim_parse_expression', function()
before_each(function()
- meths.set_option_value('isident', '', {})
+ meths.nvim_set_option_value('isident', '', {})
end)
local function simplify_east_api_node(line, east_api_node)
@@ -2856,7 +2865,7 @@ describe('API', function()
nz_flags_exps = nz_flags_exps or {}
for _, flags in ipairs(opts.flags) do
local err, msg = pcall(function()
- local east_api = meths.parse_expression(str, FLAGS_TO_STR[flags], true)
+ local east_api = meths.nvim_parse_expression(str, FLAGS_TO_STR[flags], true)
local east_hl = east_api.highlight
east_api.highlight = nil
local ast = simplify_east_api(str, east_api)
@@ -2980,33 +2989,33 @@ describe('API', function()
describe('nvim_create_namespace', function()
it('works', function()
- eq({}, meths.get_namespaces())
- eq(1, meths.create_namespace('ns-1'))
- eq(2, meths.create_namespace('ns-2'))
- eq(1, meths.create_namespace('ns-1'))
- eq({ ['ns-1'] = 1, ['ns-2'] = 2 }, meths.get_namespaces())
- eq(3, meths.create_namespace(''))
- eq(4, meths.create_namespace(''))
- eq({ ['ns-1'] = 1, ['ns-2'] = 2 }, meths.get_namespaces())
+ eq({}, meths.nvim_get_namespaces())
+ eq(1, meths.nvim_create_namespace('ns-1'))
+ eq(2, meths.nvim_create_namespace('ns-2'))
+ eq(1, meths.nvim_create_namespace('ns-1'))
+ eq({ ['ns-1'] = 1, ['ns-2'] = 2 }, meths.nvim_get_namespaces())
+ eq(3, meths.nvim_create_namespace(''))
+ eq(4, meths.nvim_create_namespace(''))
+ eq({ ['ns-1'] = 1, ['ns-2'] = 2 }, meths.nvim_get_namespaces())
end)
end)
describe('nvim_create_buf', function()
it('works', function()
- eq({ id = 2 }, meths.create_buf(true, false))
- eq({ id = 3 }, meths.create_buf(false, false))
+ eq({ id = 2 }, meths.nvim_create_buf(true, false))
+ eq({ id = 3 }, meths.nvim_create_buf(false, false))
eq(
' 1 %a "[No Name]" line 1\n'
.. ' 2 h "[No Name]" line 0',
- meths.command_output('ls')
+ meths.nvim_command_output('ls')
)
-- current buffer didn't change
- eq({ id = 1 }, meths.get_current_buf())
+ eq({ id = 1 }, meths.nvim_get_current_buf())
local screen = Screen.new(20, 4)
screen:attach()
- meths.buf_set_lines(2, 0, -1, true, { 'some text' })
- meths.set_current_buf(2)
+ meths.nvim_buf_set_lines(2, 0, -1, true, { 'some text' })
+ meths.nvim_set_current_buf(2)
screen:expect(
[[
^some text |
@@ -3020,43 +3029,43 @@ describe('API', function()
end)
it('can change buftype before visiting', function()
- meths.set_option_value('hidden', false, {})
- eq({ id = 2 }, meths.create_buf(true, false))
- meths.set_option_value('buftype', 'nofile', { buf = 2 })
- meths.buf_set_lines(2, 0, -1, true, { 'test text' })
+ meths.nvim_set_option_value('hidden', false, {})
+ eq({ id = 2 }, meths.nvim_create_buf(true, false))
+ meths.nvim_set_option_value('buftype', 'nofile', { buf = 2 })
+ meths.nvim_buf_set_lines(2, 0, -1, true, { 'test text' })
command('split | buffer 2')
- eq({ id = 2 }, meths.get_current_buf())
+ eq({ id = 2 }, meths.nvim_get_current_buf())
-- if the buf_set_option("buftype") didn't work, this would error out.
command('close')
- eq({ id = 1 }, meths.get_current_buf())
+ eq({ id = 1 }, meths.nvim_get_current_buf())
end)
it('does not trigger BufEnter, BufWinEnter', function()
command('let g:fired = v:false')
command('au BufEnter,BufWinEnter * let g:fired = v:true')
- eq({ id = 2 }, meths.create_buf(true, false))
- meths.buf_set_lines(2, 0, -1, true, { 'test', 'text' })
+ eq({ id = 2 }, meths.nvim_create_buf(true, false))
+ meths.nvim_buf_set_lines(2, 0, -1, true, { 'test', 'text' })
eq(false, eval('g:fired'))
end)
it('TextChanged and TextChangedI do not trigger without changes', function()
- local buf = meths.create_buf(true, false)
+ local buf = meths.nvim_create_buf(true, false)
command([[let g:changed = '']])
- meths.create_autocmd({ 'TextChanged', 'TextChangedI' }, {
+ meths.nvim_create_autocmd({ 'TextChanged', 'TextChangedI' }, {
buffer = buf,
command = 'let g:changed ..= mode()',
})
- meths.set_current_buf(buf)
+ meths.nvim_set_current_buf(buf)
feed('i')
- eq('', meths.get_var('changed'))
+ eq('', meths.nvim_get_var('changed'))
end)
it('scratch-buffer', function()
- eq({ id = 2 }, meths.create_buf(false, true))
- eq({ id = 3 }, meths.create_buf(true, true))
- eq({ id = 4 }, meths.create_buf(true, true))
+ eq({ id = 2 }, meths.nvim_create_buf(false, true))
+ eq({ id = 3 }, meths.nvim_create_buf(true, true))
+ eq({ id = 4 }, meths.nvim_create_buf(true, true))
local scratch_bufs = { 2, 3, 4 }
eq(
' 1 %a "[No Name]" line 1\n'
@@ -3065,7 +3074,7 @@ describe('API', function()
exec_capture('ls')
)
-- current buffer didn't change
- eq({ id = 1 }, meths.get_current_buf())
+ eq({ id = 1 }, meths.nvim_get_current_buf())
local screen = Screen.new(20, 4)
screen:set_default_attr_ids({
@@ -3077,27 +3086,27 @@ describe('API', function()
-- Editing a scratch-buffer does NOT change its properties.
--
local edited_buf = 2
- meths.buf_set_lines(edited_buf, 0, -1, true, { 'some text' })
+ meths.nvim_buf_set_lines(edited_buf, 0, -1, true, { 'some text' })
for _, b in ipairs(scratch_bufs) do
- eq('nofile', meths.get_option_value('buftype', { buf = b }))
- eq('hide', meths.get_option_value('bufhidden', { buf = b }))
- eq(false, meths.get_option_value('swapfile', { buf = b }))
- eq(false, meths.get_option_value('modeline', { buf = b }))
+ eq('nofile', meths.nvim_get_option_value('buftype', { buf = b }))
+ eq('hide', meths.nvim_get_option_value('bufhidden', { buf = b }))
+ eq(false, meths.nvim_get_option_value('swapfile', { buf = b }))
+ eq(false, meths.nvim_get_option_value('modeline', { buf = b }))
end
--
-- Visiting a scratch-buffer DOES NOT change its properties.
--
- meths.set_current_buf(edited_buf)
+ meths.nvim_set_current_buf(edited_buf)
screen:expect([[
^some text |
{1:~ }|*2
|
]])
- eq('nofile', meths.get_option_value('buftype', { buf = edited_buf }))
- eq('hide', meths.get_option_value('bufhidden', { buf = edited_buf }))
- eq(false, meths.get_option_value('swapfile', { buf = edited_buf }))
- eq(false, meths.get_option_value('modeline', { buf = edited_buf }))
+ eq('nofile', meths.nvim_get_option_value('buftype', { buf = edited_buf }))
+ eq('hide', meths.nvim_get_option_value('bufhidden', { buf = edited_buf }))
+ eq(false, meths.nvim_get_option_value('swapfile', { buf = edited_buf }))
+ eq(false, meths.nvim_get_option_value('modeline', { buf = edited_buf }))
-- Scratch buffer can be wiped without error.
command('bwipe')
@@ -3119,11 +3128,11 @@ describe('API', function()
describe('nvim_get_runtime_file', function()
local p = helpers.alter_slashes
it('can find files', function()
- eq({}, meths.get_runtime_file('bork.borkbork', false))
- eq({}, meths.get_runtime_file('bork.borkbork', true))
- eq(1, #meths.get_runtime_file('autoload/msgpack.vim', false))
- eq(1, #meths.get_runtime_file('autoload/msgpack.vim', true))
- local val = meths.get_runtime_file('autoload/remote/*.vim', true)
+ eq({}, meths.nvim_get_runtime_file('bork.borkbork', false))
+ eq({}, meths.nvim_get_runtime_file('bork.borkbork', true))
+ eq(1, #meths.nvim_get_runtime_file('autoload/msgpack.vim', false))
+ eq(1, #meths.nvim_get_runtime_file('autoload/msgpack.vim', true))
+ local val = meths.nvim_get_runtime_file('autoload/remote/*.vim', true)
eq(2, #val)
if endswith(val[1], 'define.vim') then
ok(endswith(val[1], p 'autoload/remote/define.vim'))
@@ -3132,37 +3141,37 @@ describe('API', function()
ok(endswith(val[1], p 'autoload/remote/host.vim'))
ok(endswith(val[2], p 'autoload/remote/define.vim'))
end
- val = meths.get_runtime_file('autoload/remote/*.vim', false)
+ val = meths.nvim_get_runtime_file('autoload/remote/*.vim', false)
eq(1, #val)
ok(
endswith(val[1], p 'autoload/remote/define.vim')
or endswith(val[1], p 'autoload/remote/host.vim')
)
- val = meths.get_runtime_file('lua', true)
+ val = meths.nvim_get_runtime_file('lua', true)
eq(1, #val)
ok(endswith(val[1], p 'lua'))
- val = meths.get_runtime_file('lua/vim', true)
+ val = meths.nvim_get_runtime_file('lua/vim', true)
eq(1, #val)
ok(endswith(val[1], p 'lua/vim'))
end)
it('can find directories', function()
- local val = meths.get_runtime_file('lua/', true)
+ local val = meths.nvim_get_runtime_file('lua/', true)
eq(1, #val)
ok(endswith(val[1], p 'lua/'))
- val = meths.get_runtime_file('lua/vim/', true)
+ val = meths.nvim_get_runtime_file('lua/vim/', true)
eq(1, #val)
ok(endswith(val[1], p 'lua/vim/'))
- eq({}, meths.get_runtime_file('foobarlang/', true))
+ eq({}, meths.nvim_get_runtime_file('foobarlang/', true))
end)
it('can handle bad patterns', function()
skip(is_os('win'))
- eq('Vim:E220: Missing }.', pcall_err(meths.get_runtime_file, '{', false))
+ eq('Vim:E220: Missing }.', pcall_err(meths.nvim_get_runtime_file, '{', false))
eq(
'Vim(echo):E5555: API call: Vim:E220: Missing }.',
@@ -3173,25 +3182,25 @@ describe('API', function()
describe('nvim_get_all_options_info', function()
it('should have key value pairs of option names', function()
- local options_info = meths.get_all_options_info()
+ local options_info = meths.nvim_get_all_options_info()
neq(nil, options_info.listchars)
neq(nil, options_info.tabstop)
- eq(meths.get_option_info 'winhighlight', options_info.winhighlight)
+ eq(meths.nvim_get_option_info 'winhighlight', options_info.winhighlight)
end)
it('should not crash when echoed', function()
- meths.exec2('echo nvim_get_all_options_info()', { output = true })
+ meths.nvim_exec2('echo nvim_get_all_options_info()', { output = true })
end)
end)
describe('nvim_get_option_info', function()
it('should error for unknown options', function()
- eq("Invalid option (not found): 'bogus'", pcall_err(meths.get_option_info, 'bogus'))
+ eq("Invalid option (not found): 'bogus'", pcall_err(meths.nvim_get_option_info, 'bogus'))
end)
it('should return the same options for short and long name', function()
- eq(meths.get_option_info 'winhl', meths.get_option_info 'winhighlight')
+ eq(meths.nvim_get_option_info 'winhl', meths.nvim_get_option_info 'winhighlight')
end)
it('should have information about window options', function()
@@ -3209,7 +3218,7 @@ describe('API', function()
shortname = 'winhl',
type = 'string',
was_set = false,
- }, meths.get_option_info 'winhl')
+ }, meths.nvim_get_option_info 'winhl')
end)
it('should have information about buffer options', function()
@@ -3227,13 +3236,13 @@ describe('API', function()
shortname = 'ft',
type = 'string',