2024-04-20 08:44:13 -07:00
|
|
|
local t = require('test.testutil')
|
|
|
|
local n = require('test.functional.testnvim')()
|
|
|
|
|
|
|
|
local clear = n.clear
|
2024-04-08 02:03:20 -07:00
|
|
|
local eq = t.eq
|
2024-04-20 08:44:13 -07:00
|
|
|
local exec = n.exec
|
|
|
|
local feed = n.feed
|
|
|
|
local api = n.api
|
2023-08-20 22:45:26 -07:00
|
|
|
|
|
|
|
before_each(clear)
|
|
|
|
|
|
|
|
describe('SafeState autocommand', function()
|
|
|
|
local function create_autocmd()
|
|
|
|
exec([[
|
|
|
|
let g:safe = 0
|
|
|
|
autocmd SafeState * ++once let g:safe += 1
|
|
|
|
]])
|
|
|
|
end
|
|
|
|
|
|
|
|
it('with pending operator', function()
|
|
|
|
feed('d')
|
|
|
|
create_autocmd()
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(0, api.nvim_get_var('safe'))
|
2023-08-20 22:45:26 -07:00
|
|
|
feed('d')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(1, api.nvim_get_var('safe'))
|
2023-08-20 22:45:26 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('with specified register', function()
|
|
|
|
feed('"r')
|
|
|
|
create_autocmd()
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(0, api.nvim_get_var('safe'))
|
2023-08-20 22:45:26 -07:00
|
|
|
feed('x')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(1, api.nvim_get_var('safe'))
|
2023-08-20 22:45:26 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('with i_CTRL-O', function()
|
|
|
|
feed('i<C-O>')
|
|
|
|
create_autocmd()
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(0, api.nvim_get_var('safe'))
|
2023-08-20 22:45:26 -07:00
|
|
|
feed('x')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(1, api.nvim_get_var('safe'))
|
2023-08-20 22:45:26 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('with Insert mode completion', function()
|
|
|
|
feed('i<C-X><C-V>')
|
|
|
|
create_autocmd()
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(0, api.nvim_get_var('safe'))
|
2023-08-20 22:45:26 -07:00
|
|
|
feed('<C-X><C-Z>')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(1, api.nvim_get_var('safe'))
|
2023-08-20 22:45:26 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('with Cmdline completion', function()
|
|
|
|
feed(':<Tab>')
|
|
|
|
create_autocmd()
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(0, api.nvim_get_var('safe'))
|
2023-08-20 22:45:26 -07:00
|
|
|
feed('<C-E>')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(1, api.nvim_get_var('safe'))
|
2023-08-20 22:45:26 -07:00
|
|
|
end)
|
|
|
|
end)
|