11" Tests for mappings and abbreviations
22
3+ source shared.vim
4+
35func Test_abbreviation ()
46 " abbreviation with 0x80 should work
57 inoreab чкпр vim
@@ -169,6 +171,9 @@ func Test_abbr_after_line_join()
169171endfunc
170172
171173func 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
196234endfunc
197235
198236func Test_abbreviation_CR ()
0 commit comments