diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2019-08-25 22:01:35 +0200 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2019-10-27 17:23:17 +0100 |
commit | 8ee7c94a92598d46b488b7fe3b1a5cff6b1bf94a (patch) | |
tree | a8f7d0b4fd659c93d2b1470e6ba6ef751eae4de9 /test/functional/lua/utility_functions_spec.lua | |
parent | 19ba36d0e1bb4ef28f8aa92c7386345fbcf78cf2 (diff) | |
download | rneovim-8ee7c94a92598d46b488b7fe3b1a5cff6b1bf94a.tar.gz rneovim-8ee7c94a92598d46b488b7fe3b1a5cff6b1bf94a.tar.bz2 rneovim-8ee7c94a92598d46b488b7fe3b1a5cff6b1bf94a.zip |
lua: add vim.fn.{func} for direct access to vimL function
compared to vim.api.|nvim_call_function|, this fixes some typing issues
due to the indirect conversion via the API. float values are preserved
as such (fixes #9389) as well as empty dicts/arrays.
Ref https://github.com/norcalli/nvim.lua for the call syntax
Diffstat (limited to 'test/functional/lua/utility_functions_spec.lua')
-rw-r--r-- | test/functional/lua/utility_functions_spec.lua | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/functional/lua/utility_functions_spec.lua b/test/functional/lua/utility_functions_spec.lua index a51334398c..0b789e84b0 100644 --- a/test/functional/lua/utility_functions_spec.lua +++ b/test/functional/lua/utility_functions_spec.lua @@ -10,6 +10,7 @@ local feed = helpers.feed local pcall_err = helpers.pcall_err local exec_lua = helpers.exec_lua local matches = helpers.matches +local source = helpers.source before_each(clear) @@ -299,4 +300,31 @@ describe('lua stdlib', function() eq("Error executing lua: .../shared.lua: Expected string, got number", pcall_err(exec_lua, [[return vim.pesc(2)]])) end) + + it('vim.call and vim.fn', function() + eq(true, exec_lua([[return vim.call('sin', 0.0) == 0.0 ]])) + eq(true, exec_lua([[return vim.fn.sin(0.0) == 0.0 ]])) + -- compat: nvim_call_function uses "special" value for vimL float + eq(false, exec_lua([[return vim.api.nvim_call_function('sin', {0.0}) == 0.0 ]])) + + source([[ + func! FooFunc(test) + let g:test = a:test + return {} + endfunc + func! VarArg(...) + return a:000 + endfunc + ]]) + eq(true, exec_lua([[return next(vim.fn.FooFunc(3)) == nil ]])) + eq(3, eval("g:test")) + -- compat: nvim_call_function uses "special" value for empty dict + eq(true, exec_lua([[return next(vim.api.nvim_call_function("FooFunc", {5})) == true ]])) + eq(5, eval("g:test")) + + eq({2, "foo", true}, exec_lua([[return vim.fn.VarArg(2, "foo", true)]])) + + -- error handling + eq({false, 'Vim:E714: List required'}, exec_lua([[return {pcall(vim.fn.add, "aa", "bb")}]])) + end) end) |