test: API can return Lua function to Lua code (#28380)

This commit is contained in:
zeertzjq 2024-04-17 06:34:10 +08:00 committed by GitHub
parent f150b62423
commit 329fc0e5b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 2 deletions

View File

@ -76,8 +76,7 @@ static Object typval_cbuf_to_obj(EncodedData *edata, const char *data, size_t le
do { \ do { \
ufunc_T *fp = find_func(fun); \ ufunc_T *fp = find_func(fun); \
if (fp != NULL && (fp->uf_flags & FC_LUAREF)) { \ if (fp != NULL && (fp->uf_flags & FC_LUAREF)) { \
LuaRef ref = api_new_luaref(fp->uf_luaref); \ kvi_push(edata->stack, LUAREF_OBJ(api_new_luaref(fp->uf_luaref))); \
kvi_push(edata->stack, LUAREF_OBJ(ref)); \
} else { \ } else { \
TYPVAL_ENCODE_CONV_NIL(tv); \ TYPVAL_ENCODE_CONV_NIL(tv); \
} \ } \

View File

@ -559,6 +559,16 @@ describe('API', function()
eq('Vim:E121: Undefined variable: bogus', pcall_err(request, 'nvim_eval', 'bogus expression')) eq('Vim:E121: Undefined variable: bogus', pcall_err(request, 'nvim_eval', 'bogus expression'))
eq('', eval('v:errmsg')) -- v:errmsg was not updated. eq('', eval('v:errmsg')) -- v:errmsg was not updated.
end) 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) end)
describe('nvim_call_function', function() describe('nvim_call_function', function()
@ -624,6 +634,16 @@ describe('API', function()
pcall_err(request, 'nvim_call_function', 'Foo', too_many_args) pcall_err(request, 'nvim_call_function', 'Foo', too_many_args)
) )
end) 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) end)
describe('nvim_call_dict_function', function() describe('nvim_call_dict_function', function()