diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2023-01-25 17:57:01 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2023-01-25 17:57:01 +0000 |
commit | 9837de570c5972f98e74848edc97c297a13136ea (patch) | |
tree | cc948611912d116a3f98a744e690d3d7b6e2f59a /test/functional/api/vim_spec.lua | |
parent | c367400b73d207833d51e09d663f969ffab37531 (diff) | |
parent | 3c48d3c83fc21dbc0841f9210f04bdb073d73cd1 (diff) | |
download | rneovim-9837de570c5972f98e74848edc97c297a13136ea.tar.gz rneovim-9837de570c5972f98e74848edc97c297a13136ea.tar.bz2 rneovim-9837de570c5972f98e74848edc97c297a13136ea.zip |
Merge remote-tracking branch 'upstream/master' into colorcolchar
Diffstat (limited to 'test/functional/api/vim_spec.lua')
-rw-r--r-- | test/functional/api/vim_spec.lua | 93 |
1 files changed, 68 insertions, 25 deletions
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index af6cee7e90..8fcdd9620b 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -12,7 +12,6 @@ local exec = helpers.exec local eval = helpers.eval local expect = helpers.expect local funcs = helpers.funcs -local iswin = helpers.iswin local meths = helpers.meths local matches = helpers.matches local pesc = helpers.pesc @@ -30,6 +29,7 @@ local exec_lua = helpers.exec_lua local exc_exec = helpers.exc_exec local insert = helpers.insert local expect_exit = helpers.expect_exit +local skip = helpers.skip local pcall_err = helpers.pcall_err local format_string = helpers.format_string @@ -166,7 +166,7 @@ describe('API', function() echo nvim_exec('echo Avast_ye_hades(''ahoy!'')', 1) ]], true)) - eq('Vim(call):E5555: API call: Vim(echo):E121: Undefined variable: s:pirate', + matches('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) @@ -208,12 +208,12 @@ describe('API', function() end) it('execution error', function() - eq('Vim:E492: Not an editor command: bogus_command', + eq('nvim_exec(): Vim:E492: Not an editor command: 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', + eq('nvim_exec(): Vim(buffer):E86: Buffer 23487 does not exist', pcall_err(request, 'nvim_exec', 'buffer 23487', false)) eq('', eval('v:errmsg')) -- v:errmsg was not updated. eq('', eval('v:exception')) @@ -399,7 +399,7 @@ describe('API', function() end) it('returns shell |:!| output', function() - local win_lf = iswin() and '\r' or '' + local win_lf = is_os('win') and '\r' or '' eq(':!echo foo\r\n\nfoo'..win_lf..'\n', nvim('command_output', [[!echo foo]])) end) @@ -485,7 +485,7 @@ describe('API', function() throw 'wtf' endfunction ]]) - eq('wtf', pcall_err(request, 'nvim_call_function', 'Foo', {})) + 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. end) @@ -604,10 +604,10 @@ describe('API', function() eq([[Error loading lua: [string "<nvim>"]:0: unexpected symbol]], pcall_err(meths.exec_lua, 'aa=bb\0', {})) - eq([[Error executing lua: [string "<nvim>"]:0: attempt to call global 'bork' (a nil value)]], + eq([[attempt to call global 'bork' (a nil value)]], pcall_err(meths.exec_lua, 'bork()', {})) - eq('Error executing lua: [string "<nvim>"]:0: did\nthe\nfail', + eq('did\nthe\nfail', pcall_err(meths.exec_lua, 'error("did\\nthe\\nfail")', {})) end) @@ -1108,6 +1108,14 @@ describe('API', function() nvim('paste', 'a', true, -1) eq('a', funcs.getcmdline()) end) + it('pasted text is saved in cmdline history when <CR> comes from mapping #20957', function() + command('cnoremap <CR> <CR>') + feed(':') + nvim('paste', 'echo', true, -1) + eq('', funcs.histget(':')) + feed('<CR>') + eq('echo', funcs.histget(':')) + end) it('pasting with empty last chunk in Cmdline mode', function() local screen = Screen.new(20, 4) screen:attach() @@ -1140,7 +1148,7 @@ describe('API', function() end) it('vim.paste() failure', function() nvim('exec_lua', 'vim.paste = (function(lines, phase) error("fake fail") end)', {}) - eq([[Error executing lua: [string "<nvim>"]:0: fake fail]], + eq('fake fail', pcall_err(request, 'nvim_paste', 'line 1\nline 2\nline 3', false, 1)) end) end) @@ -1799,9 +1807,11 @@ describe('API', function() }, ['jumps'] = eval(([[ - filter(map(getjumplist()[0], 'filter( - { "f": expand("#".v:val.bufnr.":p"), "l": v:val.lnum }, - { k, v -> k != "l" || v != 1 })'), '!empty(v:val.f)') + filter(map(add( + getjumplist()[0], { 'bufnr': bufnr('%'), 'lnum': getcurpos()[1] }), + 'filter( + { "f": expand("#".v:val.bufnr.":p"), "l": v:val.lnum }, + { k, v -> k != "l" || v != 1 })'), '!empty(v:val.f)') ]]):gsub('\n', '')), ['bufs'] = eval([[ @@ -2116,7 +2126,7 @@ describe('API', function() pty='?', } local event = meths.get_var("opened_event") - if not iswin() then + if not is_os('win') then info.pty = event.info.pty neq(nil, string.match(info.pty, "^/dev/")) end @@ -2132,7 +2142,7 @@ describe('API', function() stream = 'job', id = 4, argv = ( - iswin() and { + is_os('win') and { eval('&shell'), '/s', '/c', @@ -2154,7 +2164,7 @@ describe('API', function() -- :terminal with args + stopped process. eq(1, eval('jobstop(&channel)')) eval('jobwait([&channel], 1000)') -- Wait. - expected2.pty = (iswin() and '?' or '') -- pty stream was closed. + expected2.pty = (is_os('win') and '?' or '') -- pty stream was closed. eq(expected2, eval('nvim_get_chan_info(&channel)')) end) end) @@ -2315,12 +2325,6 @@ describe('API', function() meths.set_option('isident', '') end) - local it_maybe_pending = it - if helpers.isCI() and os.getenv('CONFIGURATION') == 'MSVC_32' then - -- For "works with &opt" (flaky on MSVC_32), but not easy to skip alone. #10241 - it_maybe_pending = pending - end - local function simplify_east_api_node(line, east_api_node) if east_api_node == NIL then return nil @@ -2517,7 +2521,7 @@ describe('API', function() end end require('test.unit.viml.expressions.parser_tests')( - it_maybe_pending, _check_parsing, hl, fmtn) + it, _check_parsing, hl, fmtn) end) describe('nvim_list_uis', function() @@ -2721,7 +2725,7 @@ describe('API', function() eq({}, meths.get_runtime_file("foobarlang/", true)) end) it('can handle bad patterns', function() - if helpers.pending_win32(pending) then return end + skip(is_os('win')) eq("Vim:E220: Missing }.", pcall_err(meths.get_runtime_file, "{", false)) @@ -3040,7 +3044,7 @@ describe('API', function() 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 + -- Compare the path tail only assert(string.find(mark[4], "mybuf$")) eq({2, 2, buf.id, mark[4]}, mark) end) @@ -3124,6 +3128,24 @@ describe('API', function() eq('E539: Illegal character <}>', pcall_err(meths.eval_statusline, '%{%}', {})) end) + it('supports various items', function() + eq({ str = '0', width = 1 }, + meths.eval_statusline('%l', { maxwidth = 5 })) + command('set readonly') + eq({ str = '[RO]', width = 4 }, + meths.eval_statusline('%r', { maxwidth = 5 })) + local screen = Screen.new(80, 24) + screen:attach() + command('set showcmd') + feed('1234') + screen:expect({any = '1234'}) + eq({ str = '1234', width = 4 }, + meths.eval_statusline('%S', { maxwidth = 5 })) + feed('56') + screen:expect({any = '123456'}) + eq({ str = '<3456', width = 5 }, + meths.eval_statusline('%S', { maxwidth = 5 })) + end) describe('highlight parsing', function() it('works', function() eq({ @@ -3191,6 +3213,17 @@ describe('API', function() 'TextWithNoHighlight%#WarningMsg#TextWithWarningHighlight', { use_winbar = true, highlights = true })) end) + it('no memory leak with click functions', function() + meths.eval_statusline('%@ClickFunc@StatusLineStringWithClickFunc%T', {}) + eq({ + str = 'StatusLineStringWithClickFunc', + width = 29 + }, + meths.eval_statusline( + '%@ClickFunc@StatusLineStringWithClickFunc%T', + {}) + ) + end) end) end) describe('nvim_parse_cmd', function() @@ -3851,14 +3884,16 @@ describe('API', function() eq("", meths.cmd({ cmd = "Foo", bang = false }, { output = true })) end) it('works with modifiers', function() - -- with :silent output is still captured + -- with silent = true output is still captured eq('1', meths.cmd({ cmd = 'echomsg', args = { '1' }, mods = { silent = true } }, { output = true })) -- but message isn't added to message history eq('', meths.cmd({ cmd = 'messages' }, { output = true })) + meths.create_user_command("Foo", 'set verbose', {}) eq(" verbose=1", meths.cmd({ cmd = "Foo", mods = { verbose = 1 } }, { output = true })) + meths.create_user_command("Mods", "echo '<mods>'", {}) eq('keepmarks keeppatterns silent 3verbose aboveleft horizontal', meths.cmd({ cmd = "Mods", mods = { @@ -3870,6 +3905,7 @@ describe('API', function() verbose = 3, } }, { output = true })) eq(0, meths.get_option_value("verbose", {})) + command('edit foo.txt | edit bar.txt') eq(' 1 #h "foo.txt" line 1', meths.cmd({ cmd = "buffers", mods = { filter = { pattern = "foo", force = false } } }, @@ -3877,6 +3913,13 @@ describe('API', function() eq(' 2 %a "bar.txt" line 1', meths.cmd({ cmd = "buffers", mods = { filter = { pattern = "foo", force = true } } }, { output = true })) + + -- with emsg_silent = true error is suppresed + feed([[:lua vim.api.nvim_cmd({ cmd = 'call', mods = { emsg_silent = true } }, {})<CR>]]) + eq('', meths.cmd({ cmd = 'messages' }, { output = true })) + -- error from the next command typed is not suppressed #21420 + feed(':call<CR><CR>') + eq('E471: Argument required', meths.cmd({ cmd = 'messages' }, { output = true })) end) it('works with magic.file', function() exec_lua([[ |