Skip to content

Commit 26d9821

Browse files
committed
patch 8.1.0837: timer interrupting cursorhold and mapping not tested
Problem: Timer interrupting cursorhold and mapping not tested. Solution: Add tests with timers. (Ozaki Kiichi, closes #3871)
1 parent 346d2a3 commit 26d9821

3 files changed

Lines changed: 66 additions & 3 deletions

File tree

src/testdir/test_autocmd.vim

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,28 @@ if has('timers')
3232
call timer_start(100, 'ExitInsertMode')
3333
call feedkeys('a', 'x!')
3434
call assert_equal(1, g:triggered)
35+
unlet g:triggered
36+
au! CursorHoldI
37+
set updatetime&
38+
endfunc
39+
40+
func Test_cursorhold_insert_with_timer_interrupt()
41+
if !has('job')
42+
return
43+
endif
44+
" Need to move the cursor.
45+
call feedkeys("ggG", "xt")
46+
47+
" Confirm the timer invoked in exit_cb of the job doesn't disturb
48+
" CursorHoldI event.
49+
let g:triggered = 0
50+
au CursorHoldI * let g:triggered += 1
51+
set updatetime=500
52+
call job_start(has('win32') ? 'cmd /c echo:' : 'echo',
53+
\ {'exit_cb': {j, s -> timer_start(1000, 'ExitInsertMode')}})
54+
call feedkeys('a', 'x!')
55+
call assert_equal(1, g:triggered)
56+
unlet g:triggered
3557
au! CursorHoldI
3658
set updatetime&
3759
endfunc
@@ -44,6 +66,7 @@ if has('timers')
4466
" CursorHoldI does not trigger after CTRL-X
4567
call feedkeys("a\<C-X>", 'x!')
4668
call assert_equal(0, g:triggered)
69+
unlet g:triggered
4770
au! CursorHoldI
4871
set updatetime&
4972
endfunc
@@ -452,7 +475,7 @@ func s:AutoCommandOptionSet(match)
452475
endfunc
453476

454477
func Test_OptionSet()
455-
if !has("eval") || !has("autocmd") || !exists("+autochdir")
478+
if !has("eval") || !exists("+autochdir")
456479
return
457480
endif
458481

@@ -595,7 +618,7 @@ endfunc
595618

596619
func Test_OptionSet_diffmode()
597620
call test_override('starting', 1)
598-
" 18: Changing an option when enetering diff mode
621+
" 18: Changing an option when entering diff mode
599622
new
600623
au OptionSet diff :let &l:cul=v:option_new
601624

src/testdir/test_mapping.vim

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
" Tests for mappings and abbreviations
22

3+
source shared.vim
4+
35
func Test_abbreviation()
46
" abbreviation with 0x80 should work
57
inoreab чкпр vim
@@ -169,6 +171,9 @@ func Test_abbr_after_line_join()
169171
endfunc
170172

171173
func Test_map_timeout()
174+
if !has('timers')
175+
return
176+
endif
172177
nnoremap aaaa :let got_aaaa = 1<CR>
173178
nnoremap bb :let got_bb = 1<CR>
174179
nmap b aaa
@@ -178,7 +183,7 @@ func Test_map_timeout()
178183
call feedkeys("\<Esc>", "t")
179184
endfunc
180185
set timeout timeoutlen=200
181-
call timer_start(300, 'ExitInsert')
186+
let timer = timer_start(300, 'ExitInsert')
182187
" After the 'b' Vim waits for another character to see if it matches 'bb'.
183188
" When it times out it is expanded to "aaa", but there is no wait for
184189
" "aaaa". Can't check that reliably though.
@@ -193,6 +198,39 @@ func Test_map_timeout()
193198
nunmap b
194199
set timeoutlen&
195200
delfunc ExitInsert
201+
call timer_stop(timer)
202+
endfunc
203+
204+
func Test_map_timeout_with_timer_interrupt()
205+
if !has('job') || !has('timers')
206+
return
207+
endif
208+
209+
" Confirm the timer invoked in exit_cb of the job doesn't disturb mapped key
210+
" sequence.
211+
new
212+
let g:val = 0
213+
nnoremap \12 :let g:val = 1<CR>
214+
nnoremap \123 :let g:val = 2<CR>
215+
set timeout timeoutlen=1000
216+
217+
func ExitCb(job, status)
218+
let g:timer = timer_start(1, {_ -> feedkeys("3\<Esc>", 't')})
219+
endfunc
220+
221+
call job_start([&shell, &shellcmdflag, 'echo'], {'exit_cb': 'ExitCb'})
222+
call feedkeys('\12', 'xt!')
223+
call assert_equal(2, g:val)
224+
225+
bwipe!
226+
nunmap \12
227+
nunmap \123
228+
set timeoutlen&
229+
call WaitFor({-> exists('g:timer')})
230+
call timer_stop(g:timer)
231+
unlet g:timer
232+
unlet g:val
233+
delfunc ExitCb
196234
endfunc
197235

198236
func Test_abbreviation_CR()

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,8 @@ static char *(features[]) =
783783

784784
static int included_patches[] =
785785
{ /* Add new patch number below this line */
786+
/**/
787+
837,
786788
/**/
787789
836,
788790
/**/

0 commit comments

Comments
 (0)