diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/api/autocmd_spec.lua | 38 | ||||
-rw-r--r-- | test/functional/api/vim_spec.lua | 20 | ||||
-rw-r--r-- | test/old/testdir/test_listdict.vim | 6 | ||||
-rw-r--r-- | test/old/testdir/test_match.vim | 5 |
4 files changed, 66 insertions, 3 deletions
diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index e5412a8e99..d2ec3a576c 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -355,6 +355,44 @@ describe('autocmd api', function() test({ 'list' }) test({ foo = 'bar' }) end) + + it('function in arbitrary data is passed to all autocmds #28353', function() + eq( + 1303, + exec_lua([[ + local res = 1 + + local fun = function(m, x) + res = res * m + x + end + + local group = vim.api.nvim_create_augroup('MyTest', { clear = false }) + + vim.api.nvim_create_autocmd('User', { + group = group, + callback = function(payload) + payload.data.fun(10, payload.data.x) + end, + pattern = 'MyEvent', + }) + vim.api.nvim_create_autocmd('User', { + group = group, + callback = function(payload) + payload.data.fun(100, payload.data.x) + end, + pattern = 'MyEvent', + }) + + vim.api.nvim_exec_autocmds('User', { + group = group, + pattern = 'MyEvent', + data = { x = 3, fun = fun }, + }) + + return res + ]]) + ) + end) end) describe('nvim_get_autocmds', function() diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 4e9a42f11d..c412773482 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -559,6 +559,16 @@ describe('API', function() eq('Vim:E121: Undefined variable: bogus', pcall_err(request, 'nvim_eval', 'bogus expression')) eq('', eval('v:errmsg')) -- v:errmsg was not updated. end) + + it('can return Lua function to Lua code', function() + eq( + [["a string with \"double quotes\" and 'single quotes'"]], + exec_lua([=[ + local fun = vim.api.nvim_eval([[luaeval('string.format')]]) + return fun('%q', [[a string with "double quotes" and 'single quotes']]) + ]=]) + ) + end) end) describe('nvim_call_function', function() @@ -624,6 +634,16 @@ describe('API', function() pcall_err(request, 'nvim_call_function', 'Foo', too_many_args) ) end) + + it('can return Lua function to Lua code', function() + eq( + [["a string with \"double quotes\" and 'single quotes'"]], + exec_lua([=[ + local fun = vim.api.nvim_call_function('luaeval', { 'string.format' }) + return fun('%q', [[a string with "double quotes" and 'single quotes']]) + ]=]) + ) + end) end) describe('nvim_call_dict_function', function() diff --git a/test/old/testdir/test_listdict.vim b/test/old/testdir/test_listdict.vim index 649d5f5c6c..0adc3286f9 100644 --- a/test/old/testdir/test_listdict.vim +++ b/test/old/testdir/test_listdict.vim @@ -1441,4 +1441,10 @@ func Test_indexof() delfunc TestIdx endfunc +func Test_extendnew_leak() + " This used to leak memory + for i in range(100) | silent! call extendnew([], [], []) | endfor + for i in range(100) | silent! call extendnew({}, {}, {}) | endfor +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/test/old/testdir/test_match.vim b/test/old/testdir/test_match.vim index 1cb52b8b2a..ddf032d593 100644 --- a/test/old/testdir/test_match.vim +++ b/test/old/testdir/test_match.vim @@ -310,6 +310,7 @@ func Test_matchaddpos_error() " call assert_fails("call matchaddpos('Error', [{}])", 'E290:') call assert_fails("call matchaddpos('Error', [{}])", 'E5031:') call assert_equal(-1, matchaddpos('Error', v:_null_list)) + call assert_equal(-1, matchaddpos('Error', [])) call assert_fails("call matchaddpos('Error', [1], [], 1)", 'E745:') endfunc @@ -427,13 +428,11 @@ func Test_match_tab_with_linebreak() call setline(1, "\tix") call matchadd('ErrorMsg', '\t') END - call writefile(lines, 'XscriptMatchTabLinebreak') + call writefile(lines, 'XscriptMatchTabLinebreak', 'D') let buf = RunVimInTerminal('-S XscriptMatchTabLinebreak', #{rows: 10}) call VerifyScreenDump(buf, 'Test_match_tab_linebreak', {}) call StopVimInTerminal(buf) - call delete('XscriptMatchTabLinebreak') endfunc - " vim: shiftwidth=2 sts=2 expandtab |