diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2017-05-14 07:43:07 +0200 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2018-05-23 18:18:16 +0200 |
commit | 6da4548f0e7ccaf2b3271c0b0d59b5c8869792a7 (patch) | |
tree | 7a6e50a3e6ecff85882d91f0a503a212312ee334 /test/functional/api/vim_spec.lua | |
parent | f1bc152fa081f5d630ea1a027aa5bd00bdbb78f0 (diff) | |
download | rneovim-6da4548f0e7ccaf2b3271c0b0d59b5c8869792a7.tar.gz rneovim-6da4548f0e7ccaf2b3271c0b0d59b5c8869792a7.tar.bz2 rneovim-6da4548f0e7ccaf2b3271c0b0d59b5c8869792a7.zip |
api: list information about all channels/jobs.
Fire autocmd when channel opens or its info changes.
Add a way for API clients can describe themselves.
Diffstat (limited to 'test/functional/api/vim_spec.lua')
-rw-r--r-- | test/functional/api/vim_spec.lua | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 71fa6632c7..1e910b6aa7 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -766,6 +766,115 @@ describe('api', function() end) end) + describe('nvim_list_chans and 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)') + end) + local testinfo = { + stream = 'stdio', + id = 1, + mode = 'rpc', + client = {}, + } + local stderr = { + stream = 'stderr', + id = 2, + mode = 'bytes', + } + + it('returns {} for invalid channel', function() + eq({}, meths.get_chan_info(0)) + eq({}, meths.get_chan_info(-1)) + -- more preallocated numbers might be added, try something high + eq({}, meths.get_chan_info(10)) + end) + + it('works for 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)) + + meths.set_client_info("functionaltests", + {major=0, minor=3, patch=17}, + 'ui', + {do_stuff={n_args={2,3}}}, + {license= 'Apache2'}) + local info = { + stream = 'stdio', + id = 1, + mode = 'rpc', + client = { + name='functionaltests', + version={major=0, minor=3, patch=17}, + type='ui', + methods={do_stuff={n_args={2,3}}}, + attributes={license='Apache2'}, + }, + } + eq({info=info}, meths.get_var("info_event")) + eq({[1]=info, [2]=stderr}, meths.list_chans()) + eq(info, meths.get_chan_info(1)) + end) + + it('works for job channel', function() + if iswin() and os.getenv('APPVEYOR') ~= nil then + pending("jobstart(['cat']) unreliable on appveyor") + return + end + eq(3, eval("jobstart(['cat'], {'rpc': v:true})")) + local info = { + stream='job', + id=3, + mode='rpc', + client={}, + } + eq({info=info}, meths.get_var("opened_event")) + eq({[1]=testinfo,[2]=stderr,[3]=info}, meths.list_chans()) + eq(info, meths.get_chan_info(3)) + eval('rpcrequest(3, "nvim_set_client_info", "cat", {}, "remote",'.. + '{"nvim_command":{"n_args":1}},'.. -- and so on + '{"description":"The Amazing Cat"})') + info = { + stream='job', + id=3, + mode='rpc', + client = { + name='cat', + version={major=0}, + type='remote', + methods={nvim_command={n_args=1}}, + attributes={description="The Amazing Cat"}, + }, + } + eq({info=info}, meths.get_var("info_event")) + eq({[1]=testinfo,[2]=stderr,[3]=info}, meths.list_chans()) + end) + + it('works for :terminal channel', function() + command(":terminal") + eq({id=1}, meths.get_current_buf()) + eq(3, meths.buf_get_option(1, "channel")) + + local info = { + stream='job', + id=3, + mode='terminal', + buffer = 1, + pty='?', + } + local event = meths.get_var("opened_event") + if not iswin() then + info.pty = event.info.pty + neq(nil, string.match(info.pty, "^/dev/")) + end + eq({info=info}, event) + info.buffer = {id=1} + eq({[1]=testinfo,[2]=stderr,[3]=info}, meths.list_chans()) + eq(info, meths.get_chan_info(3)) + end) + end) + describe('nvim_call_atomic', function() it('works', function() meths.buf_set_lines(0, 0, -1, true, {'first'}) |