test: getting autocmd Lua callback in Vimscript (#28367)

Also remove unnecessary variable in API converter.
This commit is contained in:
zeertzjq 2024-04-16 11:59:55 +08:00 committed by GitHub
parent 60fb8a6a8b
commit 47ba96a6b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 7 deletions

View File

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

View File

@ -610,15 +610,17 @@ describe('autocmd api', function()
it('can retrieve a callback from an autocmd', function()
local content = 'I Am A Callback'
api.nvim_set_var('content', content)
local result = exec_lua([[
exec_lua([[
local cb = function() return vim.g.content end
vim.api.nvim_create_autocmd("User", {
pattern = "TestTrigger",
desc = "A test autocommand with a callback",
callback = cb,
})
local aus = vim.api.nvim_get_autocmds({ event = 'User', pattern = 'TestTrigger'})
]])
local result = exec_lua([[
local aus = vim.api.nvim_get_autocmds({ event = 'User', pattern = 'TestTrigger' })
local first = aus[1]
return {
cb = {
@ -627,9 +629,14 @@ describe('autocmd api', function()
}
}
]])
eq({ cb = { type = 'function', can_retrieve = true } }, result)
eq('function', result.cb.type)
eq(true, result.cb.can_retrieve)
-- Also test with Vimscript
source([[
let s:aus = nvim_get_autocmds({'event': 'User', 'pattern': 'TestTrigger'})
let g:result = s:aus[0].callback()
]])
eq(content, api.nvim_get_var('result'))
end)
it(