aboutsummaryrefslogtreecommitdiff
path: root/test/functional/vimscript/state_spec.lua
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-08-21 12:26:02 +0800
committerzeertzjq <zeertzjq@outlook.com>2023-08-21 14:16:16 +0800
commit6bf5b2428b146330688922d66438357c0568725d (patch)
tree89372aa73110ab7d3446d29a43ae020ce28cb70f /test/functional/vimscript/state_spec.lua
parent7ce2acd59be89e5e6d2ac778ad074a9ae42951cd (diff)
downloadrneovim-6bf5b2428b146330688922d66438357c0568725d.tar.gz
rneovim-6bf5b2428b146330688922d66438357c0568725d.tar.bz2
rneovim-6bf5b2428b146330688922d66438357c0568725d.zip
vim-patch:8.1.2066: no tests for state()
Problem: No tests for state(). Solution: Add tests. Clean up some feature checks. Make "a" flag work. https://github.com/vim/vim/commit/c2585490321854ca3df115efcf0b40986901d96c Co-authored-by: Bram Moolenaar <Bram@vim.org>
Diffstat (limited to 'test/functional/vimscript/state_spec.lua')
-rw-r--r--test/functional/vimscript/state_spec.lua69
1 files changed, 69 insertions, 0 deletions
diff --git a/test/functional/vimscript/state_spec.lua b/test/functional/vimscript/state_spec.lua
new file mode 100644
index 0000000000..dcff3c8d7e
--- /dev/null
+++ b/test/functional/vimscript/state_spec.lua
@@ -0,0 +1,69 @@
+local helpers = require('test.functional.helpers')(after_each)
+local clear = helpers.clear
+local eq = helpers.eq
+local exec = helpers.exec
+local exec_lua = helpers.exec_lua
+local feed = helpers.feed
+local meths = helpers.meths
+local poke_eventloop = helpers.poke_eventloop
+
+before_each(clear)
+
+describe('state() function', function()
+ it('works', function()
+ meths.ui_attach(80, 24, {}) -- Allow hit-enter-prompt
+
+ 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
+ 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>]])
+ poke_eventloop() -- Allow polling for events
+ eq({ 'c', 'n' }, exec_lua('return _G.res'))
+
+ -- Halfway a mapping
+ feed([[:call v:lua.Run_timer()<CR>;]])
+ meths.get_mode() -- Allow polling for fast events
+ feed(';')
+ eq({ 'mS', 'n' }, exec_lua('return _G.res'))
+
+ -- Insert mode completion
+ feed([[:call RunTimer()<CR>Got<C-X><C-N>]])
+ poke_eventloop() -- Allow polling for events
+ 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>]])
+ meths.get_mode() -- Allow polling for fast events
+ feed('<CR>')
+ eq({ 'Ss', 'r' }, exec_lua('return _G.res'))
+ end)
+end)