mirror of
https://github.com/neovim/neovim.git
synced 2024-12-23 20:55:18 -07:00
refactor(tests): get channel id via nvim_get_chan_info #27441
Minor "best practices" nudge.
This commit is contained in:
parent
210ec3b7a9
commit
0185152802
@ -482,7 +482,7 @@ describe('API: buffer events:', function()
|
||||
end)
|
||||
|
||||
it('does not get confused if enabled/disabled many times', function()
|
||||
local channel = api.nvim_get_api_info()[1]
|
||||
local channel = api.nvim_get_chan_info(0).id
|
||||
local b, tick = editoriginal(false)
|
||||
|
||||
-- Enable buffer events many times.
|
||||
@ -564,7 +564,7 @@ describe('API: buffer events:', function()
|
||||
|
||||
-- make sure there are no other pending nvim_buf_lines_event messages going to
|
||||
-- channel 1
|
||||
local channel1 = request(1, 'nvim_get_api_info')[1]
|
||||
local channel1 = request(1, 'nvim_get_chan_info', 0).id
|
||||
eval('rpcnotify(' .. channel1 .. ', "Hello")')
|
||||
wantn(1, 'Hello', {})
|
||||
|
||||
@ -576,14 +576,14 @@ describe('API: buffer events:', function()
|
||||
|
||||
-- make sure there are no other pending nvim_buf_lines_event messages going to
|
||||
-- channel 1
|
||||
channel1 = request(1, 'nvim_get_api_info')[1]
|
||||
channel1 = request(1, 'nvim_get_chan_info', 0).id
|
||||
eval('rpcnotify(' .. channel1 .. ', "Hello Again")')
|
||||
wantn(1, 'Hello Again', {})
|
||||
end)
|
||||
|
||||
it('works with :diffput and :diffget', function()
|
||||
local b1, tick1 = editoriginal(true, { 'AAA', 'BBB' })
|
||||
local channel = api.nvim_get_api_info()[1]
|
||||
local channel = api.nvim_get_chan_info(0).id
|
||||
command('diffthis')
|
||||
command('rightbelow vsplit')
|
||||
local b2, tick2 = open(true, { 'BBB', 'CCC' })
|
||||
@ -700,7 +700,7 @@ describe('API: buffer events:', function()
|
||||
|
||||
it('detaches if the buffer is closed', function()
|
||||
local b, tick = editoriginal(true, { 'AAA' })
|
||||
local channel = api.nvim_get_api_info()[1]
|
||||
local channel = api.nvim_get_chan_info(0).id
|
||||
|
||||
-- Test that buffer events are working.
|
||||
command('normal! x')
|
||||
@ -739,7 +739,7 @@ describe('API: buffer events:', function()
|
||||
|
||||
it(':enew! does not detach hidden buffer', function()
|
||||
local b, tick = editoriginal(true, { 'AAA', 'BBB' })
|
||||
local channel = api.nvim_get_api_info()[1]
|
||||
local channel = api.nvim_get_chan_info(0).id
|
||||
|
||||
command('set undoreload=1 hidden')
|
||||
command('normal! x')
|
||||
@ -753,7 +753,7 @@ describe('API: buffer events:', function()
|
||||
|
||||
it('stays attached if the buffer is hidden', function()
|
||||
local b, tick = editoriginal(true, { 'AAA' })
|
||||
local channel = api.nvim_get_api_info()[1]
|
||||
local channel = api.nvim_get_chan_info(0).id
|
||||
|
||||
-- Test that buffer events are working.
|
||||
command('normal! x')
|
||||
|
@ -14,7 +14,7 @@ describe('notify', function()
|
||||
|
||||
before_each(function()
|
||||
clear()
|
||||
channel = api.nvim_get_api_info()[1]
|
||||
channel = api.nvim_get_chan_info(0).id
|
||||
end)
|
||||
|
||||
after_each(function()
|
||||
|
@ -18,18 +18,18 @@ describe('server -> client', function()
|
||||
|
||||
before_each(function()
|
||||
clear()
|
||||
cid = api.nvim_get_api_info()[1]
|
||||
cid = api.nvim_get_chan_info(0).id
|
||||
end)
|
||||
|
||||
it('handles unexpected closed stream while preparing RPC response', function()
|
||||
source([[
|
||||
let g:_nvim_args = [v:progpath, '--embed', '--headless', '-n', '-u', 'NONE', '-i', 'NONE', ]
|
||||
let ch1 = jobstart(g:_nvim_args, {'rpc': v:true})
|
||||
let child1_ch = rpcrequest(ch1, "nvim_get_api_info")[0]
|
||||
let child1_ch = rpcrequest(ch1, "nvim_get_chan_info", 0).id
|
||||
call rpcnotify(ch1, 'nvim_eval', 'rpcrequest('.child1_ch.', "nvim_get_api_info")')
|
||||
|
||||
let ch2 = jobstart(g:_nvim_args, {'rpc': v:true})
|
||||
let child2_ch = rpcrequest(ch2, "nvim_get_api_info")[0]
|
||||
let child2_ch = rpcrequest(ch2, "nvim_get_chan_info", 0).id
|
||||
call rpcnotify(ch2, 'nvim_eval', 'rpcrequest('.child2_ch.', "nvim_get_api_info")')
|
||||
|
||||
call jobstop(ch1)
|
||||
@ -231,7 +231,7 @@ describe('server -> client', function()
|
||||
describe('jobstart()', function()
|
||||
local jobid
|
||||
before_each(function()
|
||||
local channel = api.nvim_get_api_info()[1]
|
||||
local channel = api.nvim_get_chan_info(0).id
|
||||
api.nvim_set_var('channel', channel)
|
||||
source([[
|
||||
function! s:OnEvent(id, data, event)
|
||||
@ -292,7 +292,7 @@ describe('server -> client', function()
|
||||
ok(id > 0)
|
||||
|
||||
fn.rpcrequest(id, 'nvim_set_current_line', 'hello')
|
||||
local client_id = fn.rpcrequest(id, 'nvim_get_api_info')[1]
|
||||
local client_id = fn.rpcrequest(id, 'nvim_get_chan_info', 0).id
|
||||
|
||||
set_session(server)
|
||||
eq(serverpid, fn.getpid())
|
||||
@ -300,7 +300,7 @@ describe('server -> client', function()
|
||||
|
||||
-- method calls work both ways
|
||||
fn.rpcrequest(client_id, 'nvim_set_current_line', 'howdy!')
|
||||
eq(id, fn.rpcrequest(client_id, 'nvim_get_api_info')[1])
|
||||
eq(id, fn.rpcrequest(client_id, 'nvim_get_chan_info', 0).id)
|
||||
|
||||
set_session(client)
|
||||
eq(clientpid, fn.getpid())
|
||||
@ -378,7 +378,7 @@ describe('server -> client', function()
|
||||
eq('hello', api.nvim_get_current_line())
|
||||
eq(serverpid, fn.rpcrequest(id, 'nvim_eval', 'getpid()'))
|
||||
|
||||
eq(id, fn.rpcrequest(id, 'nvim_get_api_info')[1])
|
||||
eq(id, fn.rpcrequest(id, 'nvim_get_chan_info', 0).id)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
@ -14,7 +14,7 @@ describe('cmdline autocommands', function()
|
||||
local channel
|
||||
before_each(function()
|
||||
clear()
|
||||
channel = api.nvim_get_api_info()[1]
|
||||
channel = api.nvim_get_chan_info(0).id
|
||||
api.nvim_set_var('channel', channel)
|
||||
command("autocmd CmdlineEnter * call rpcnotify(g:channel, 'CmdlineEnter', v:event)")
|
||||
command("autocmd CmdlineLeave * call rpcnotify(g:channel, 'CmdlineLeave', v:event)")
|
||||
|
@ -18,7 +18,7 @@ describe('v:exiting', function()
|
||||
|
||||
before_each(function()
|
||||
helpers.clear()
|
||||
cid = helpers.api.nvim_get_api_info()[1]
|
||||
cid = helpers.api.nvim_get_chan_info(0).id
|
||||
end)
|
||||
|
||||
it('defaults to v:null', function()
|
||||
|
@ -42,7 +42,7 @@ describe('jobs', function()
|
||||
before_each(function()
|
||||
clear()
|
||||
|
||||
channel = api.nvim_get_api_info()[1]
|
||||
channel = api.nvim_get_chan_info(0).id
|
||||
api.nvim_set_var('channel', channel)
|
||||
source([[
|
||||
function! Normalize(data) abort
|
||||
|
@ -14,7 +14,7 @@ describe('Vimscript dictionary notifications', function()
|
||||
|
||||
before_each(function()
|
||||
clear()
|
||||
channel = api.nvim_get_api_info()[1]
|
||||
channel = api.nvim_get_chan_info(0).id
|
||||
api.nvim_set_var('channel', channel)
|
||||
end)
|
||||
|
||||
|
@ -3363,7 +3363,7 @@ describe('lua stdlib', function()
|
||||
|
||||
describe('returns -2 when interrupted', function()
|
||||
before_each(function()
|
||||
local channel = api.nvim_get_api_info()[1]
|
||||
local channel = api.nvim_get_chan_info(0).id
|
||||
api.nvim_set_var('channel', channel)
|
||||
end)
|
||||
|
||||
|
@ -362,7 +362,7 @@ local function function_specs_for(fn, sync, first_arg_factory, init)
|
||||
end
|
||||
|
||||
local function channel()
|
||||
return api.nvim_get_api_info()[1]
|
||||
return api.nvim_get_chan_info(0).id
|
||||
end
|
||||
|
||||
local function host()
|
||||
|
@ -13,7 +13,7 @@ local pcall_err = helpers.pcall_err
|
||||
|
||||
before_each(function()
|
||||
clear()
|
||||
local channel = api.nvim_get_api_info()[1]
|
||||
local channel = api.nvim_get_chan_info(0).id
|
||||
api.nvim_set_var('channel', channel)
|
||||
end)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user