diff options
author | glepnir <glephunter@gmail.com> | 2025-01-27 07:28:33 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-26 15:28:33 -0800 |
commit | d84a95da7e11555376a0ce60a0d4b5fbe15892d3 (patch) | |
tree | 6cb18bc5dc232bafd0f6f932a8ac4f1f2d6d698d /test/functional/api/autocmd_spec.lua | |
parent | b8e947ed4ed04f9aeef471f579451bbf2bb2993d (diff) | |
download | rneovim-d84a95da7e11555376a0ce60a0d4b5fbe15892d3.tar.gz rneovim-d84a95da7e11555376a0ce60a0d4b5fbe15892d3.tar.bz2 rneovim-d84a95da7e11555376a0ce60a0d4b5fbe15892d3.zip |
feat(api): nvim_get_autocmds filter by id#31549
Problem:
nvim_get_autocmds cannot filter by id.
Solution:
Support it.
Diffstat (limited to 'test/functional/api/autocmd_spec.lua')
-rw-r--r-- | test/functional/api/autocmd_spec.lua | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index bb6456f45b..64b28e7bf7 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -899,6 +899,89 @@ describe('autocmd api', function() eq([[:echo "Buffer"]], normalized_aus[1].command) end) end) + + describe('id', function() + it('gets events by ID', function() + local id = api.nvim_create_autocmd('BufEnter', { + command = 'echo "hello"', + }) + eq({ + { + buflocal = false, + command = 'echo "hello"', + event = 'BufEnter', + id = id, + once = false, + pattern = '*', + }, + }, api.nvim_get_autocmds({ id = id })) + end) + + it('gets events by ID by other filters', function() + local group_name = 'NVIM_GET_AUTOCMDS_ID' + local group = api.nvim_create_augroup(group_name, { clear = true }) + local id = api.nvim_create_autocmd('BufEnter', { + command = 'set number', + group = group, + }) + api.nvim_create_autocmd('WinEnter', { + group = group, + command = 'set cot&', + }) + eq({ + { + buflocal = false, + command = 'set number', + event = 'BufEnter', + group = group, + group_name = group_name, + id = id, + once = false, + pattern = '*', + }, + }, api.nvim_get_autocmds({ id = id, group = group })) + end) + + it('gets events by ID and a specific event', function() + local id = api.nvim_create_autocmd('InsertEnter', { command = 'set number' }) + api.nvim_create_autocmd('InsertEnter', { command = 'set wrap' }) + eq({ + { + buflocal = false, + command = 'set number', + event = 'InsertEnter', + id = id, + once = false, + pattern = '*', + }, + }, api.nvim_get_autocmds({ id = id, event = 'InsertEnter' })) + end) + + it('gets events by ID and a specific pattern', function() + local id = api.nvim_create_autocmd('InsertEnter', { + pattern = '*.c', + command = 'set number', + }) + api.nvim_create_autocmd('InsertEnter', { + pattern = '*.c', + command = 'set wrap', + }) + eq({ + { + buflocal = false, + command = 'set number', + event = 'InsertEnter', + id = id, + once = false, + pattern = '*.c', + }, + }, api.nvim_get_autocmds({ id = id, pattern = '*.c' })) + end) + + it('empty result when id does not found', function() + eq({}, api.nvim_get_autocmds({ id = 255 })) + end) + end) end) describe('nvim_exec_autocmds', function() |