mirror of
https://github.com/neovim/neovim.git
synced 2025-10-26 12:27:24 +00:00
API: rename nvim_source => nvim_exec
- Eliminate nvim_source_output(): add boolean `output` param to nvim_exec() instead.
This commit is contained in:
@@ -16,6 +16,7 @@ local parse_context = helpers.parse_context
|
||||
local request = helpers.request
|
||||
local source = helpers.source
|
||||
local next_msg = helpers.next_msg
|
||||
local tmpname = helpers.tmpname
|
||||
local write_file = helpers.write_file
|
||||
|
||||
local pcall_err = helpers.pcall_err
|
||||
@@ -75,131 +76,127 @@ describe('API', function()
|
||||
eq({mode='i', blocking=false}, nvim("get_mode"))
|
||||
end)
|
||||
|
||||
describe('nvim_source', function()
|
||||
describe('nvim_exec', function()
|
||||
it('one-line input', function()
|
||||
nvim('source', "let x1 = 'a'")
|
||||
nvim('exec', "let x1 = 'a'", false)
|
||||
eq('a', nvim('get_var', 'x1'))
|
||||
end)
|
||||
|
||||
it(':verbose set {option}?', function()
|
||||
nvim('source', 'set nowrap')
|
||||
nvim('exec', 'set nowrap', false)
|
||||
eq('nowrap\n\tLast set from :source (no file)',
|
||||
nvim('source_output', 'verbose set wrap?'))
|
||||
nvim('exec', 'verbose set wrap?', true))
|
||||
end)
|
||||
|
||||
it('multiline input', function()
|
||||
-- Heredoc + empty lines.
|
||||
nvim('source', "let x2 = 'a'\n")
|
||||
nvim('exec', "let x2 = 'a'\n", false)
|
||||
eq('a', nvim('get_var', 'x2'))
|
||||
nvim('source','lua <<EOF\n\n\n\ny=3\n\n\nEOF')
|
||||
nvim('exec','lua <<EOF\n\n\n\ny=3\n\n\nEOF', false)
|
||||
eq(3, nvim('eval', "luaeval('y')"))
|
||||
|
||||
nvim('source', 'lua <<EOF\ny=3\nEOF')
|
||||
eq('', nvim('exec', 'lua <<EOF\ny=3\nEOF', false))
|
||||
eq(3, nvim('eval', "luaeval('y')"))
|
||||
|
||||
-- Multiple statements
|
||||
nvim('source', 'let x1=1\nlet x2=2\nlet x3=3\n')
|
||||
nvim('exec', 'let x1=1\nlet x2=2\nlet x3=3\n', false)
|
||||
eq(1, nvim('eval', 'x1'))
|
||||
eq(2, nvim('eval', 'x2'))
|
||||
eq(3, nvim('eval', 'x3'))
|
||||
|
||||
-- Functions
|
||||
nvim('source', 'function Foo()\ncall setline(1,["xxx"])\nendfunction')
|
||||
nvim('exec', 'function Foo()\ncall setline(1,["xxx"])\nendfunction', false)
|
||||
eq(nvim('get_current_line'), '')
|
||||
nvim('source', 'call Foo()')
|
||||
nvim('exec', 'call Foo()', false)
|
||||
eq(nvim('get_current_line'), 'xxx')
|
||||
|
||||
-- Autocmds
|
||||
nvim('source','autocmd BufAdd * :let x1 = "Hello"')
|
||||
nvim('exec','autocmd BufAdd * :let x1 = "Hello"', false)
|
||||
nvim('command', 'new foo')
|
||||
eq('Hello', request('nvim_eval', 'g:x1'))
|
||||
end)
|
||||
|
||||
it('non-ASCII input', function()
|
||||
nvim('source', [=[
|
||||
nvim('exec', [=[
|
||||
new
|
||||
exe "normal! i ax \n Ax "
|
||||
:%s/ax/--a1234--/g | :%s/Ax/--A1234--/g
|
||||
]=])
|
||||
]=], false)
|
||||
nvim('command', '1')
|
||||
eq(' --a1234-- ', nvim('get_current_line'))
|
||||
nvim('command', '2')
|
||||
eq(' --A1234-- ', nvim('get_current_line'))
|
||||
|
||||
nvim('source', [[
|
||||
nvim('exec', [[
|
||||
new
|
||||
call setline(1,['xxx'])
|
||||
call feedkeys('r')
|
||||
call feedkeys('ñ', 'xt')
|
||||
]])
|
||||
]], false)
|
||||
eq('ñxx', nvim('get_current_line'))
|
||||
end)
|
||||
|
||||
it('execution error', function()
|
||||
eq('Vim:E492: Not an editor command: bogus_command',
|
||||
pcall_err(request, 'nvim_source', 'bogus_command'))
|
||||
pcall_err(request, 'nvim_exec', 'bogus_command', false))
|
||||
eq('', nvim('eval', 'v:errmsg')) -- v:errmsg was not updated.
|
||||
eq('', eval('v:exception'))
|
||||
|
||||
eq('Vim(buffer):E86: Buffer 23487 does not exist',
|
||||
pcall_err(request, 'nvim_source', 'buffer 23487'))
|
||||
pcall_err(request, 'nvim_exec', 'buffer 23487', false))
|
||||
eq('', eval('v:errmsg')) -- v:errmsg was not updated.
|
||||
eq('', eval('v:exception'))
|
||||
end)
|
||||
|
||||
it('recursion', function()
|
||||
local fname = helpers.tmpname()
|
||||
local fname = tmpname()
|
||||
write_file(fname, 'let x1 = "set from :source file"\n')
|
||||
-- nvim_source
|
||||
-- nvim_exec
|
||||
-- :source
|
||||
-- nvim_source
|
||||
request('nvim_source', [[
|
||||
-- nvim_exec
|
||||
request('nvim_exec', [[
|
||||
let x2 = substitute('foo','o','X','g')
|
||||
let x4 = 'should be overwritten'
|
||||
call nvim_source("source ]]..fname..[[\nlet x3 = substitute('foo','foo','set by recursive nvim_source','g')\nlet x5='overwritten'\nlet x4=x5\n")
|
||||
]])
|
||||
call nvim_exec("source ]]..fname..[[\nlet x3 = substitute('foo','foo','set by recursive nvim_exec','g')\nlet x5='overwritten'\nlet x4=x5\n", v:false)
|
||||
]], false)
|
||||
eq('set from :source file', request('nvim_get_var', 'x1'))
|
||||
eq('fXX', request('nvim_get_var', 'x2'))
|
||||
eq('set by recursive nvim_source', request('nvim_get_var', 'x3'))
|
||||
eq('set by recursive nvim_exec', request('nvim_get_var', 'x3'))
|
||||
eq('overwritten', request('nvim_get_var', 'x4'))
|
||||
eq('overwritten', request('nvim_get_var', 'x5'))
|
||||
os.remove(fname)
|
||||
end)
|
||||
|
||||
it('traceback', function()
|
||||
local fname = helpers.tmpname()
|
||||
local fname = tmpname()
|
||||
write_file(fname, 'echo "hello"\n')
|
||||
local sourcing_fname = helpers.tmpname()
|
||||
write_file(sourcing_fname, 'call nvim_source("source '..fname..'")\n')
|
||||
meths.source('set verbose=2')
|
||||
print()
|
||||
local sourcing_fname = tmpname()
|
||||
write_file(sourcing_fname, 'call nvim_exec("source '..fname..'", v:false)\n')
|
||||
meths.exec('set verbose=2', false)
|
||||
local traceback_output = 'line 0: sourcing "'..sourcing_fname..'"\n'..
|
||||
'line 0: sourcing "'..fname..'"\n'..
|
||||
'hello\n'..
|
||||
'finished sourcing '..fname..'\n'..
|
||||
'continuing in nvim_source(..) called at '..sourcing_fname..':1\n'..
|
||||
'continuing in nvim_exec() called at '..sourcing_fname..':1\n'..
|
||||
'finished sourcing '..sourcing_fname..'\n'..
|
||||
'continuing in nvim_source(..) called at nvim_source_output(..):0'
|
||||
eq(traceback_output, meths.source_output('call nvim_source("source '..sourcing_fname..'")'))
|
||||
'continuing in nvim_exec() called at nvim_exec():0'
|
||||
eq(traceback_output,
|
||||
meths.exec('call nvim_exec("source '..sourcing_fname..'", v:false)', true))
|
||||
os.remove(fname)
|
||||
os.remove(sourcing_fname)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('nvim_source_output', function()
|
||||
it('multiline input', function()
|
||||
it('returns output', function()
|
||||
eq('this is spinal tap',
|
||||
nvim('source_output', 'lua <<EOF\n\n\nprint("this is spinal tap")\n\n\nEOF'))
|
||||
end)
|
||||
|
||||
it('empty output', function()
|
||||
eq('', nvim('source_output', 'echo'))
|
||||
nvim('exec', 'lua <<EOF\n\n\nprint("this is spinal tap")\n\n\nEOF', true))
|
||||
eq('', nvim('exec', 'echo', true))
|
||||
eq('foo 42', nvim('exec', 'echo "foo" 42', true))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('nvim_command', function()
|
||||
it('works', function()
|
||||
local fname = helpers.tmpname()
|
||||
local fname = tmpname()
|
||||
nvim('command', 'new')
|
||||
nvim('command', 'edit '..fname)
|
||||
nvim('command', 'normal itesting\napi')
|
||||
|
||||
Reference in New Issue
Block a user