diff options
Diffstat (limited to 'test/functional/api/vim_spec.lua')
-rw-r--r-- | test/functional/api/vim_spec.lua | 85 |
1 files changed, 72 insertions, 13 deletions
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 91d2745130..ffef6a6066 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1,6 +1,8 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') +local fmt = string.format +local assert_alive = helpers.assert_alive local NIL = helpers.NIL local clear, nvim, eq, neq = helpers.clear, helpers.nvim, helpers.eq, helpers.neq local command = helpers.command @@ -57,7 +59,7 @@ describe('API', function() eq({'notification', 'nvim_error_event', {error_types.Exception.id, 'Invalid method: nvim_bogus'}}, next_msg()) -- error didn't close channel. - eq(2, eval('1+1')) + assert_alive() end) it('failed async request emits nvim_error_event', function() @@ -67,7 +69,7 @@ describe('API', function() {error_types.Exception.id, 'Vim:E492: Not an editor command: bogus'}}, next_msg()) -- error didn't close channel. - eq(2, eval('1+1')) + assert_alive() end) it('does not set CA_COMMAND_BUSY #7254', function() @@ -115,6 +117,19 @@ describe('API', function() nvim('exec','autocmd BufAdd * :let x1 = "Hello"', false) nvim('command', 'new foo') eq('Hello', request('nvim_eval', 'g:x1')) + + -- Line continuations + nvim('exec', [[ + let abc = #{ + \ a: 1, + "\ b: 2, + \ c: 3 + \ }]], false) + eq({a = 1, c = 3}, request('nvim_eval', 'g:abc')) + + -- 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')) end) it('non-ASCII input', function() @@ -518,7 +533,7 @@ describe('API', function() nvim("notify", "hello world", 2, {}) end) - it('can be overriden', function() + it('can be overridden', function() command("lua vim.notify = function(...) return 42 end") eq(42, meths.exec_lua("return vim.notify('Hello world')", {})) nvim("notify", "hello world", 4, {}) @@ -1326,10 +1341,10 @@ describe('API', function() end) end) - describe('nvim_list_chans and nvim_get_chan_info', function() + describe('nvim_list_chans, nvim_get_chan_info', function() before_each(function() - command('autocmd ChanOpen * let g:opened_event = copy(v:event)') - command('autocmd ChanInfo * let g:info_event = copy(v:event)') + command('autocmd ChanOpen * let g:opened_event = deepcopy(v:event)') + command('autocmd ChanInfo * let g:info_event = deepcopy(v:event)') end) local testinfo = { stream = 'stdio', @@ -1350,7 +1365,7 @@ describe('API', function() eq({}, meths.get_chan_info(10)) end) - it('works for stdio channel', function() + it('stream=stdio channel', function() eq({[1]=testinfo,[2]=stderr}, meths.list_chans()) eq(testinfo, meths.get_chan_info(1)) eq(stderr, meths.get_chan_info(2)) @@ -1377,11 +1392,13 @@ describe('API', function() eq(info, meths.get_chan_info(1)) end) - it('works for job channel', function() + it('stream=job channel', function() eq(3, eval("jobstart(['cat'], {'rpc': v:true})")) + local catpath = eval('exepath("cat")') local info = { stream='job', id=3, + argv={ catpath }, mode='rpc', client={}, } @@ -1394,6 +1411,7 @@ describe('API', function() info = { stream='job', id=3, + argv={ catpath }, mode='rpc', client = { name='amazing-cat', @@ -1410,14 +1428,15 @@ describe('API', function() pcall_err(eval, 'rpcrequest(3, "nvim_set_current_buf", -1)')) end) - it('works for :terminal channel', function() - command(":terminal") + it('stream=job :terminal channel', function() + command(':terminal') eq({id=1}, meths.get_current_buf()) - eq(3, meths.buf_get_option(1, "channel")) + eq(3, meths.buf_get_option(1, 'channel')) local info = { stream='job', id=3, + argv={ eval('exepath(&shell)') }, mode='terminal', buffer = 1, pty='?', @@ -1431,6 +1450,38 @@ describe('API', function() info.buffer = {id=1} eq({[1]=testinfo,[2]=stderr,[3]=info}, meths.list_chans()) eq(info, meths.get_chan_info(3)) + + -- :terminal with args + running process. + command(':exe "terminal" shellescape(v:progpath) "-u NONE -i NONE"') + eq(-1, eval('jobwait([&channel], 0)[0]')) -- Running? + local expected2 = { + stream = 'job', + id = 4, + argv = ( + iswin() and { + eval('&shell'), + '/s', + '/c', + fmt('"%s -u NONE -i NONE"', eval('shellescape(v:progpath)')), + } or { + eval('&shell'), + eval('&shellcmdflag'), + fmt('%s -u NONE -i NONE', eval('shellescape(v:progpath)')), + } + ), + mode = 'terminal', + buffer = 2, + pty = '?', + } + local actual2 = eval('nvim_get_chan_info(&channel)') + expected2.pty = actual2.pty + eq(expected2, actual2) + + -- :terminal with args + stopped process. + eq(1, eval('jobstop(&channel)')) + eval('jobwait([&channel], 1000)') -- Wait. + expected2.pty = (iswin() and '?' or '') -- pty stream was closed. + eq(expected2, eval('nvim_get_chan_info(&channel)')) end) end) @@ -1540,7 +1591,10 @@ describe('API', function() eq({'a', '', 'b'}, meths.list_runtime_paths()) meths.set_option('runtimepath', ',a,b') eq({'', 'a', 'b'}, meths.list_runtime_paths()) + -- trailing , is ignored, use ,, if you really really want $CWD meths.set_option('runtimepath', 'a,b,') + eq({'a', 'b'}, meths.list_runtime_paths()) + meths.set_option('runtimepath', 'a,b,,') eq({'a', 'b', ''}, meths.list_runtime_paths()) end) it('truncates too long paths', function() @@ -1961,8 +2015,13 @@ describe('API', function() ok(endswith(val[1], p"autoload/remote/define.vim") or endswith(val[1], p"autoload/remote/host.vim")) - eq({}, meths.get_runtime_file("lua", true)) - eq({}, meths.get_runtime_file("lua/vim", true)) + val = meths.get_runtime_file("lua", true) + eq(1, #val) + ok(endswith(val[1], p"lua")) + + val = meths.get_runtime_file("lua/vim", true) + eq(1, #val) + ok(endswith(val[1], p"lua/vim")) end) it('can find directories', function() |