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 exec_lua = n.exec_lua
|
|
|
|
local feed = n.feed
|
|
|
|
local api = n.api
|
|
|
|
local poke_eventloop = n.poke_eventloop
|
2023-08-20 21:26:02 -07:00
|
|
|
|
|
|
|
before_each(clear)
|
|
|
|
|
|
|
|
describe('state() function', function()
|
2023-08-22 15:42:10 -07:00
|
|
|
-- oldtest: Test_state()
|
2023-08-20 21:26:02 -07:00
|
|
|
it('works', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_ui_attach(80, 24, {}) -- Allow hit-enter-prompt
|
2023-08-20 21:26:02 -07:00
|
|
|
|
|
|
|
exec_lua([[
|
|
|
|
function _G.Get_state_mode()
|
|
|
|
_G.res = { vim.fn.state(), vim.api.nvim_get_mode().mode:sub(1, 1) }
|
|
|
|
end
|
|
|
|
function _G.Run_timer()
|
|
|
|
local timer = vim.uv.new_timer()
|
|
|
|
timer:start(0, 0, function()
|
|
|
|
_G.Get_state_mode()
|
|
|
|
timer:close()
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
]])
|
|
|
|
exec([[
|
|
|
|
call setline(1, ['one', 'two', 'three'])
|
|
|
|
map ;; gg
|
2023-08-20 22:21:28 -07:00
|
|
|
set complete=.
|
2023-08-20 21:26:02 -07:00
|
|
|
func RunTimer()
|
|
|
|
call timer_start(0, {id -> v:lua.Get_state_mode()})
|
|
|
|
endfunc
|
|
|
|
au Filetype foobar call v:lua.Get_state_mode()
|
|
|
|
]])
|
|
|
|
|
|
|
|
-- Using a ":" command Vim is busy, thus "S" is returned
|
|
|
|
feed([[:call v:lua.Get_state_mode()<CR>]])
|
|
|
|
eq({ 'S', 'n' }, exec_lua('return _G.res'))
|
|
|
|
|
|
|
|
-- Using a timer callback
|
|
|
|
feed([[:call RunTimer()<CR>]])
|
2023-08-22 09:00:57 -07:00
|
|
|
poke_eventloop() -- Process pending input
|
|
|
|
poke_eventloop() -- Process time_event
|
2023-08-20 21:26:02 -07:00
|
|
|
eq({ 'c', 'n' }, exec_lua('return _G.res'))
|
|
|
|
|
|
|
|
-- Halfway a mapping
|
|
|
|
feed([[:call v:lua.Run_timer()<CR>;]])
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_get_mode() -- Process pending input and luv timer callback
|
2023-08-20 21:26:02 -07:00
|
|
|
feed(';')
|
|
|
|
eq({ 'mS', 'n' }, exec_lua('return _G.res'))
|
|
|
|
|
2023-08-22 15:42:10 -07:00
|
|
|
-- An operator is pending
|
|
|
|
feed([[:call RunTimer()<CR>y]])
|
|
|
|
poke_eventloop() -- Process pending input
|
|
|
|
poke_eventloop() -- Process time_event
|
|
|
|
feed('y')
|
|
|
|
eq({ 'oSc', 'n' }, exec_lua('return _G.res'))
|
|
|
|
|
|
|
|
-- A register was specified
|
|
|
|
feed([[:call RunTimer()<CR>"r]])
|
|
|
|
poke_eventloop() -- Process pending input
|
|
|
|
poke_eventloop() -- Process time_event
|
|
|
|
feed('yy')
|
|
|
|
eq({ 'oSc', 'n' }, exec_lua('return _G.res'))
|
|
|
|
|
2023-08-20 21:26:02 -07:00
|
|
|
-- Insert mode completion
|
2023-08-20 22:21:28 -07:00
|
|
|
feed([[:call RunTimer()<CR>Got<C-N>]])
|
2023-08-22 09:00:57 -07:00
|
|
|
poke_eventloop() -- Process pending input
|
|
|
|
poke_eventloop() -- Process time_event
|
2023-08-20 21:26:02 -07:00
|
|
|
feed('<Esc>')
|
|
|
|
eq({ 'aSc', 'i' }, exec_lua('return _G.res'))
|
|
|
|
|
|
|
|
-- Autocommand executing
|
|
|
|
feed([[:set filetype=foobar<CR>]])
|
|
|
|
eq({ 'xS', 'n' }, exec_lua('return _G.res'))
|
|
|
|
|
|
|
|
-- messages scrolled
|
|
|
|
feed([[:call v:lua.Run_timer() | echo "one\ntwo\nthree"<CR>]])
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_get_mode() -- Process pending input and luv timer callback
|
2023-08-20 21:26:02 -07:00
|
|
|
feed('<CR>')
|
|
|
|
eq({ 'Ss', 'r' }, exec_lua('return _G.res'))
|
|
|
|
end)
|
|
|
|
end)
|