From 0c2ec77ae0c0bde70b168313f89fa3259682a056 Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Wed, 8 Oct 2014 13:56:01 -0300 Subject: test: Use lua to perform sanity API checks Sanity API checks made by the python-client in the api-python travis target were converted to lua and will now live in this repository. This will simplify performing breaking changes to the API as it won't be necessary to send parallel PRs the python-client. --- test/functional/api/server_requests_spec.lua | 68 ++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 test/functional/api/server_requests_spec.lua (limited to 'test/functional/api/server_requests_spec.lua') diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua new file mode 100644 index 0000000000..b6f56a868c --- /dev/null +++ b/test/functional/api/server_requests_spec.lua @@ -0,0 +1,68 @@ +-- Tests for some server->client RPC scenarios. Note that unlike with +-- `rpcnotify`, to evaluate `rpcrequest` calls we need the client event loop to +-- be running. +local helpers = require('test.functional.helpers') +local clear, nvim, eval, eq, run, stop = helpers.clear, helpers.nvim, + helpers.eval, helpers.eq, helpers.run, helpers.stop + + +describe('server -> client', function() + local cid + + before_each(function() + clear() + cid = nvim('get_api_info')[1] + end) + + describe('simple call', function() + it('works', function() + local function on_setup() + eq({4, 5, 6}, eval('rpcrequest('..cid..', "scall", 1, 2, 3)')) + stop() + end + + local function on_request(method, args) + eq('scall', method) + eq({1, 2, 3}, args) + nvim('command', 'let g:result = [4, 5, 6]') + return eval('g:result') + end + run(on_request, nil, on_setup) + end) + end) + + 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')) + stop() + end + + local function on_request(method, args) + eq('rcall', method) + local n = unpack(args) * 2 + if n <= 16 then + local cmd + if n == 4 then + cmd = 'let g:result2 = rpcrequest('..cid..', "rcall", '..n..')' + elseif n == 8 then + cmd = 'let g:result3 = rpcrequest('..cid..', "rcall", '..n..')' + elseif n == 16 then + cmd = 'let g:result4 = rpcrequest('..cid..', "rcall", '..n..')' + end + nvim('command', cmd) + end + return n + end + run(on_request, nil, on_setup) + end) + end) +end) -- cgit