test: getting autocmd Lua callback in Vimscript (#28367)
Also remove unnecessary variable in API converter.
This commit is contained in:
parent
60fb8a6a8b
commit
47ba96a6b3
|
@ -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); \
|
||||
} \
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue