mirror of
https://github.com/neovim/neovim.git
synced 2026-05-26 23:08:36 +00:00
feat(api): nvim_buf_call, win_call can has multiple return values #39801
from the "because we can and it is not much code" department. (diffcount excluding tests is actually negative) fixes https://github.com/neovim/neovim/issues/39636#issuecomment-4397141270
This commit is contained in:
@@ -2427,4 +2427,75 @@ describe('api/buf', function()
|
||||
eq(false, pcall(api.nvim_buf_del_mark, 99, 'a'))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('nvim_buf_call', function()
|
||||
it('supports multiple returns', function()
|
||||
local curbuf = api.nvim_get_current_buf()
|
||||
local other = api.nvim_create_buf(false, true)
|
||||
exec_lua(function()
|
||||
function with_len(...)
|
||||
return select('#', ...), { ... }
|
||||
end
|
||||
function test(fn)
|
||||
local len, res = with_len(vim.api.nvim_buf_call(other, fn))
|
||||
-- convert to serializable vim.NIL
|
||||
for i = 1, len do
|
||||
if res[i] == nil then
|
||||
res[i] = vim.NIL
|
||||
end
|
||||
end
|
||||
return res
|
||||
end
|
||||
end)
|
||||
|
||||
eq(
|
||||
{ other },
|
||||
exec_lua(function()
|
||||
return test(function()
|
||||
return vim.api.nvim_get_current_buf()
|
||||
end)
|
||||
end)
|
||||
)
|
||||
eq(curbuf, api.nvim_get_current_buf())
|
||||
eq(
|
||||
{ other, vim.NIL },
|
||||
exec_lua(function()
|
||||
return test(function()
|
||||
return vim.api.nvim_get_current_buf(), nil
|
||||
end)
|
||||
end)
|
||||
)
|
||||
|
||||
eq(
|
||||
{ 6, 7 },
|
||||
exec_lua(function()
|
||||
return test(function()
|
||||
return 6, 7
|
||||
end)
|
||||
end)
|
||||
)
|
||||
eq(
|
||||
{ 6, vim.NIL, 7 },
|
||||
exec_lua(function()
|
||||
return test(function()
|
||||
return 6, nil, 7
|
||||
end)
|
||||
end)
|
||||
)
|
||||
eq(
|
||||
{},
|
||||
exec_lua(function()
|
||||
return test(function() end)
|
||||
end)
|
||||
)
|
||||
eq(
|
||||
{ vim.NIL },
|
||||
exec_lua(function()
|
||||
return test(function()
|
||||
return nil
|
||||
end)
|
||||
end)
|
||||
)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user