diff options
author | Thiago de Arruda <tpadilha84@gmail.com> | 2014-10-08 13:56:01 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-10-16 14:06:54 -0300 |
commit | 0c2ec77ae0c0bde70b168313f89fa3259682a056 (patch) | |
tree | 8ae4c703deff5a369cd35c7580351e320faa6d93 /test/functional/helpers.lua | |
parent | 69561ea922ae6789703c06cbc245929d7c625db9 (diff) | |
download | rneovim-0c2ec77ae0c0bde70b168313f89fa3259682a056.tar.gz rneovim-0c2ec77ae0c0bde70b168313f89fa3259682a056.tar.bz2 rneovim-0c2ec77ae0c0bde70b168313f89fa3259682a056.zip |
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.
Diffstat (limited to 'test/functional/helpers.lua')
-rw-r--r-- | test/functional/helpers.lua | 83 |
1 files changed, 80 insertions, 3 deletions
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 6aa78804e7..324af6a232 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -24,13 +24,15 @@ if os.getenv('VALGRIND') then end local session -do + +local function restart() local loop = Loop.new() local msgpack_stream = MsgpackStream.new(loop) local async_session = AsyncSession.new(msgpack_stream) session = Session.new(async_session) loop:spawn(nvim_argv) end +restart() local function request(method, ...) local status, rv = session:request(method, ...) @@ -40,6 +42,18 @@ local function request(method, ...) return rv end +local function next_message() + return session:next_message() +end + +local function run(request_cb, notification_cb, setup_cb) + session:run(request_cb, notification_cb, setup_cb) +end + +local function stop() + session:stop() +end + local function nvim_command(cmd) request('vim_command', cmd) end @@ -141,7 +155,7 @@ local function neq(expected, actual) end local function expect(contents, first, last, buffer_index) - return eq(dedent(contents), buffer_slice(first, last, buffer_idx)) + return eq(dedent(contents), buffer_slice(first, last, buffer_index)) end rawfeed([[:function BeforeEachTest() @@ -182,14 +196,77 @@ rawfeed([[:function BeforeEachTest() endfunction ]]) + +local function ok(expr) + assert.is_true(expr) +end + +local function nvim(method, ...) + return request('vim_'..method, ...) +end + +local function buffer(method, ...) + return request('buffer_'..method, ...) +end + +local function window(method, ...) + return request('window_'..method, ...) +end + +local function tabpage(method, ...) + return request('tabpage_'..method, ...) +end + +local function curbuf(method, ...) + local buf = nvim('get_current_buffer') + if not method then + return buf + end + return buffer(method, buf, ...) +end + +local function curbuf_contents() + return table.concat(curbuf('get_line_slice', 0, -1, true, true), '\n') +end + +local function curwin(method, ...) + local win = nvim('get_current_window') + if not method then + return win + end + return window(method, win, ...) +end + +local function curtab(method, ...) + local tab = nvim('get_current_tabpage') + if not method then + return tab + end + return tabpage(method, tab, ...) +end + return { clear = clear, + restart = restart, rawfeed = rawfeed, insert = insert, feed = feed, execute = execute, eval = eval, + request = request, + next_message = next_message, + run = run, + stop = stop, eq = eq, neq = neq, - expect = expect + expect = expect, + ok = ok, + nvim = nvim, + buffer = buffer, + window = window, + tabpage = tabpage, + curbuf = curbuf, + curwin = curwin, + curtab = curtab, + curbuf_contents = curbuf_contents } |