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.lua266
1 files changed, 263 insertions, 3 deletions
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index ffef6a6066..c95c24fabe 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -12,14 +12,17 @@ local funcs = helpers.funcs
local iswin = helpers.iswin
local meths = helpers.meths
local matches = helpers.matches
+local mkdir_p = helpers.mkdir_p
local ok, nvim_async, feed = helpers.ok, helpers.nvim_async, helpers.feed
local is_os = helpers.is_os
local parse_context = helpers.parse_context
local request = helpers.request
+local rmdir = helpers.rmdir
local source = helpers.source
local next_msg = helpers.next_msg
local tmpname = helpers.tmpname
local write_file = helpers.write_file
+local exec_lua = helpers.exec_lua
local pcall_err = helpers.pcall_err
local format_string = helpers.format_string
@@ -89,6 +92,14 @@ describe('API', function()
nvim('exec', 'set nowrap', false)
eq('nowrap\n\tLast set from anonymous :source',
nvim('exec', 'verbose set wrap?', true))
+
+ -- Using script var to force creation of a script item
+ nvim('exec', [[
+ let s:a = 1
+ set nowrap
+ ]], false)
+ eq('nowrap\n\tLast set from anonymous :source (script id 1)',
+ nvim('exec', 'verbose set wrap?', true))
end)
it('multiline input', function()
@@ -130,6 +141,43 @@ describe('API', function()
-- try no spaces before continuations to catch off-by-one error
nvim('exec', 'let ab = #{\n\\a: 98,\n"\\ b: 2\n\\}', false)
eq({a = 98}, request('nvim_eval', 'g:ab'))
+
+ -- Script scope (s:)
+ eq('ahoy! script-scoped varrrrr', nvim('exec', [[
+ 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!')
+ ]], true))
+
+ eq('ahoy! script-scoped varrrrr', nvim('exec', [[
+ let s:pirate = 'script-scoped varrrrr'
+ function! Avast_ye_hades(s) abort
+ return a:s .. ' ' .. s:pirate
+ endfunction
+ echo nvim_exec('echo Avast_ye_hades(''ahoy!'')', 1)
+ ]], true))
+
+ eq('Vim(call):E5555: API call: Vim(echo):E121: Undefined variable: s:pirate',
+ pcall_err(request, 'nvim_exec', [[
+ let s:pirate = 'script-scoped varrrrr'
+ call nvim_exec('echo s:pirate', 1)
+ ]], false))
+
+ -- Script items are created only on script var access
+ eq('1\n0', nvim('exec', [[
+ echo expand("<SID>")->empty()
+ let s:a = 123
+ echo expand("<SID>")->empty()
+ ]], true))
+
+ eq('1\n0', nvim('exec', [[
+ echo expand("<SID>")->empty()
+ function s:a() abort
+ endfunction
+ echo expand("<SID>")->empty()
+ ]], true))
end)
it('non-ASCII input', function()
@@ -1117,7 +1165,7 @@ describe('API', function()
describe('nvim_get_context', function()
it('validates args', function()
- eq('unexpected key: blah',
+ eq("Invalid key: 'blah'",
pcall_err(nvim, 'get_context', {blah={}}))
eq('invalid value for key: types',
pcall_err(nvim, 'get_context', {types=42}))
@@ -1574,6 +1622,18 @@ describe('API', function()
end)
describe('nvim_list_runtime_paths', function()
+ setup(function()
+ local pathsep = helpers.get_pathsep()
+ mkdir_p('Xtest'..pathsep..'a')
+ mkdir_p('Xtest'..pathsep..'b')
+ end)
+ teardown(function()
+ rmdir 'Xtest'
+ end)
+ before_each(function()
+ meths.set_current_dir 'Xtest'
+ end)
+
it('returns nothing with empty &runtimepath', function()
meths.set_option('runtimepath', '')
eq({}, meths.list_runtime_paths())
@@ -1601,8 +1661,7 @@ describe('API', function()
local long_path = ('/a'):rep(8192)
meths.set_option('runtimepath', long_path)
local paths_list = meths.list_runtime_paths()
- neq({long_path}, paths_list)
- eq({long_path:sub(1, #(paths_list[1]))}, paths_list)
+ eq({}, paths_list)
end)
end)
@@ -2206,6 +2265,9 @@ describe('API', function()
[2] = {background = tonumber('0xffff40'), bg_indexed = true};
[3] = {background = Screen.colors.Plum1, fg_indexed = true, foreground = tonumber('0x00e000')};
[4] = {bold = true, reverse = true, background = Screen.colors.Plum1};
+ [5] = {foreground = Screen.colors.Blue, background = Screen.colors.LightMagenta, bold = true};
+ [6] = {bold = true};
+ [7] = {reverse = true, background = Screen.colors.LightMagenta};
})
end)
@@ -2253,5 +2315,203 @@ describe('API', function()
|
]]}
end)
+
+ it('can handle input', function()
+ screen:try_resize(50, 10)
+ eq({3, 2}, exec_lua [[
+ buf = vim.api.nvim_create_buf(1,1)
+
+ stream = ''
+ do_the_echo = false
+ function input(_,t1,b1,data)
+ stream = stream .. data
+ _G.vals = {t1, b1}
+ if do_the_echo then
+ vim.api.nvim_chan_send(t1, data)
+ end
+ end
+
+ term = vim.api.nvim_open_term(buf, {on_input=input})
+ vim.api.nvim_open_win(buf, true, {width=40, height=5, row=1, col=1, relative='editor'})
+ return {term, buf}
+ ]])
+
+ screen:expect{grid=[[
+ |
+ {0:~}{1:^ }{0: }|
+ {0:~}{1: }{0: }|
+ {0:~}{1: }{0: }|
+ {0:~}{1: }{0: }|
+ {0:~}{1: }{0: }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]]}
+
+ feed 'iba<c-x>bla'
+ screen:expect{grid=[[
+ |
+ {0:~}{7: }{1: }{0: }|
+ {0:~}{1: }{0: }|
+ {0:~}{1: }{0: }|
+ {0:~}{1: }{0: }|
+ {0:~}{1: }{0: }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {6:-- TERMINAL --} |
+ ]]}
+
+ eq('ba\024bla', exec_lua [[ return stream ]])
+ eq({3,2}, exec_lua [[ return vals ]])
+
+ exec_lua [[ do_the_echo = true ]]
+ feed 'herrejösses!'
+
+ screen:expect{grid=[[
+ |
+ {0:~}{1:herrejösses!}{7: }{1: }{0: }|
+ {0:~}{1: }{0: }|
+ {0:~}{1: }{0: }|
+ {0:~}{1: }{0: }|
+ {0:~}{1: }{0: }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {6:-- TERMINAL --} |
+ ]]}
+ eq('ba\024blaherrejösses!', exec_lua [[ return stream ]])
+ end)
+ end)
+
+ describe('nvim_del_mark', function()
+ it('works', function()
+ local buf = meths.create_buf(false,true)
+ meths.buf_set_lines(buf, -1, -1, true, {'a', 'bit of', 'text'})
+ eq(true, meths.buf_set_mark(buf, 'F', 2, 2))
+ eq(true, meths.del_mark('F'))
+ eq({0, 0}, meths.buf_get_mark(buf, 'F'))
+ end)
+ it('fails when invalid marks are used', function()
+ eq(false, pcall(meths.del_mark, 'f'))
+ eq(false, pcall(meths.del_mark, '!'))
+ eq(false, pcall(meths.del_mark, 'fail'))
+ end)
+ end)
+ describe('nvim_get_mark', function()
+ it('works', function()
+ local buf = meths.create_buf(false,true)
+ meths.buf_set_lines(buf, -1, -1, true, {'a', 'bit of', 'text'})
+ meths.buf_set_mark(buf, 'F', 2, 2)
+ meths.buf_set_name(buf, "mybuf")
+ local mark = meths.get_mark('F')
+ -- Compare the path tail ony
+ assert(string.find(mark[4], "mybuf$"))
+ eq({2, 2, buf.id, mark[4]}, mark)
+ end)
+ it('fails when invalid marks are used', function()
+ eq(false, pcall(meths.del_mark, 'f'))
+ eq(false, pcall(meths.del_mark, '!'))
+ eq(false, pcall(meths.del_mark, 'fail'))
+ end)
+ it('returns the expected when mark is not set', function()
+ eq(true, meths.del_mark('A'))
+ eq({0, 0, 0, ''}, meths.get_mark('A'))
+ end)
+ it('works with deleted buffers', function()
+ local fname = tmpname()
+ write_file(fname, 'a\nbit of\text')
+ nvim("command", "edit " .. fname)
+ local buf = meths.get_current_buf()
+
+ meths.buf_set_mark(buf, 'F', 2, 2)
+ nvim("command", "new") -- Create new buf to avoid :bd failing
+ nvim("command", "bd! " .. buf.id)
+ os.remove(fname)
+
+ local mark = meths.get_mark('F')
+ -- To avoid comparing relative vs absolute path
+ local mfname = mark[4]
+ local tail_patt = [[[\/][^\/]*$]]
+ -- tail of paths should be equals
+ eq(fname:match(tail_patt), mfname:match(tail_patt))
+ eq({2, 2, buf.id, mark[4]}, mark)
+ end)
+ end)
+ describe('nvim_eval_statusline', function()
+ it('works', function()
+ eq({
+ str = '%StatusLineStringWithHighlights',
+ width = 31
+ },
+ meths.eval_statusline(
+ '%%StatusLineString%#WarningMsg#WithHighlights',
+ {}))
+ end)
+ it('doesn\'t exceed maxwidth', function()
+ eq({
+ str = 'Should be trun>',
+ width = 15
+ },
+ meths.eval_statusline(
+ 'Should be truncated%<',
+ { maxwidth = 15 }))
+ end)
+ describe('highlight parsing', function()
+ it('works', function()
+ eq({
+ str = "TextWithWarningHighlightTextWithUserHighlight",
+ width = 45,
+ highlights = {
+ { start = 0, group = 'WarningMsg' },
+ { start = 24, group = 'User1' }
+ },
+ },
+ meths.eval_statusline(
+ '%#WarningMsg#TextWithWarningHighlight%1*TextWithUserHighlight',
+ { highlights = true }))
+ end)
+ it('works with no highlight', function()
+ eq({
+ str = "TextWithNoHighlight",
+ width = 19,
+ highlights = {
+ { start = 0, group = 'StatusLine' },
+ },
+ },
+ meths.eval_statusline(
+ 'TextWithNoHighlight',
+ { highlights = true }))
+ end)
+ it('works with inactive statusline', function()
+ command('split')
+
+ eq({
+ str = 'TextWithNoHighlightTextWithWarningHighlight',
+ width = 43,
+ highlights = {
+ { start = 0, group = 'StatusLineNC' },
+ { start = 19, group = 'WarningMsg' }
+ }
+ },
+ meths.eval_statusline(
+ 'TextWithNoHighlight%#WarningMsg#TextWithWarningHighlight',
+ { winid = meths.list_wins()[2].id, highlights = true }))
+ end)
+ it('works with tabline', function()
+ eq({
+ str = 'TextWithNoHighlightTextWithWarningHighlight',
+ width = 43,
+ highlights = {
+ { start = 0, group = 'TabLineFill' },
+ { start = 19, group = 'WarningMsg' }
+ }
+ },
+ meths.eval_statusline(
+ 'TextWithNoHighlight%#WarningMsg#TextWithWarningHighlight',
+ { use_tabline = true, highlights = true }))
+ end)
+ end)
end)
end)