diff options
author | Lewis Russell <lewis6991@gmail.com> | 2024-01-12 19:40:58 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-12 19:40:58 +0000 |
commit | 07a7c0ec999102f223a6aca17e93d33e18c02b94 (patch) | |
tree | 221ea513b45596f8e63035955494167fc20bf826 /test/functional/api/server_requests_spec.lua | |
parent | 7f249936a989dbc21ad03e394197afc07cb9c0bf (diff) | |
parent | 795f896a5772d5e0795f86642bdf90c82efac45c (diff) | |
download | rneovim-07a7c0ec999102f223a6aca17e93d33e18c02b94.tar.gz rneovim-07a7c0ec999102f223a6aca17e93d33e18c02b94.tar.bz2 rneovim-07a7c0ec999102f223a6aca17e93d33e18c02b94.zip |
Merge pull request #26994 from lewis6991/vimhelpers
test: big cleanup
Diffstat (limited to 'test/functional/api/server_requests_spec.lua')
-rw-r--r-- | test/functional/api/server_requests_spec.lua | 106 |
1 files changed, 53 insertions, 53 deletions
diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua index 421e0b5c9a..5e508e7513 100644 --- a/test/functional/api/server_requests_spec.lua +++ b/test/functional/api/server_requests_spec.lua @@ -2,12 +2,12 @@ -- `rpcrequest` calls we need the client event loop to be running. local helpers = require('test.functional.helpers')(after_each) -local clear, nvim, eval = helpers.clear, helpers.nvim, helpers.eval +local clear, eval = helpers.clear, helpers.eval local eq, neq, run, stop = helpers.eq, helpers.neq, helpers.run, helpers.stop -local nvim_prog, command, funcs = helpers.nvim_prog, helpers.command, helpers.funcs +local nvim_prog, command, fn = helpers.nvim_prog, helpers.command, helpers.fn local source, next_msg = helpers.source, helpers.next_msg local ok = helpers.ok -local meths = helpers.meths +local api = helpers.api local spawn, merge_args = helpers.spawn, helpers.merge_args local set_session = helpers.set_session local pcall_err = helpers.pcall_err @@ -18,7 +18,7 @@ describe('server -> client', function() before_each(function() clear() - cid = nvim('get_api_info')[1] + cid = api.nvim_get_api_info()[1] end) it('handles unexpected closed stream while preparing RPC response', function() @@ -47,7 +47,7 @@ describe('server -> client', function() local function on_request(method, args) eq('scall', method) eq({ 1, 2, 3 }, args) - nvim('command', 'let g:result = [4, 5, 6]') + command('let g:result = [4, 5, 6]') return eval('g:result') end run(on_request, nil, on_setup) @@ -77,15 +77,15 @@ describe('server -> client', function() describe('recursive call', function() it('works', function() local function on_setup() - nvim('set_var', 'result1', 0) - nvim('set_var', 'result2', 0) - nvim('set_var', 'result3', 0) - nvim('set_var', 'result4', 0) - nvim('command', 'let g:result1 = rpcrequest(' .. cid .. ', "rcall", 2)') - eq(4, nvim('get_var', 'result1')) - eq(8, nvim('get_var', 'result2')) - eq(16, nvim('get_var', 'result3')) - eq(32, nvim('get_var', 'result4')) + api.nvim_set_var('result1', 0) + api.nvim_set_var('result2', 0) + api.nvim_set_var('result3', 0) + api.nvim_set_var('result4', 0) + command('let g:result1 = rpcrequest(' .. cid .. ', "rcall", 2)') + eq(4, api.nvim_get_var('result1')) + eq(8, api.nvim_get_var('result2')) + eq(16, api.nvim_get_var('result3')) + eq(32, api.nvim_get_var('result4')) stop() end @@ -101,7 +101,7 @@ describe('server -> client', function() elseif n == 16 then cmd = 'let g:result4 = rpcrequest(' .. cid .. ', "rcall", ' .. n .. ')' end - nvim('command', cmd) + command(cmd) end return n end @@ -113,12 +113,12 @@ describe('server -> client', function() it('does not delay notifications during pending request', function() local received = false local function on_setup() - eq('retval', funcs.rpcrequest(cid, 'doit')) + eq('retval', fn.rpcrequest(cid, 'doit')) stop() end local function on_request(method) if method == 'doit' then - funcs.rpcnotify(cid, 'headsup') + fn.rpcnotify(cid, 'headsup') eq(true, received) return 'retval' end @@ -195,10 +195,10 @@ describe('server -> client', function() end) it('can send/receive notifications and make requests', function() - nvim('command', "call rpcnotify(vim, 'vim_set_current_line', 'SOME TEXT')") + command("call rpcnotify(vim, 'vim_set_current_line', 'SOME TEXT')") -- Wait for the notification to complete. - nvim('command', "call rpcrequest(vim, 'vim_eval', '0')") + command("call rpcrequest(vim, 'vim_eval', '0')") eq('SOME TEXT', eval("rpcrequest(vim, 'vim_get_current_line')")) end) @@ -212,7 +212,7 @@ describe('server -> client', function() eq(1, buf) eval("rpcnotify(vim, 'buffer_set_line', " .. buf .. ", 0, 'SOME TEXT')") - nvim('command', "call rpcrequest(vim, 'vim_eval', '0')") -- wait + command("call rpcrequest(vim, 'vim_eval', '0')") -- wait eq('SOME TEXT', eval("rpcrequest(vim, 'buffer_get_line', " .. buf .. ', 0)')) @@ -231,8 +231,8 @@ describe('server -> client', function() describe('jobstart()', function() local jobid before_each(function() - local channel = nvim('get_api_info')[1] - nvim('set_var', 'channel', channel) + local channel = api.nvim_get_api_info()[1] + api.nvim_set_var('channel', channel) source([[ function! s:OnEvent(id, data, event) call rpcnotify(g:channel, a:event, 0, a:data) @@ -244,7 +244,7 @@ describe('server -> client', function() \ 'rpc': v:true \ } ]]) - meths.set_var('args', { + api.nvim_set_var('args', { nvim_prog, '-ll', 'test/functional/api/rpc_fixture.lua', @@ -256,7 +256,7 @@ describe('server -> client', function() end) after_each(function() - pcall(funcs.jobstop, jobid) + pcall(fn.jobstop, jobid) end) if helpers.skip(helpers.is_os('win')) then @@ -264,16 +264,16 @@ describe('server -> client', function() end it('rpc and text stderr can be combined', function() - local status, rv = pcall(funcs.rpcrequest, jobid, 'poll') + local status, rv = pcall(fn.rpcrequest, jobid, 'poll') if not status then error(string.format('missing nvim Lua module? (%s)', rv)) end eq('ok', rv) - funcs.rpcnotify(jobid, 'ping') + fn.rpcnotify(jobid, 'ping') eq({ 'notification', 'pong', {} }, next_msg()) - eq('done!', funcs.rpcrequest(jobid, 'write_stderr', 'fluff\n')) + eq('done!', fn.rpcrequest(jobid, 'write_stderr', 'fluff\n')) eq({ 'notification', 'stderr', { 0, { 'fluff', '' } } }, next_msg()) - pcall(funcs.rpcrequest, jobid, 'exit') + pcall(fn.rpcrequest, jobid, 'exit') eq({ 'notification', 'stderr', { 0, { '' } } }, next_msg()) eq({ 'notification', 'exit', { 0, 0 } }, next_msg()) end) @@ -282,29 +282,29 @@ describe('server -> client', function() describe('connecting to another (peer) nvim', function() local nvim_argv = merge_args(helpers.nvim_argv, { '--headless' }) local function connect_test(server, mode, address) - local serverpid = funcs.getpid() + local serverpid = fn.getpid() local client = spawn(nvim_argv, false, nil, true) set_session(client) - local clientpid = funcs.getpid() + local clientpid = fn.getpid() neq(serverpid, clientpid) - local id = funcs.sockconnect(mode, address, { rpc = true }) + local id = fn.sockconnect(mode, address, { rpc = true }) ok(id > 0) - funcs.rpcrequest(id, 'nvim_set_current_line', 'hello') - local client_id = funcs.rpcrequest(id, 'nvim_get_api_info')[1] + fn.rpcrequest(id, 'nvim_set_current_line', 'hello') + local client_id = fn.rpcrequest(id, 'nvim_get_api_info')[1] set_session(server) - eq(serverpid, funcs.getpid()) - eq('hello', meths.get_current_line()) + eq(serverpid, fn.getpid()) + eq('hello', api.nvim_get_current_line()) -- method calls work both ways - funcs.rpcrequest(client_id, 'nvim_set_current_line', 'howdy!') - eq(id, funcs.rpcrequest(client_id, 'nvim_get_api_info')[1]) + fn.rpcrequest(client_id, 'nvim_set_current_line', 'howdy!') + eq(id, fn.rpcrequest(client_id, 'nvim_get_api_info')[1]) set_session(client) - eq(clientpid, funcs.getpid()) - eq('howdy!', meths.get_current_line()) + eq(clientpid, fn.getpid()) + eq('howdy!', api.nvim_get_current_line()) server:close() client:close() @@ -313,7 +313,7 @@ describe('server -> client', function() it('via named pipe', function() local server = spawn(nvim_argv) set_session(server) - local address = funcs.serverlist()[1] + local address = fn.serverlist()[1] local first = string.sub(address, 1, 1) ok(first == '/' or first == '\\') connect_test(server, 'pipe', address) @@ -322,7 +322,7 @@ describe('server -> client', function() it('via ipv4 address', function() local server = spawn(nvim_argv) set_session(server) - local status, address = pcall(funcs.serverstart, '127.0.0.1:') + local status, address = pcall(fn.serverstart, '127.0.0.1:') if not status then pending('no ipv4 stack') end @@ -333,7 +333,7 @@ describe('server -> client', function() it('via ipv6 address', function() local server = spawn(nvim_argv) set_session(server) - local status, address = pcall(funcs.serverstart, '::1:') + local status, address = pcall(fn.serverstart, '::1:') if not status then pending('no ipv6 stack') end @@ -344,7 +344,7 @@ describe('server -> client', function() it('via hostname', function() local server = spawn(nvim_argv) set_session(server) - local address = funcs.serverstart('localhost:') + local address = fn.serverstart('localhost:') eq('localhost:', string.sub(address, 1, 10)) connect_test(server, 'tcp', address) end) @@ -352,12 +352,12 @@ describe('server -> client', function() it('does not crash on receiving UI events', function() local server = spawn(nvim_argv) set_session(server) - local address = funcs.serverlist()[1] + local address = fn.serverlist()[1] local client = spawn(nvim_argv, false, nil, true) set_session(client) - local id = funcs.sockconnect('pipe', address, { rpc = true }) - funcs.rpcrequest(id, 'nvim_ui_attach', 80, 24, {}) + local id = fn.sockconnect('pipe', address, { rpc = true }) + fn.rpcrequest(id, 'nvim_ui_attach', 80, 24, {}) assert_alive() server:close() @@ -367,18 +367,18 @@ describe('server -> client', function() describe('connecting to its own pipe address', function() it('does not deadlock', function() - local address = funcs.serverlist()[1] + local address = fn.serverlist()[1] local first = string.sub(address, 1, 1) ok(first == '/' or first == '\\') - local serverpid = funcs.getpid() + local serverpid = fn.getpid() - local id = funcs.sockconnect('pipe', address, { rpc = true }) + local id = fn.sockconnect('pipe', address, { rpc = true }) - funcs.rpcrequest(id, 'nvim_set_current_line', 'hello') - eq('hello', meths.get_current_line()) - eq(serverpid, funcs.rpcrequest(id, 'nvim_eval', 'getpid()')) + fn.rpcrequest(id, 'nvim_set_current_line', 'hello') + eq('hello', api.nvim_get_current_line()) + eq(serverpid, fn.rpcrequest(id, 'nvim_eval', 'getpid()')) - eq(id, funcs.rpcrequest(id, 'nvim_get_api_info')[1]) + eq(id, fn.rpcrequest(id, 'nvim_get_api_info')[1]) end) end) end) |