refactor: nvim_call_dict_function

- Add test coverage for errors.
- Rename, rearrange.
This commit is contained in:
Justin M. Keyes
2018-05-03 00:20:14 +02:00
parent 124275dd58
commit 19c2ce1901
2 changed files with 75 additions and 73 deletions

View File

@@ -183,23 +183,34 @@ describe('api', 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('Hello, World!', nvim('call_dict_function', 'g:dict_function_dict', 'F', false, {'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('Hi, Moon!', nvim('call_dict_function', 'g:dict_function_dict_i', 'F', true, {'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', {}))
eq('self', nvim('call_dict_function', { result = 'self', G = 'G'}, 'G', false, {}))
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()
it('validates args', function()
command('let g:d={"baz":"zub","meep":[]}')
expect_err('Function not found in dict', request,
'nvim_call_dict_function', 'g:d', 'bogus', true, {1,2})
expect_err('Error calling function.', request,
'nvim_call_dict_function', 'g:d', 'baz', true, {1,2})
expect_err('Value found in dict is not a valid function', request,
'nvim_call_dict_function', 'g:d', 'meep', true, {1,2})
expect_err('Cannot invoke RPC dict as a VimL reference', request,
'nvim_call_dict_function', { f = '' }, 'f', true, {1,2})
expect_err('Invalid %(empty%) function name', request,
'nvim_call_dict_function', "{ 'f': '' }", true, 'f', {1,2})
'nvim_call_dict_function', "{ 'f': '' }", 'f', true, {1,2})
expect_err('dict argument type must be String or Dictionary', request,
'nvim_call_dict_function', 42, 'f', true, {1,2})
expect_err('Failed to evaluate dict expression', request,
'nvim_call_dict_function', 'foo', 'f', true, {1,2})
expect_err('Referenced dict does not exist', request,
'nvim_call_dict_function', '42', 'f', true, {1,2})
end)
end)