API: nvim_call_dict_function #3032

This commit is contained in:
Sebastian Witte
2018-05-02 23:38:18 +02:00
committed by Justin M. Keyes
parent f46f138fb6
commit 124275dd58
2 changed files with 137 additions and 7 deletions

View File

@@ -4,17 +4,19 @@ local global_helpers = require('test.helpers')
local NIL = helpers.NIL
local clear, nvim, eq, neq = helpers.clear, helpers.nvim, helpers.eq, helpers.neq
local command = helpers.command
local funcs = helpers.funcs
local iswin = helpers.iswin
local meth_pcall = helpers.meth_pcall
local meths = helpers.meths
local ok, nvim_async, feed = helpers.ok, helpers.nvim_async, helpers.feed
local os_name = helpers.os_name
local meths = helpers.meths
local funcs = helpers.funcs
local request = helpers.request
local meth_pcall = helpers.meth_pcall
local command = helpers.command
local iswin = helpers.iswin
local source = helpers.source
local intchar2lua = global_helpers.intchar2lua
local expect_err = global_helpers.expect_err
local format_string = global_helpers.format_string
local intchar2lua = global_helpers.intchar2lua
local mergedicts_copy = global_helpers.mergedicts_copy
describe('api', function()
@@ -177,6 +179,30 @@ describe('api', function()
end)
end)
describe('nvim_call_dict_function', function()
it('invokes VimL dict', function()
source('function! F(name) dict\n return self.greeting . ", " . a:name . "!"\nendfunction')
nvim('set_var', 'dict_function_dict', { greeting = 'Hello', F = 'function("F")' })
eq('Hello, World!', nvim('call_dict_function', 'g:dict_function_dict', false, 'F', {'World'}))
eq({ greeting = 'Hello', F = 'function("F")' }, nvim('get_var', 'dict_function_dict'))
nvim('set_var', 'dict_function_dict_i', { greeting = 'Hi', F = "F" })
eq('Hi, Moon!', nvim('call_dict_function', 'g:dict_function_dict_i', true, 'F', {'Moon'}))
eq({ greeting = 'Hi', F = "F" }, nvim('get_var', 'dict_function_dict_i'))
end)
it('invokes RPC dict', function()
source('function! G() dict\n return self.result\nendfunction')
eq('self', nvim('call_dict_function', { result = 'self', G = 'G'}, false, 'G', {}))
end)
it('fails for a RPC dictionary and internal set to true', function()
expect_err('Funcrefs are not supported for RPC dicts', request,
'nvim_call_dict_function', { f = '' }, true, 'f', {1,2})
end)
it('fails with empty function name', function()
expect_err('Invalid %(empty%) function name', request,
'nvim_call_dict_function', "{ 'f': '' }", true, 'f', {1,2})
end)
end)
describe('nvim_execute_lua', function()
it('works', function()
meths.execute_lua('vim.api.nvim_set_var("test", 3)', {})