diff options
author | ZyX <kp-pav@yandex.ru> | 2015-09-27 02:49:48 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2015-10-08 22:01:12 +0300 |
commit | 1162962d8beaab6be78a32954600205686f5d09b (patch) | |
tree | b08c4f7a92e4f3f254daad372778aa06d8e41268 /test/functional/helpers.lua | |
parent | 9d72f8ebaa6a30cdf32d538ad5cb7605dd88b1fe (diff) | |
download | rneovim-1162962d8beaab6be78a32954600205686f5d09b.tar.gz rneovim-1162962d8beaab6be78a32954600205686f5d09b.tar.bz2 rneovim-1162962d8beaab6be78a32954600205686f5d09b.zip |
functests: Refactor tests:
- Remove unused variables.
- Do not use helpers.nvim_feed in most cases.
- Do not use helpers.nvim and helpers.nvim_eval at all.
- Add helpers.funcs and helpers.\*meths special tables. Indexing such table
creates functions which call helpers.call or helpers.nvim (and similar) with
first argument equal to table index.
Diffstat (limited to 'test/functional/helpers.lua')
-rw-r--r-- | test/functional/helpers.lua | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 79f1feb7b5..a62f7a3d00 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -359,6 +359,38 @@ local exc_exec = function(cmd) return ret end +local function redir_exec(cmd) + nvim_command(([[ + redir => g:__output + silent! execute "%s" + redir END + ]]):format(cmd:gsub('\n', '\\n'):gsub('[\\"]', '\\%0'))) + local ret = nvim_eval('get(g:, "__output", 0)') + nvim_command('unlet! g:__output') + return ret +end + +local function create_callindex(func) + local tbl = {} + setmetatable(tbl, { + __index = function(tbl, arg1) + ret = function(...) return func(arg1, ...) end + tbl[arg1] = ret + return ret + end, + }) + return tbl +end + +local funcs = create_callindex(nvim_call) +local meths = create_callindex(nvim) +local bufmeths = create_callindex(buffer) +local winmeths = create_callindex(window) +local tabmeths = create_callindex(tabpage) +local curbufmeths = create_callindex(curbuf) +local curwinmeths = create_callindex(curwin) +local curtabmeths = create_callindex(curtab) + return { prepend_argv = prepend_argv, clear = clear, @@ -397,5 +429,14 @@ return { rmdir = rmdir, mkdir = lfs.mkdir, exc_exec = exc_exec, + redir_exec = redir_exec, merge_args = merge_args, + funcs = funcs, + meths = meths, + bufmeths = bufmeths, + winmeths = winmeths, + tabmeths = tabmeths, + curbufmeths = curbufmeths, + curwinmeths = curwinmeths, + curtabmeths = curtabmeths, } |