aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-09-14 19:49:55 +0800
committerzeertzjq <zeertzjq@outlook.com>2022-09-17 21:48:44 +0800
commit644a3f48b117abd1d0d0aab5ec96cd62392ca0f1 (patch)
tree0b15f58a19574d34ba97d455e09b3afc94b35bb7 /test
parent3c3f3e7353ba2cb9071183cd05036ca2a98d3672 (diff)
downloadrneovim-644a3f48b117abd1d0d0aab5ec96cd62392ca0f1.tar.gz
rneovim-644a3f48b117abd1d0d0aab5ec96cd62392ca0f1.tar.bz2
rneovim-644a3f48b117abd1d0d0aab5ec96cd62392ca0f1.zip
fix(events): make CursorHold behave as documented
Diffstat (limited to 'test')
-rw-r--r--test/functional/autocmd/cursorhold_spec.lua57
1 files changed, 48 insertions, 9 deletions
diff --git a/test/functional/autocmd/cursorhold_spec.lua b/test/functional/autocmd/cursorhold_spec.lua
index 506b688853..5d54610e1d 100644
--- a/test/functional/autocmd/cursorhold_spec.lua
+++ b/test/functional/autocmd/cursorhold_spec.lua
@@ -5,22 +5,61 @@ local eq = helpers.eq
local eval = helpers.eval
local feed = helpers.feed
local retry = helpers.retry
-local source = helpers.source
+local exec = helpers.source
local sleep = helpers.sleep
+local meths = helpers.meths
-describe('CursorHoldI', function()
- before_each(clear)
+before_each(clear)
+
+describe('CursorHold', function()
+ it('is triggered correctly #12587', function()
+ exec([[
+ augroup test
+ au CursorHold * let g:cursorhold += 1
+ augroup END
+ ]])
+
+ local function test_cursorhold(fn, early)
+ local ut = 2
+ -- if testing with small 'updatetime' fails, double its value and test again
+ retry(10, nil, function()
+ ut = ut * 2
+ meths.set_option('updatetime', ut)
+ feed('0') -- reset did_cursorhold
+ meths.set_var('cursorhold', 0)
+ sleep(ut / 4)
+ fn()
+ eq(0, meths.get_var('cursorhold'))
+ sleep(ut / 2)
+ fn()
+ eq(0, meths.get_var('cursorhold'))
+ sleep(ut / 2)
+ eq(early, meths.get_var('cursorhold'))
+ sleep(ut / 4 * 3)
+ eq(1, meths.get_var('cursorhold'))
+ end)
+ end
+ local ignore_key = meths.replace_termcodes('<Ignore>', true, true, true)
+ test_cursorhold(function() end, 1)
+ test_cursorhold(function() feed('') end, 1)
+ test_cursorhold(function() meths.feedkeys('', 'n', true) end, 1)
+ test_cursorhold(function() feed('<Ignore>') end, 0)
+ test_cursorhold(function() meths.feedkeys(ignore_key, 'n', true) end, 0)
+ end)
+end)
+
+describe('CursorHoldI', function()
-- NOTE: since this test uses RPC it is not necessary to trigger the initial
-- issue (#3757) via timer's or RPC callbacks in the first place.
it('is triggered after input', function()
- source([[
- set updatetime=1
+ exec([[
+ set updatetime=1
- let g:cursorhold = 0
- augroup test
- au CursorHoldI * let g:cursorhold += 1
- augroup END
+ let g:cursorhold = 0
+ augroup test
+ au CursorHoldI * let g:cursorhold += 1
+ augroup END
]])
feed('ifoo')
retry(5, nil, function()