diff options
Diffstat (limited to 'test/functional/api')
-rw-r--r-- | test/functional/api/buffer_spec.lua | 55 | ||||
-rw-r--r-- | test/functional/api/command_spec.lua | 2 | ||||
-rw-r--r-- | test/functional/api/keymap_spec.lua | 12 | ||||
-rw-r--r-- | test/functional/api/vim_spec.lua | 266 | ||||
-rw-r--r-- | test/functional/api/window_spec.lua | 26 |
5 files changed, 345 insertions, 16 deletions
diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index 81fad206da..01fcfab543 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -707,4 +707,59 @@ describe('api/buf', function() eq({3, 0}, curbuf('get_mark', 'v')) end) end) + + describe('nvim_buf_set_mark', function() + it('works with buffer local marks', function() + curbufmeths.set_lines(-1, -1, true, {'a', 'bit of', 'text'}) + eq(true, curbufmeths.set_mark('z', 1, 1)) + eq({1, 1}, curbufmeths.get_mark('z')) + end) + it('works with file/uppercase marks', function() + curbufmeths.set_lines(-1, -1, true, {'a', 'bit of', 'text'}) + eq(true, curbufmeths.set_mark('Z', 3, 1)) + eq({3, 1}, curbufmeths.get_mark('Z')) + end) + it('fails when invalid marks names are used', function() + eq(false, pcall(curbufmeths.set_mark, '!', 1, 0)) + eq(false, pcall(curbufmeths.set_mark, 'fail', 1, 0)) + end) + it('fails when invalid buffer number is used', function() + eq(false, pcall(meths.buf_set_mark, 99, 'a', 1, 1)) + end) + end) + + describe('nvim_buf_del_mark', function() + it('works with buffer local marks', function() + curbufmeths.set_lines(-1, -1, true, {'a', 'bit of', 'text'}) + curbufmeths.set_mark('z', 3, 1) + eq(true, curbufmeths.del_mark('z')) + eq({0, 0}, curbufmeths.get_mark('z')) + end) + it('works with file/uppercase marks', function() + curbufmeths.set_lines(-1, -1, true, {'a', 'bit of', 'text'}) + curbufmeths.set_mark('Z', 3, 3) + eq(true, curbufmeths.del_mark('Z')) + eq({0, 0}, curbufmeths.get_mark('Z')) + end) + it('returns false in marks not set in this buffer', function() + local abuf = meths.create_buf(false,true) + bufmeths.set_lines(abuf, -1, -1, true, {'a', 'bit of', 'text'}) + bufmeths.set_mark(abuf, 'A', 2, 2) + eq(false, curbufmeths.del_mark('A')) + eq({2, 2}, bufmeths.get_mark(abuf, 'A')) + end) + it('returns false if mark was not deleted', function() + curbufmeths.set_lines(-1, -1, true, {'a', 'bit of', 'text'}) + curbufmeths.set_mark('z', 3, 1) + eq(true, curbufmeths.del_mark('z')) + eq(false, curbufmeths.del_mark('z')) -- Mark was already deleted + end) + it('fails when invalid marks names are used', function() + eq(false, pcall(curbufmeths.del_mark, '!')) + eq(false, pcall(curbufmeths.del_mark, 'fail')) + end) + it('fails when invalid buffer number is used', function() + eq(false, pcall(meths.buf_del_mark, 99, 'a')) + end) + end) end) diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua index 37331d11c7..6f929ad1ca 100644 --- a/test/functional/api/command_spec.lua +++ b/test/functional/api/command_spec.lua @@ -21,7 +21,7 @@ describe('nvim_get_commands', function() it('validates input', function() eq('builtin=true not implemented', pcall_err(meths.get_commands, {builtin=true})) - eq('unexpected key: foo', pcall_err(meths.get_commands, + eq("Invalid key: 'foo'", pcall_err(meths.get_commands, {foo='blah'})) end) diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua index 4194945645..dd8eef7ca0 100644 --- a/test/functional/api/keymap_spec.lua +++ b/test/functional/api/keymap_spec.lua @@ -436,16 +436,16 @@ describe('nvim_set_keymap, nvim_del_keymap', function() end) it('error on invalid optnames', function() - eq('Invalid key: silentt', + eq("Invalid key: 'silentt'", pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', {silentt = true})) - eq('Invalid key: sidd', + eq("Invalid key: 'sidd'", pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', {sidd = false})) - eq('Invalid key: nowaiT', + eq("Invalid key: 'nowaiT'", pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', {nowaiT = false})) end) it('error on <buffer> option key', function() - eq('Invalid key: buffer', + eq("Invalid key: 'buffer'", pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', {buffer = true})) end) @@ -454,8 +454,8 @@ describe('nvim_set_keymap, nvim_del_keymap', function() -- note: need '%' to escape hyphens, which have special meaning in lua it('throws an error when given non-boolean value for '..opt, function() local opts = {} - opts[opt] = 2 - eq('Gave non-boolean value for an opt: '..opt, + opts[opt] = 'fooo' + eq(opt..' is not a boolean', pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', opts)) end) end 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) diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index c49d6405f4..11755a9d97 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -1,8 +1,9 @@ local helpers = require('test.functional.helpers')(after_each) local clear, nvim, curbuf, curbuf_contents, window, curwin, eq, neq, - ok, feed, insert, eval = helpers.clear, helpers.nvim, helpers.curbuf, + ok, feed, insert, eval, tabpage = helpers.clear, helpers.nvim, helpers.curbuf, helpers.curbuf_contents, helpers.window, helpers.curwin, helpers.eq, - helpers.neq, helpers.ok, helpers.feed, helpers.insert, helpers.eval + helpers.neq, helpers.ok, helpers.feed, helpers.insert, helpers.eval, + helpers.tabpage local poke_eventloop = helpers.poke_eventloop local curwinmeths = helpers.curwinmeths local funcs = helpers.funcs @@ -11,6 +12,7 @@ local NIL = helpers.NIL local meths = helpers.meths local command = helpers.command local pcall_err = helpers.pcall_err +local assert_alive = helpers.assert_alive -- check if str is visible at the beginning of some line local function is_visible(str) @@ -206,7 +208,7 @@ describe('API/win', function() end) end) - describe('{get,set}_option', function() + describe('nvim_win_get_option, nvim_win_set_option', function() it('works', function() curwin('set_option', 'colorcolumn', '4,3') eq('4,3', curwin('get_option', 'colorcolumn')) @@ -224,6 +226,18 @@ describe('API/win', function() pcall_err(curwin, 'get_option', 'statusline')) eq('', eval('&l:statusline')) -- confirm local value was not copied end) + + it('after switching windows #15390', function() + nvim('command', 'tabnew') + local tab1 = unpack(nvim('list_tabpages')) + local win1 = unpack(tabpage('list_wins', tab1)) + window('set_option', win1, 'statusline', 'window-status') + nvim('command', 'split') + nvim('command', 'wincmd J') + nvim('command', 'wincmd j') + eq('window-status', window('get_option', win1, 'statusline')) + assert_alive() + end) end) describe('get_position', function() @@ -354,13 +368,13 @@ describe('API/win', function() local win = meths.open_win(0, true, { relative='editor', row=10, col=10, width=50, height=10 }) - local tabpage = eval('tabpagenr()') + local tab = eval('tabpagenr()') command('tabprevious') eq(1, eval('tabpagenr()')) meths.win_close(win, false) - eq(1001, meths.tabpage_get_win(tabpage).id) - helpers.assert_alive() + eq(1001, meths.tabpage_get_win(tab).id) + assert_alive() end) end) |