aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api/vim_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/api/vim_spec.lua')
-rw-r--r--test/functional/api/vim_spec.lua2585
1 files changed, 1460 insertions, 1125 deletions
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index 104ffd7d6c..ce2838879b 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -3,6 +3,7 @@ local Screen = require('test.functional.ui.screen')
local luv = require('luv')
local fmt = string.format
+local dedent = helpers.dedent
local assert_alive = helpers.assert_alive
local NIL = helpers.NIL
local clear, nvim, eq, neq = helpers.clear, helpers.nvim, helpers.eq, helpers.neq
@@ -41,32 +42,41 @@ describe('API', function()
it('validates requests', function()
-- RPC
- matches('Invalid method: bogus$',
- pcall_err(request, 'bogus'))
- matches('Invalid method: … の り 。…$',
- pcall_err(request, '… の り 。…'))
- matches('Invalid method: <empty>$',
- pcall_err(request, ''))
+ matches('Invalid method: bogus$', pcall_err(request, 'bogus'))
+ matches('Invalid method: … の り 。…$', pcall_err(request, '… の り 。…'))
+ matches('Invalid method: <empty>$', pcall_err(request, ''))
-- Non-RPC: rpcrequest(v:servername) uses internal channel.
- matches('Invalid method: … の り 。…$',
- pcall_err(request, 'nvim_eval',
- [=[rpcrequest(sockconnect('pipe', v:servername, {'rpc':1}), '… の り 。…')]=]))
- matches('Invalid method: bogus$',
- pcall_err(request, 'nvim_eval',
- [=[rpcrequest(sockconnect('pipe', v:servername, {'rpc':1}), 'bogus')]=]))
+ matches(
+ 'Invalid method: … の り 。…$',
+ pcall_err(
+ request,
+ 'nvim_eval',
+ [=[rpcrequest(sockconnect('pipe', v:servername, {'rpc':1}), '… の り 。…')]=]
+ )
+ )
+ matches(
+ 'Invalid method: bogus$',
+ pcall_err(
+ request,
+ 'nvim_eval',
+ [=[rpcrequest(sockconnect('pipe', v:servername, {'rpc':1}), 'bogus')]=]
+ )
+ )
-- XXX: This must be the last one, else next one will fail:
-- "Packer instance already working. Use another Packer ..."
- matches("can't serialize object of type .$",
- pcall_err(request, nil))
+ matches("can't serialize object of type .$", pcall_err(request, nil))
end)
it('handles errors in async requests', function()
local error_types = meths.get_api_info()[2].error_types
nvim_async('bogus')
- eq({'notification', 'nvim_error_event',
- {error_types.Exception.id, 'Invalid method: nvim_bogus'}}, next_msg())
+ eq({
+ 'notification',
+ 'nvim_error_event',
+ { error_types.Exception.id, 'Invalid method: nvim_bogus' },
+ }, next_msg())
-- error didn't close channel.
assert_alive()
end)
@@ -74,9 +84,11 @@ describe('API', function()
it('failed async request emits nvim_error_event', function()
local error_types = meths.get_api_info()[2].error_types
nvim_async('command', 'bogus')
- eq({'notification', 'nvim_error_event',
- {error_types.Exception.id, 'Vim:E492: Not an editor command: bogus'}},
- next_msg())
+ eq({
+ 'notification',
+ 'nvim_error_event',
+ { error_types.Exception.id, 'Vim:E492: Not an editor command: bogus' },
+ }, next_msg())
-- error didn't close channel.
assert_alive()
end)
@@ -85,7 +97,7 @@ describe('API', function()
nvim('command', 'split')
nvim('command', 'autocmd WinEnter * startinsert')
nvim('command', 'wincmd w')
- eq({mode='i', blocking=false}, nvim("get_mode"))
+ eq({ mode = 'i', blocking = false }, nvim('get_mode'))
end)
describe('nvim_exec2', function()
@@ -109,23 +121,31 @@ describe('API', function()
it(':verbose set {option}?', function()
nvim('exec2', 'set nowrap', { output = false })
- eq({ output = 'nowrap\n\tLast set from anonymous :source' },
- nvim('exec2', 'verbose set wrap?', { output = true }))
+ eq(
+ { output = 'nowrap\n\tLast set from anonymous :source' },
+ nvim('exec2', 'verbose set wrap?', { output = true })
+ )
-- Using script var to force creation of a script item
- nvim('exec2', [[
+ nvim(
+ 'exec2',
+ [[
let s:a = 1
set nowrap
- ]], { output = false })
- eq({ output = 'nowrap\n\tLast set from anonymous :source (script id 1)' },
- nvim('exec2', 'verbose set wrap?', { output = true }))
+ ]],
+ { output = false }
+ )
+ eq(
+ { output = 'nowrap\n\tLast set from anonymous :source (script id 1)' },
+ nvim('exec2', 'verbose set wrap?', { output = true })
+ )
end)
it('multiline input', function()
-- Heredoc + empty lines.
nvim('exec2', "let x2 = 'a'\n", { output = false })
eq('a', nvim('get_var', 'x2'))
- nvim('exec2','lua <<EOF\n\n\n\ny=3\n\n\nEOF', { output = false })
+ nvim('exec2', 'lua <<EOF\n\n\n\ny=3\n\n\nEOF', { output = false })
eq(3, nvim('eval', "luaeval('y')"))
eq({}, nvim('exec2', 'lua <<EOF\ny=3\nEOF', { output = false }))
@@ -144,90 +164,141 @@ describe('API', function()
eq('xxx', nvim('get_current_line'))
-- Autocmds
- nvim('exec2','autocmd BufAdd * :let x1 = "Hello"', { output = false })
+ nvim('exec2', 'autocmd BufAdd * :let x1 = "Hello"', { output = false })
nvim('command', 'new foo')
eq('Hello', request('nvim_eval', 'g:x1'))
-- Line continuations
- nvim('exec2', [[
+ nvim(
+ 'exec2',
+ [[
let abc = #{
\ a: 1,
"\ b: 2,
\ c: 3
- \ }]], { output = false })
- eq({a = 1, c = 3}, request('nvim_eval', 'g:abc'))
+ \ }]],
+ { output = false }
+ )
+ eq({ a = 1, c = 3 }, request('nvim_eval', 'g:abc'))
-- try no spaces before continuations to catch off-by-one error
nvim('exec2', 'let ab = #{\n\\a: 98,\n"\\ b: 2\n\\}', { output = false })
- eq({a = 98}, request('nvim_eval', 'g:ab'))
+ eq({ a = 98 }, request('nvim_eval', 'g:ab'))
-- Script scope (s:)
- eq({ output = 'ahoy! script-scoped varrrrr' }, nvim('exec2', [[
+ eq(
+ { output = 'ahoy! script-scoped varrrrr' },
+ nvim(
+ 'exec2',
+ [[
let s:pirate = 'script-scoped varrrrr'
function! s:avast_ye_hades(s) abort
return a:s .. ' ' .. s:pirate
endfunction
echo <sid>avast_ye_hades('ahoy!')
- ]], { output = true }))
-
- eq({ output = "{'output': 'ahoy! script-scoped varrrrr'}" }, nvim('exec2', [[
+ ]],
+ { output = true }
+ )
+ )
+
+ eq(
+ { output = "{'output': 'ahoy! script-scoped varrrrr'}" },
+ nvim(
+ 'exec2',
+ [[
let s:pirate = 'script-scoped varrrrr'
function! Avast_ye_hades(s) abort
return a:s .. ' ' .. s:pirate
endfunction
echo nvim_exec2('echo Avast_ye_hades(''ahoy!'')', {'output': v:true})
- ]], { output = true }))
-
- matches('Vim%(echo%):E121: Undefined variable: s:pirate$',
- pcall_err(request, 'nvim_exec2', [[
+ ]],
+ { output = true }
+ )
+ )
+
+ matches(
+ 'Vim%(echo%):E121: Undefined variable: s:pirate$',
+ pcall_err(
+ request,
+ 'nvim_exec2',
+ [[
let s:pirate = 'script-scoped varrrrr'
call nvim_exec2('echo s:pirate', {'output': v:true})
- ]], { output = false }))
+ ]],
+ { output = false }
+ )
+ )
-- Script items are created only on script var access
- eq({ output = '1\n0' }, nvim('exec2', [[
+ eq(
+ { output = '1\n0' },
+ nvim(
+ 'exec2',
+ [[
echo expand("<SID>")->empty()
let s:a = 123
echo expand("<SID>")->empty()
- ]], { output = true }))
-
- eq({ output = '1\n0' }, nvim('exec2', [[
+ ]],
+ { output = true }
+ )
+ )
+
+ eq(
+ { output = '1\n0' },
+ nvim(
+ 'exec2',
+ [[
echo expand("<SID>")->empty()
function s:a() abort
endfunction
echo expand("<SID>")->empty()
- ]], { output = true }))
+ ]],
+ { output = true }
+ )
+ )
end)
it('non-ASCII input', function()
- nvim('exec2', [=[
+ nvim(
+ 'exec2',
+ [=[
new
exe "normal! i ax \n Ax "
:%s/ax/--a1234--/g | :%s/Ax/--A1234--/g
- ]=], { output = false })
+ ]=],
+ { output = false }
+ )
nvim('command', '1')
eq(' --a1234-- ', nvim('get_current_line'))
nvim('command', '2')
eq(' --A1234-- ', nvim('get_current_line'))
- nvim('exec2', [[
+ nvim(
+ 'exec2',
+ [[
new
call setline(1,['xxx'])
call feedkeys('r')
call feedkeys('ñ', 'xt')
- ]], { output = false })
+ ]],
+ { output = false }
+ )
eq('ñxx', nvim('get_current_line'))
end)
it('execution error', function()
- eq('nvim_exec2(): Vim:E492: Not an editor command: bogus_command',
- pcall_err(request, 'nvim_exec2', 'bogus_command', {}))
- eq('', nvim('eval', 'v:errmsg')) -- v:errmsg was not updated.
+ eq(
+ 'nvim_exec2(): Vim:E492: Not an editor command: bogus_command',
+ pcall_err(request, 'nvim_exec2', 'bogus_command', {})
+ )
+ eq('', nvim('eval', 'v:errmsg')) -- v:errmsg was not updated.
eq('', eval('v:exception'))
- eq('nvim_exec2(): Vim(buffer):E86: Buffer 23487 does not exist',
- pcall_err(request, 'nvim_exec2', 'buffer 23487', {}))
- eq('', eval('v:errmsg')) -- v:errmsg was not updated.
+ eq(
+ 'nvim_exec2(): Vim(buffer):E86: Buffer 23487 does not exist',
+ pcall_err(request, 'nvim_exec2', 'buffer 23487', {})
+ )
+ eq('', eval('v:errmsg')) -- v:errmsg was not updated.
eq('', eval('v:exception'))
end)
@@ -240,7 +311,7 @@ describe('API', function()
request('nvim_exec2', [[
let x2 = substitute('foo','o','X','g')
let x4 = 'should be overwritten'
- call nvim_exec2("source ]]..fname..[[\nlet x3 = substitute('foo','foo','set by recursive nvim_exec2','g')\nlet x5='overwritten'\nlet x4=x5\n", {'output': v:false})
+ call nvim_exec2("source ]] .. fname .. [[\nlet x3 = substitute('foo','foo','set by recursive nvim_exec2','g')\nlet x5='overwritten'\nlet x4=x5\n", {'output': v:false})
]], { output = false })
eq('set from :source file', request('nvim_get_var', 'x1'))
eq('fXX', request('nvim_get_var', 'x2'))
@@ -254,24 +325,38 @@ describe('API', function()
local fname = tmpname()
write_file(fname, 'echo "hello"\n')
local sourcing_fname = tmpname()
- write_file(sourcing_fname, 'call nvim_exec2("source '..fname..'", {"output": v:false})\n')
+ write_file(sourcing_fname, 'call nvim_exec2("source ' .. fname .. '", {"output": v:false})\n')
meths.exec2('set verbose=2', { output = false })
- local traceback_output = 'line 0: sourcing "'..sourcing_fname..'"\n'..
- 'line 0: sourcing "'..fname..'"\n'..
- 'hello\n'..
- 'finished sourcing '..fname..'\n'..
- 'continuing in nvim_exec2() called at '..sourcing_fname..':1\n'..
- 'finished sourcing '..sourcing_fname..'\n'..
- 'continuing in nvim_exec2() called at nvim_exec2():0'
- eq({ output = traceback_output },
- meths.exec2('call nvim_exec2("source '..sourcing_fname..'", {"output": v:false})', { output = true }))
+ local traceback_output = dedent([[
+ line 0: sourcing "%s"
+ line 0: sourcing "%s"
+ hello
+ finished sourcing %s
+ continuing in nvim_exec2() called at %s:1
+ finished sourcing %s
+ continuing in nvim_exec2() called at nvim_exec2():0]]):format(
+ sourcing_fname,
+ fname,
+ fname,
+ sourcing_fname,
+ sourcing_fname
+ )
+ eq(
+ { output = traceback_output },
+ meths.exec2(
+ 'call nvim_exec2("source ' .. sourcing_fname .. '", {"output": v:false})',
+ { output = true }
+ )
+ )
os.remove(fname)
os.remove(sourcing_fname)
end)
it('returns output', function()
- eq({ output = 'this is spinal tap' },
- nvim('exec2', 'lua <<EOF\n\n\nprint("this is spinal tap")\n\n\nEOF', { output = true }))
+ eq(
+ { output = 'this is spinal tap' },
+ nvim('exec2', 'lua <<EOF\n\n\nprint("this is spinal tap")\n\n\nEOF', { output = true })
+ )
eq({ output = '' }, nvim('exec2', 'echo', { output = true }))
eq({ output = 'foo 42' }, nvim('exec2', 'echo "foo" 42', { output = true }))
end)
@@ -280,39 +365,45 @@ describe('API', function()
local screen = Screen.new(40, 8)
screen:attach()
screen:set_default_attr_ids({
- [0] = {bold=true, foreground=Screen.colors.Blue},
+ [0] = { bold = true, foreground = Screen.colors.Blue },
})
meths.exec2("echo 'hello'", { output = false })
- screen:expect{grid=[[
+ screen:expect {
+ grid = [[
^ |
{0:~ }|*6
hello |
- ]]}
+ ]],
+ }
end)
- it('doesn\'t display messages when output=true', function()
+ it("doesn't display messages when output=true", function()
local screen = Screen.new(40, 6)
screen:attach()
screen:set_default_attr_ids({
- [0] = {bold=true, foreground=Screen.colors.Blue},
+ [0] = { bold = true, foreground = Screen.colors.Blue },
})
meths.exec2("echo 'hello'", { output = true })
- screen:expect{grid=[[
+ screen:expect {
+ grid = [[
^ |
{0:~ }|*4
|
- ]]}
+ ]],
+ }
exec([[
func Print()
call nvim_exec2('echo "hello"', { 'output': v:true })
endfunc
]])
feed([[:echon 1 | call Print() | echon 5<CR>]])
- screen:expect{grid=[[
+ screen:expect {
+ grid = [[
^ |
{0:~ }|*4
15 |
- ]]}
+ ]],
+ }
end)
end)
@@ -320,7 +411,7 @@ describe('API', function()
it('works', function()
local fname = tmpname()
nvim('command', 'new')
- nvim('command', 'edit '..fname)
+ nvim('command', 'edit ' .. fname)
nvim('command', 'normal itesting\napi')
nvim('command', 'w')
local f = assert(io.open(fname))
@@ -334,49 +425,49 @@ describe('API', function()
end)
it('Vimscript validation error: fails with specific error', function()
- local status, rv = pcall(nvim, "command", "bogus_command")
- eq(false, status) -- nvim_command() failed.
- eq("E492:", string.match(rv, "E%d*:")) -- Vimscript error was returned.
- eq('', nvim('eval', 'v:errmsg')) -- v:errmsg was not updated.
+ local status, rv = pcall(nvim, 'command', 'bogus_command')
+ eq(false, status) -- nvim_command() failed.
+ eq('E492:', string.match(rv, 'E%d*:')) -- Vimscript error was returned.
+ eq('', nvim('eval', 'v:errmsg')) -- v:errmsg was not updated.
eq('', eval('v:exception'))
end)
it('Vimscript execution error: fails with specific error', function()
- local status, rv = pcall(nvim, "command", "buffer 23487")
- eq(false, status) -- nvim_command() failed.
- eq("E86: Buffer 23487 does not exist", string.match(rv, "E%d*:.*"))
- eq('', eval('v:errmsg')) -- v:errmsg was not updated.
+ local status, rv = pcall(nvim, 'command', 'buffer 23487')
+ eq(false, status) -- nvim_command() failed.
+ eq('E86: Buffer 23487 does not exist', string.match(rv, 'E%d*:.*'))
+ eq('', eval('v:errmsg')) -- v:errmsg was not updated.
eq('', eval('v:exception'))
end)
it('gives E493 instead of prompting on backwards range', function()
command('split')
- eq('Vim(windo):E493: Backwards range given: 2,1windo echo',
- pcall_err(command, '2,1windo echo'))
+ eq(
+ 'Vim(windo):E493: Backwards range given: 2,1windo echo',
+ pcall_err(command, '2,1windo echo')
+ )
end)
end)
describe('nvim_command_output', function()
it('does not induce hit-enter prompt', function()
- nvim("ui_attach", 80, 20, {})
+ nvim('ui_attach', 80, 20, {})
-- Induce a hit-enter prompt use nvim_input (non-blocking).
nvim('command', 'set cmdheight=1')
nvim('input', [[:echo "hi\nhi2"<CR>]])
-- Verify hit-enter prompt.
- eq({mode='r', blocking=true}, nvim("get_mode"))
+ eq({ mode = 'r', blocking = true }, nvim('get_mode'))
nvim('input', [[<C-c>]])
-- Verify NO hit-enter prompt.
nvim('command_output', [[echo "hi\nhi2"]])
- eq({mode='n', blocking=false}, nvim("get_mode"))
+ eq({ mode = 'n', blocking = false }, nvim('get_mode'))
end)
it('captures command output', function()
- eq('this is\nspinal tap',
- nvim('command_output', [[echo "this is\nspinal tap"]]))
- eq('no line ending!',
- nvim('command_output', [[echon "no line ending!"]]))
+ eq('this is\nspinal tap', nvim('command_output', [[echo "this is\nspinal tap"]]))
+ eq('no line ending!', nvim('command_output', [[echon "no line ending!"]]))
end)
it('captures empty command output', function()
@@ -388,49 +479,51 @@ describe('API', function()
end)
it('captures multiple commands', function()
- eq('foo\n 1 %a "[No Name]" line 1',
- nvim('command_output', 'echo "foo" | ls'))
+ eq(
+ 'foo\n 1 %a "[No Name]" line 1',
+ nvim('command_output', 'echo "foo" | ls')
+ )
end)
it('captures nested execute()', function()
- eq('\nnested1\nnested2\n 1 %a "[No Name]" line 1',
- nvim('command_output',
- [[echo execute('echo "nested1\nnested2"') | ls]]))
+ eq(
+ '\nnested1\nnested2\n 1 %a "[No Name]" line 1',
+ nvim('command_output', [[echo execute('echo "nested1\nnested2"') | ls]])
+ )
end)
it('captures nested nvim_command_output()', function()
- eq('nested1\nnested2\n 1 %a "[No Name]" line 1',
- nvim('command_output',
- [[echo nvim_command_output('echo "nested1\nnested2"') | ls]]))
+ eq(
+ 'nested1\nnested2\n 1 %a "[No Name]" line 1',
+ nvim('command_output', [[echo nvim_command_output('echo "nested1\nnested2"') | ls]])
+ )
end)
it('returns shell |:!| output', function()
local win_lf = is_os('win') and '\r' or ''
- eq(':!echo foo\r\n\nfoo'..win_lf..'\n', nvim('command_output', [[!echo foo]]))
+ eq(':!echo foo\r\n\nfoo' .. win_lf .. '\n', nvim('command_output', [[!echo foo]]))
end)
it('Vimscript validation error: fails with specific error', function()
- local status, rv = pcall(nvim, "command_output", "bogus commannnd")
- eq(false, status) -- nvim_command_output() failed.
- eq("E492: Not an editor command: bogus commannnd",
- string.match(rv, "E%d*:.*"))
- eq('', eval('v:errmsg')) -- v:errmsg was not updated.
+ local status, rv = pcall(nvim, 'command_output', 'bogus commannnd')
+ eq(false, status) -- nvim_command_output() failed.
+ eq('E492: Not an editor command: bogus commannnd', string.match(rv, 'E%d*:.*'))
+ eq('', eval('v:errmsg')) -- v:errmsg was not updated.
-- Verify NO hit-enter prompt.
- eq({mode='n', blocking=false}, nvim("get_mode"))
+ eq({ mode = 'n', blocking = false }, nvim('get_mode'))
end)
it('Vimscript execution error: fails with specific error', function()
- local status, rv = pcall(nvim, "command_output", "buffer 42")
- eq(false, status) -- nvim_command_output() failed.
- eq("E86: Buffer 42 does not exist", string.match(rv, "E%d*:.*"))
- eq('', eval('v:errmsg')) -- v:errmsg was not updated.
+ local status, rv = pcall(nvim, 'command_output', 'buffer 42')
+ eq(false, status) -- nvim_command_output() failed.
+ eq('E86: Buffer 42 does not exist', string.match(rv, 'E%d*:.*'))
+ eq('', eval('v:errmsg')) -- v:errmsg was not updated.
-- Verify NO hit-enter prompt.
- eq({mode='n', blocking=false}, nvim("get_mode"))
+ eq({ mode = 'n', blocking = false }, nvim('get_mode'))
end)
it('does not cause heap buffer overflow with large output', function()
- eq(eval('string(range(1000000))'),
- nvim('command_output', 'echo range(1000000)'))
+ eq(eval('string(range(1000000))'), nvim('command_output', 'echo range(1000000)'))
end)
end)
@@ -438,22 +531,21 @@ describe('API', function()
it('works', function()
nvim('command', 'let g:v1 = "a"')
nvim('command', 'let g:v2 = [1, 2, {"v3": 3}]')
- eq({v1 = 'a', v2 = { 1, 2, { v3 = 3 } } }, nvim('eval', 'g:'))
+ eq({ v1 = 'a', v2 = { 1, 2, { v3 = 3 } } }, nvim('eval', 'g:'))
end)
it('handles NULL-initialized strings correctly', function()
- eq(1, nvim('eval',"matcharg(1) == ['', '']"))
- eq({'', ''}, nvim('eval','matcharg(1)'))
+ eq(1, nvim('eval', "matcharg(1) == ['', '']"))
+ eq({ '', '' }, nvim('eval', 'matcharg(1)'))
end)
it('works under deprecated name', function()
- eq(2, request("vim_eval", "1+1"))
+ eq(2, request('vim_eval', '1+1'))
end)
- it("Vimscript error: returns error details, does NOT update v:errmsg", function()
- eq('Vim:E121: Undefined variable: bogus',
- pcall_err(request, 'nvim_eval', 'bogus expression'))
- eq('', eval('v:errmsg')) -- v:errmsg was not updated.
+ it('Vimscript error: returns error details, does NOT update v:errmsg', function()
+ eq('Vim:E121: Undefined variable: bogus', pcall_err(request, 'nvim_eval', 'bogus expression'))
+ eq('', eval('v:errmsg')) -- v:errmsg was not updated.
end)
end)
@@ -461,31 +553,41 @@ describe('API', function()
it('works', function()
nvim('call_function', 'setqflist', { { { filename = 'something', lnum = 17 } }, 'r' })
eq(17, nvim('call_function', 'getqflist', {})[1].lnum)
- eq(17, nvim('call_function', 'eval', {17}))
- eq('foo', nvim('call_function', 'simplify', {'this/./is//redundant/../../../foo'}))
- end)
-
- it("Vimscript validation error: returns specific error, does NOT update v:errmsg", function()
- eq('Vim:E117: Unknown function: bogus function',
- pcall_err(request, 'nvim_call_function', 'bogus function', {'arg1'}))
- eq('Vim:E119: Not enough arguments for function: atan',
- pcall_err(request, 'nvim_call_function', 'atan', {}))
+ eq(17, nvim('call_function', 'eval', { 17 }))
+ eq('foo', nvim('call_function', 'simplify', { 'this/./is//redundant/../../../foo' }))
+ end)
+
+ it('Vimscript validation error: returns specific error, does NOT update v:errmsg', function()
+ eq(
+ 'Vim:E117: Unknown function: bogus function',
+ pcall_err(request, 'nvim_call_function', 'bogus function', { 'arg1' })
+ )
+ eq(
+ 'Vim:E119: Not enough arguments for function: atan',
+ pcall_err(request, 'nvim_call_function', 'atan', {})
+ )
eq('', eval('v:exception'))
- eq('', eval('v:errmsg')) -- v:errmsg was not updated.
- end)
-
- it("Vimscript error: returns error details, does NOT update v:errmsg", function()
- eq('Vim:E808: Number or Float required',
- pcall_err(request, 'nvim_call_function', 'atan', {'foo'}))
- eq('Vim:Invalid channel stream "xxx"',
- pcall_err(request, 'nvim_call_function', 'chanclose', {999, 'xxx'}))
- eq('Vim:E900: Invalid channel id',
- pcall_err(request, 'nvim_call_function', 'chansend', {999, 'foo'}))
+ eq('', eval('v:errmsg')) -- v:errmsg was not updated.
+ end)
+
+ it('Vimscript error: returns error details, does NOT update v:errmsg', function()
+ eq(
+ 'Vim:E808: Number or Float required',
+ pcall_err(request, 'nvim_call_function', 'atan', { 'foo' })
+ )
+ eq(
+ 'Vim:Invalid channel stream "xxx"',
+ pcall_err(request, 'nvim_call_function', 'chanclose', { 999, 'xxx' })
+ )
+ eq(
+ 'Vim:E900: Invalid channel id',
+ pcall_err(request, 'nvim_call_function', 'chansend', { 999, 'foo' })
+ )
eq('', eval('v:exception'))
- eq('', eval('v:errmsg')) -- v:errmsg was not updated.
+ eq('', eval('v:errmsg')) -- v:errmsg was not updated.
end)
- it("Vimscript exception: returns exception details, does NOT update v:errmsg", function()
+ it('Vimscript exception: returns exception details, does NOT update v:errmsg', function()
source([[
function! Foo() abort
throw 'wtf'
@@ -493,10 +595,11 @@ describe('API', function()
]])
eq('function Foo, line 1: wtf', pcall_err(request, 'nvim_call_function', 'Foo', {}))
eq('', eval('v:exception'))
- eq('', eval('v:errmsg')) -- v:errmsg was not updated.
+ eq('', eval('v:errmsg')) -- v:errmsg was not updated.
end)
it('validation', function()
+ -- stylua: ignore
local too_many_args = { 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' }
source([[
function! Foo(...) abort
@@ -504,8 +607,10 @@ describe('API', function()
endfunction
]])
-- E740
- eq('Function called with too many arguments',
- pcall_err(request, 'nvim_call_function', 'Foo', too_many_args))
+ eq(
+ 'Function called with too many arguments',
+ pcall_err(request, 'nvim_call_function', 'Foo', too_many_args)
+ )
end)
end)
@@ -524,40 +629,55 @@ describe('API', function()
]])
-- :help Dictionary-function
- eq('Hello, World!', nvim('call_dict_function', 'g:test_dict_fn', 'F', {'World'}))
+ eq('Hello, World!', nvim('call_dict_function', 'g:test_dict_fn', 'F', { 'World' }))
-- Funcref is sent as NIL over RPC.
eq({ greeting = 'Hello', F = NIL }, nvim('get_var', 'test_dict_fn'))
-- :help numbered-function
- eq('Hi, Moon ...', nvim('call_dict_function', 'g:test_dict_fn2', 'F2', {'Moon'}))
+ eq('Hi, Moon ...', nvim('call_dict_function', 'g:test_dict_fn2', 'F2', { 'Moon' }))
-- Funcref is sent as NIL over RPC.
eq({ greeting = 'Hi', F2 = NIL }, nvim('get_var', 'test_dict_fn2'))
-- Function specified via RPC dict.
source('function! G() dict\n return "@".(self.result)."@"\nendfunction')
- eq('@it works@', nvim('call_dict_function', { result = 'it works', G = 'G'}, 'G', {}))
+ eq('@it works@', nvim('call_dict_function', { result = 'it works', G = 'G' }, 'G', {}))
end)
it('validation', function()
command('let g:d={"baz":"zub","meep":[]}')
- eq('Not found: bogus',
- pcall_err(request, 'nvim_call_dict_function', 'g:d', 'bogus', {1,2}))
- eq('Not a function: baz',
- pcall_err(request, 'nvim_call_dict_function', 'g:d', 'baz', {1,2}))
- eq('Not a function: meep',
- pcall_err(request, 'nvim_call_dict_function', 'g:d', 'meep', {1,2}))
- eq('Vim:E117: Unknown function: f',
- pcall_err(request, 'nvim_call_dict_function', { f = '' }, 'f', {1,2}))
- eq('Not a function: f',
- pcall_err(request, 'nvim_call_dict_function', "{ 'f': '' }", 'f', {1,2}))
- eq('dict argument type must be String or Dictionary',
- pcall_err(request, 'nvim_call_dict_function', 42, 'f', {1,2}))
- eq('Failed to evaluate dict expression',
- pcall_err(request, 'nvim_call_dict_function', 'foo', 'f', {1,2}))
- eq('dict not found',
- pcall_err(request, 'nvim_call_dict_function', '42', 'f', {1,2}))
- eq('Invalid (empty) function name',
- pcall_err(request, 'nvim_call_dict_function', "{ 'f': '' }", '', {1,2}))
+ eq(
+ 'Not found: bogus',
+ pcall_err(request, 'nvim_call_dict_function', 'g:d', 'bogus', { 1, 2 })
+ )
+ eq(
+ 'Not a function: baz',
+ pcall_err(request, 'nvim_call_dict_function', 'g:d', 'baz', { 1, 2 })
+ )
+ eq(
+ 'Not a function: meep',
+ pcall_err(request, 'nvim_call_dict_function', 'g:d', 'meep', { 1, 2 })
+ )
+ eq(
+ 'Vim:E117: Unknown function: f',
+ pcall_err(request, 'nvim_call_dict_function', { f = '' }, 'f', { 1, 2 })
+ )
+ eq(
+ 'Not a function: f',
+ pcall_err(request, 'nvim_call_dict_function', "{ 'f': '' }", 'f', { 1, 2 })
+ )
+ eq(
+ 'dict argument type must be String or Dictionary',
+ pcall_err(request, 'nvim_call_dict_function', 42, 'f', { 1, 2 })
+ )
+ eq(
+ 'Failed to evaluate dict expression',
+ pcall_err(request, 'nvim_call_dict_function', 'foo', 'f', { 1, 2 })
+ )
+ eq('dict not found', pcall_err(request, 'nvim_call_dict_function', '42', 'f', { 1, 2 }))
+ eq(
+ 'Invalid (empty) function name',
+ pcall_err(request, 'nvim_call_dict_function', "{ 'f': '' }", '', { 1, 2 })
+ )
end)
end)
@@ -565,21 +685,21 @@ describe('API', function()
local start_dir
before_each(function()
- funcs.mkdir("Xtestdir")
+ funcs.mkdir('Xtestdir')
start_dir = funcs.getcwd()
end)
after_each(function()
- helpers.rmdir("Xtestdir")
+ helpers.rmdir('Xtestdir')
end)
it('works', function()
- meths.set_current_dir("Xtestdir")
- eq(funcs.getcwd(), start_dir .. helpers.get_pathsep() .. "Xtestdir")
+ meths.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.set_current_dir('Xtestdir')
command('cd -')
eq(funcs.getcwd(), start_dir)
end)
@@ -590,60 +710,67 @@ describe('API', function()
meths.exec_lua('vim.api.nvim_set_var("test", 3)', {})
eq(3, meths.get_var('test'))
- eq(17, meths.exec_lua('a, b = ...\nreturn a + b', {10,7}))
+ eq(17, meths.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.exec_lua('function xx(a,b)\nreturn a..b\nend', {}))
+ eq('xy', meths.exec_lua('return xx(...)', { 'x', 'y' }))
-- Deprecated name: nvim_execute_lua.
- eq("xy", meths.execute_lua('return xx(...)', {'x','y'}))
+ eq('xy', meths.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', {}))
+ eq(
+ [[Error loading lua: [string "<nvim>"]:0: '=' expected near '+']],
+ pcall_err(meths.exec_lua, 'a+*b', {})
+ )
- eq([[Error loading lua: [string "<nvim>"]:0: unexpected symbol near '1']],
- pcall_err(meths.exec_lua, '1+2', {}))
+ eq(
+ [[Error loading lua: [string "<nvim>"]:0: unexpected symbol near '1']],
+ pcall_err(meths.exec_lua, '1+2', {})
+ )
- eq([[Error loading lua: [string "<nvim>"]:0: unexpected symbol]],
- pcall_err(meths.exec_lua, 'aa=bb\0', {}))
+ eq(
+ [[Error loading lua: [string "<nvim>"]:0: unexpected symbol]],
+ pcall_err(meths.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.exec_lua, 'bork()', {}))
- eq('did\nthe\nfail',
- pcall_err(meths.exec_lua, 'error("did\\nthe\\nfail")', {}))
+ eq('did\nthe\nfail', pcall_err(meths.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.exec_lua('return select(1, ...)', { 2.5 }))
+ eq('2.5', meths.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("{\n [false] = 2.5,\n [true] = 3\n}", meths.exec_lua("return vim.inspect(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'))", {})
+ )
end)
end)
describe('nvim_notify', function()
it('can notify a info message', function()
- nvim("notify", "hello world", 2, {})
+ nvim('notify', 'hello world', 2, {})
end)
it('can be overridden', function()
- command("lua vim.notify = function(...) return 42 end")
+ command('lua vim.notify = function(...) return 42 end')
eq(42, meths.exec_lua("return vim.notify('Hello world')", {}))
- nvim("notify", "hello world", 4, {})
+ nvim('notify', 'hello world', 4, {})
end)
end)
describe('nvim_input', function()
- it("Vimscript error: does NOT fail, updates v:errmsg", function()
- local status, _ = pcall(nvim, "input", ":call bogus_fn()<CR>")
- local v_errnum = string.match(nvim("eval", "v:errmsg"), "E%d*:")
- eq(true, status) -- nvim_input() did not fail.
- eq("E117:", v_errnum) -- v:errmsg was updated.
+ it('Vimscript error: does NOT fail, updates v:errmsg', function()
+ local status, _ = pcall(nvim, 'input', ':call bogus_fn()<CR>')
+ local v_errnum = string.match(nvim('eval', 'v:errmsg'), 'E%d*:')
+ eq(true, status) -- nvim_input() did not fail.
+ eq('E117:', v_errnum) -- v:errmsg was updated.
end)
it('does not crash even if trans_special result is largest #11788, #12287', function()
@@ -654,10 +781,8 @@ describe('API', function()
describe('nvim_paste', function()
it('validation', function()
- eq("Invalid 'phase': -2",
- pcall_err(request, 'nvim_paste', 'foo', true, -2))
- eq("Invalid 'phase': 4",
- pcall_err(request, 'nvim_paste', 'foo', true, 4))
+ eq("Invalid 'phase': -2", pcall_err(request, 'nvim_paste', 'foo', true, -2))
+ eq("Invalid 'phase': 4", pcall_err(request, 'nvim_paste', 'foo', true, 4))
end)
local function run_streamed_paste_tests()
it('stream: multiple chunks form one undo-block', function()
@@ -686,7 +811,7 @@ describe('API', function()
2/chunk 3
2/chunk 4 (end)
]])
- feed('u') -- Undo.
+ feed('u') -- Undo.
expect(expected1)
end)
it('stream: Insert mode', function()
@@ -1036,7 +1161,7 @@ describe('API', function()
line 2
line 3
]])
- eq({0,4,1,0}, funcs.getpos('.')) -- Cursor follows the paste.
+ eq({ 0, 4, 1, 0 }, funcs.getpos('.')) -- Cursor follows the paste.
eq(false, nvim('get_option_value', 'paste', {}))
command('%delete _')
-- Without final "\n".
@@ -1045,7 +1170,7 @@ describe('API', function()
line 1
line 2
line 3]])
- eq({0,3,6,0}, funcs.getpos('.'))
+ eq({ 0, 3, 6, 0 }, funcs.getpos('.'))
command('%delete _')
-- CRLF #10872
nvim('paste', 'line 1\r\nline 2\r\nline 3\r\n', true, -1)
@@ -1054,7 +1179,7 @@ describe('API', function()
line 2
line 3
]])
- eq({0,4,1,0}, funcs.getpos('.'))
+ eq({ 0, 4, 1, 0 }, funcs.getpos('.'))
command('%delete _')
-- CRLF without final "\n".
nvim('paste', 'line 1\r\nline 2\r\nline 3\r', true, -1)
@@ -1063,7 +1188,7 @@ describe('API', function()
line 2
line 3
]])
- eq({0,4,1,0}, funcs.getpos('.'))
+ eq({ 0, 4, 1, 0 }, funcs.getpos('.'))
command('%delete _')
-- CRLF without final "\r\n".
nvim('paste', 'line 1\r\nline 2\r\nline 3', true, -1)
@@ -1071,17 +1196,17 @@ describe('API', function()
line 1
line 2
line 3]])
- eq({0,3,6,0}, funcs.getpos('.'))
+ eq({ 0, 3, 6, 0 }, funcs.getpos('.'))
command('%delete _')
-- Various other junk.
nvim('paste', 'line 1\r\n\r\rline 2\nline 3\rline 4\r', true, -1)
expect('line 1\n\n\nline 2\nline 3\nline 4\n')
- eq({0,7,1,0}, funcs.getpos('.'))
+ eq({ 0, 7, 1, 0 }, funcs.getpos('.'))
eq(false, nvim('get_option_value', 'paste', {}))
end)
it('Replace-mode', function()
-- Within single line
- nvim('put', {'aabbccdd', 'eeffgghh', 'iijjkkll'}, "c", true, false)
+ nvim('put', { 'aabbccdd', 'eeffgghh', 'iijjkkll' }, 'c', true, false)
command('normal l')
command('startreplace')
nvim('paste', '123456', true, -1)