2016-04-21 08:06:03 -07:00
|
|
|
" Test for timers
|
|
|
|
|
2022-07-07 17:26:25 -07:00
|
|
|
source check.vim
|
|
|
|
CheckFeature timers
|
2016-04-21 08:06:03 -07:00
|
|
|
|
2022-10-23 22:48:51 -07:00
|
|
|
source screendump.vim
|
2017-03-05 08:25:40 -07:00
|
|
|
source shared.vim
|
2020-04-28 20:13:23 -07:00
|
|
|
source term_util.vim
|
2019-01-16 13:20:38 -07:00
|
|
|
source load.vim
|
2017-03-05 08:25:40 -07:00
|
|
|
|
2022-07-11 15:55:32 -07:00
|
|
|
func SetUp()
|
|
|
|
call timer_stopall()
|
|
|
|
endfunc
|
|
|
|
|
2016-04-21 08:06:03 -07:00
|
|
|
func MyHandler(timer)
|
2017-03-05 08:25:40 -07:00
|
|
|
let g:val += 1
|
2016-04-21 08:06:03 -07:00
|
|
|
endfunc
|
|
|
|
|
2016-11-02 22:11:25 -07:00
|
|
|
func MyHandlerWithLists(lists, timer)
|
|
|
|
let x = string(a:lists)
|
|
|
|
endfunc
|
|
|
|
|
2022-07-07 19:05:03 -07:00
|
|
|
func Test_timer_oneshot()
|
2017-03-05 08:25:40 -07:00
|
|
|
let g:val = 0
|
2016-04-21 08:06:03 -07:00
|
|
|
let timer = timer_start(50, 'MyHandler')
|
2017-03-05 08:25:40 -07:00
|
|
|
let slept = WaitFor('g:val == 1')
|
|
|
|
call assert_equal(1, g:val)
|
2017-03-20 12:52:54 -07:00
|
|
|
if has('reltime')
|
2019-05-18 00:50:44 -07:00
|
|
|
call assert_inrange(40, LoadAdjust(120), slept)
|
2017-03-20 12:52:54 -07:00
|
|
|
else
|
2018-10-07 23:56:13 -07:00
|
|
|
call assert_inrange(20, 120, slept)
|
2017-03-20 12:52:54 -07:00
|
|
|
endif
|
2016-04-21 08:06:03 -07:00
|
|
|
endfunc
|
|
|
|
|
2022-07-07 19:05:03 -07:00
|
|
|
func Test_timer_repeat_three()
|
2017-03-05 08:25:40 -07:00
|
|
|
let g:val = 0
|
2016-04-21 08:06:03 -07:00
|
|
|
let timer = timer_start(50, 'MyHandler', {'repeat': 3})
|
2017-03-05 08:25:40 -07:00
|
|
|
let slept = WaitFor('g:val == 3')
|
|
|
|
call assert_equal(3, g:val)
|
2017-03-20 12:52:54 -07:00
|
|
|
if has('reltime')
|
2019-05-18 00:50:44 -07:00
|
|
|
call assert_inrange(120, LoadAdjust(250), slept)
|
2017-03-20 12:52:54 -07:00
|
|
|
else
|
|
|
|
call assert_inrange(80, 200, slept)
|
|
|
|
endif
|
2016-04-21 08:06:03 -07:00
|
|
|
endfunc
|
|
|
|
|
2022-07-07 19:05:03 -07:00
|
|
|
func Test_timer_repeat_many()
|
2017-03-05 08:25:40 -07:00
|
|
|
let g:val = 0
|
2016-04-21 08:06:03 -07:00
|
|
|
let timer = timer_start(50, 'MyHandler', {'repeat': -1})
|
|
|
|
sleep 200m
|
|
|
|
call timer_stop(timer)
|
2019-08-16 01:11:03 -07:00
|
|
|
call assert_inrange((has('mac') ? 1 : 2), LoadAdjust(5), g:val)
|
2016-04-21 08:06:03 -07:00
|
|
|
endfunc
|
2016-10-30 15:10:11 -07:00
|
|
|
|
2022-07-07 19:05:03 -07:00
|
|
|
func Test_timer_with_partial_callback()
|
2017-03-05 08:25:40 -07:00
|
|
|
let g:val = 0
|
2017-04-06 05:58:18 -07:00
|
|
|
let meow = {'one': 1}
|
|
|
|
function meow.bite(...)
|
|
|
|
let g:val += self.one
|
2016-11-02 22:11:25 -07:00
|
|
|
endfunction
|
2016-11-01 02:54:32 -07:00
|
|
|
|
2017-04-06 05:58:18 -07:00
|
|
|
call timer_start(50, meow.bite)
|
2017-03-05 08:25:40 -07:00
|
|
|
let slept = WaitFor('g:val == 1')
|
|
|
|
call assert_equal(1, g:val)
|
2017-03-20 12:52:54 -07:00
|
|
|
if has('reltime')
|
2019-05-18 00:50:44 -07:00
|
|
|
call assert_inrange(40, LoadAdjust(130), slept)
|
2017-03-20 12:52:54 -07:00
|
|
|
else
|
|
|
|
call assert_inrange(20, 100, slept)
|
|
|
|
endif
|
2016-11-02 22:11:25 -07:00
|
|
|
endfunc
|
|
|
|
|
2022-07-07 19:05:03 -07:00
|
|
|
func Test_timer_retain_partial()
|
2017-03-05 08:25:40 -07:00
|
|
|
call timer_start(50, function('MyHandlerWithLists', [['a']]))
|
2022-07-07 19:05:03 -07:00
|
|
|
call test_garbagecollect_now()
|
2017-03-05 08:25:40 -07:00
|
|
|
sleep 100m
|
|
|
|
endfunc
|
|
|
|
|
2022-07-07 19:05:03 -07:00
|
|
|
func Test_timer_info()
|
2017-03-05 08:25:40 -07:00
|
|
|
let id = timer_start(1000, 'MyHandler')
|
2021-11-01 09:26:19 -07:00
|
|
|
let info = id->timer_info()
|
2017-03-05 08:25:40 -07:00
|
|
|
call assert_equal(id, info[0]['id'])
|
|
|
|
call assert_equal(1000, info[0]['time'])
|
|
|
|
call assert_equal("function('MyHandler')", string(info[0]['callback']))
|
|
|
|
|
|
|
|
let found = 0
|
|
|
|
for info in timer_info()
|
|
|
|
if info['id'] == id
|
|
|
|
let found += 1
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
call assert_equal(1, found)
|
|
|
|
|
|
|
|
call timer_stop(id)
|
|
|
|
call assert_equal([], timer_info(id))
|
2022-07-11 16:22:17 -07:00
|
|
|
|
2023-04-25 08:39:15 -07:00
|
|
|
call assert_fails('call timer_info("abc")', 'E1210:')
|
2023-04-25 06:52:27 -07:00
|
|
|
|
|
|
|
" check repeat count inside the callback
|
|
|
|
let g:timer_repeat = []
|
|
|
|
let tid = timer_start(10, {tid -> execute("call add(g:timer_repeat, timer_info(tid)[0].repeat)")}, #{repeat: 3})
|
2023-04-25 07:03:52 -07:00
|
|
|
call WaitForAssert({-> assert_equal([2, 1, 0], g:timer_repeat)})
|
2023-04-25 06:52:27 -07:00
|
|
|
unlet g:timer_repeat
|
2017-03-05 08:25:40 -07:00
|
|
|
endfunc
|
|
|
|
|
2022-07-07 19:05:03 -07:00
|
|
|
func Test_timer_stopall()
|
2017-03-05 08:25:40 -07:00
|
|
|
let id1 = timer_start(1000, 'MyHandler')
|
|
|
|
let id2 = timer_start(2000, 'MyHandler')
|
|
|
|
let info = timer_info()
|
|
|
|
call assert_equal(2, len(info))
|
|
|
|
|
|
|
|
call timer_stopall()
|
|
|
|
let info = timer_info()
|
|
|
|
call assert_equal(0, len(info))
|
|
|
|
endfunc
|
|
|
|
|
2022-07-07 19:05:03 -07:00
|
|
|
func Test_timer_paused()
|
2017-03-05 08:25:40 -07:00
|
|
|
let g:val = 0
|
|
|
|
|
|
|
|
let id = timer_start(50, 'MyHandler')
|
|
|
|
let info = timer_info(id)
|
|
|
|
call assert_equal(0, info[0]['paused'])
|
|
|
|
|
2021-11-01 09:26:19 -07:00
|
|
|
eval id->timer_pause(1)
|
2017-03-05 08:25:40 -07:00
|
|
|
let info = timer_info(id)
|
|
|
|
call assert_equal(1, info[0]['paused'])
|
2016-11-02 22:11:25 -07:00
|
|
|
sleep 200m
|
2017-03-05 08:25:40 -07:00
|
|
|
call assert_equal(0, g:val)
|
|
|
|
|
|
|
|
call timer_pause(id, 0)
|
|
|
|
let info = timer_info(id)
|
|
|
|
call assert_equal(0, info[0]['paused'])
|
|
|
|
|
|
|
|
let slept = WaitFor('g:val == 1')
|
|
|
|
call assert_equal(1, g:val)
|
2017-03-20 12:52:54 -07:00
|
|
|
if has('reltime')
|
2019-05-18 00:50:44 -07:00
|
|
|
call assert_inrange(0, LoadAdjust(140), slept)
|
2017-03-20 12:52:54 -07:00
|
|
|
else
|
|
|
|
call assert_inrange(0, 10, slept)
|
|
|
|
endif
|
2022-07-11 16:22:17 -07:00
|
|
|
|
|
|
|
call assert_fails('call timer_pause("abc", 1)', 'E39:')
|
2016-11-02 22:11:25 -07:00
|
|
|
endfunc
|
2017-03-14 01:58:13 -07:00
|
|
|
|
2017-04-06 05:55:51 -07:00
|
|
|
func StopMyself(timer)
|
|
|
|
let g:called += 1
|
|
|
|
if g:called == 2
|
|
|
|
call timer_stop(a:timer)
|
|
|
|
endif
|
|
|
|
endfunc
|
|
|
|
|
2022-07-07 19:05:03 -07:00
|
|
|
func Test_timer_delete_myself()
|
2017-04-06 05:55:51 -07:00
|
|
|
let g:called = 0
|
|
|
|
let t = timer_start(10, 'StopMyself', {'repeat': -1})
|
2019-09-20 16:19:46 -07:00
|
|
|
call WaitForAssert({-> assert_equal(2, g:called)})
|
2017-04-06 05:55:51 -07:00
|
|
|
call assert_equal(2, g:called)
|
|
|
|
call assert_equal([], timer_info(t))
|
|
|
|
endfunc
|
|
|
|
|
2017-04-06 05:56:53 -07:00
|
|
|
func StopTimer1(timer)
|
2021-11-01 09:26:19 -07:00
|
|
|
let g:timer2 = 10->timer_start('StopTimer2')
|
2017-04-06 05:56:53 -07:00
|
|
|
" avoid maxfuncdepth error
|
|
|
|
call timer_pause(g:timer1, 1)
|
2022-07-07 19:20:47 -07:00
|
|
|
sleep 20m
|
2017-04-06 05:56:53 -07:00
|
|
|
endfunc
|
|
|
|
|
|
|
|
func StopTimer2(timer)
|
|
|
|
call timer_stop(g:timer1)
|
|
|
|
endfunc
|
|
|
|
|
2022-07-07 19:05:03 -07:00
|
|
|
func Test_timer_stop_in_callback()
|
2022-07-07 19:17:42 -07:00
|
|
|
call assert_equal(0, len(timer_info()))
|
2017-04-06 05:56:53 -07:00
|
|
|
let g:timer1 = timer_start(10, 'StopTimer1')
|
2022-07-07 19:21:27 -07:00
|
|
|
let slept = 0
|
|
|
|
for i in range(10)
|
|
|
|
if len(timer_info()) == 0
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
sleep 10m
|
|
|
|
let slept += 10
|
|
|
|
endfor
|
|
|
|
" This should take only 30 msec, but on Mac it's often longer
|
|
|
|
call assert_inrange(0, 50, slept)
|
2017-04-06 05:56:53 -07:00
|
|
|
endfunc
|
|
|
|
|
|
|
|
func StopTimerAll(timer)
|
|
|
|
call timer_stopall()
|
|
|
|
endfunc
|
|
|
|
|
2022-07-07 19:05:03 -07:00
|
|
|
func Test_timer_stop_all_in_callback()
|
2022-07-07 19:17:42 -07:00
|
|
|
call assert_equal(0, len(timer_info()))
|
|
|
|
call timer_start(10, 'StopTimerAll')
|
|
|
|
call assert_equal(1, len(timer_info()))
|
|
|
|
let slept = 0
|
|
|
|
for i in range(10)
|
|
|
|
if len(timer_info()) == 0
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
sleep 10m
|
|
|
|
let slept += 10
|
|
|
|
endfor
|
|
|
|
call assert_inrange(0, 30, slept)
|
2017-04-06 05:56:53 -07:00
|
|
|
endfunc
|
|
|
|
|
2018-10-15 18:16:00 -07:00
|
|
|
func FeedkeysCb(timer)
|
|
|
|
call feedkeys("hello\<CR>", 'nt')
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
func InputCb(timer)
|
|
|
|
call timer_start(10, 'FeedkeysCb')
|
|
|
|
let g:val = input('?')
|
|
|
|
call Resume()
|
|
|
|
endfunc
|
|
|
|
|
2022-07-07 19:05:03 -07:00
|
|
|
func Test_timer_input_in_timer()
|
2018-10-15 18:16:00 -07:00
|
|
|
let g:val = ''
|
|
|
|
call timer_start(10, 'InputCb')
|
|
|
|
call Standby(1000)
|
|
|
|
call assert_equal('hello', g:val)
|
|
|
|
endfunc
|
|
|
|
|
2019-04-09 15:50:51 -07:00
|
|
|
func FuncWithError(timer)
|
|
|
|
let g:call_count += 1
|
|
|
|
if g:call_count == 4
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
doesnotexist
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
func Test_timer_errors()
|
|
|
|
let g:call_count = 0
|
|
|
|
let timer = timer_start(10, 'FuncWithError', {'repeat': -1})
|
|
|
|
" Timer will be stopped after failing 3 out of 3 times.
|
2019-09-20 16:19:46 -07:00
|
|
|
call WaitForAssert({-> assert_equal(3, g:call_count)})
|
2019-04-09 15:50:51 -07:00
|
|
|
sleep 50m
|
|
|
|
call assert_equal(3, g:call_count)
|
2022-07-11 16:22:17 -07:00
|
|
|
|
2023-04-25 06:32:12 -07:00
|
|
|
call assert_fails('call timer_start(100, "MyHandler", "abc")', 'E1206:')
|
2022-07-11 16:22:17 -07:00
|
|
|
call assert_fails('call timer_start(100, [])', 'E921:')
|
2023-04-25 08:39:15 -07:00
|
|
|
call assert_fails('call timer_stop("abc")', 'E1210:')
|
2019-04-09 15:50:51 -07:00
|
|
|
endfunc
|
|
|
|
|
2018-10-15 21:02:10 -07:00
|
|
|
func FuncWithCaughtError(timer)
|
|
|
|
let g:call_count += 1
|
|
|
|
try
|
|
|
|
doesnotexist
|
|
|
|
catch
|
|
|
|
" nop
|
|
|
|
endtry
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
func Test_timer_catch_error()
|
|
|
|
let g:call_count = 0
|
|
|
|
let timer = timer_start(10, 'FuncWithCaughtError', {'repeat': 4})
|
|
|
|
" Timer will not be stopped.
|
2019-09-20 16:19:46 -07:00
|
|
|
call WaitForAssert({-> assert_equal(4, g:call_count)})
|
2018-10-15 21:02:10 -07:00
|
|
|
sleep 50m
|
|
|
|
call assert_equal(4, g:call_count)
|
|
|
|
endfunc
|
|
|
|
|
2018-08-22 12:39:38 -07:00
|
|
|
func FeedAndPeek(timer)
|
2020-09-25 19:02:06 -07:00
|
|
|
" call test_feedinput('a')
|
|
|
|
call nvim_input('a')
|
2018-08-22 12:39:38 -07:00
|
|
|
call getchar(1)
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
func Interrupt(timer)
|
2021-10-31 17:28:00 -07:00
|
|
|
" eval "\<C-C>"->test_feedinput()
|
2020-09-25 19:02:06 -07:00
|
|
|
call nvim_input("\<C-C>")
|
2018-08-22 12:39:38 -07:00
|
|
|
endfunc
|
|
|
|
|
2022-07-07 19:05:03 -07:00
|
|
|
func Test_timer_peek_and_get_char()
|
2022-10-26 07:13:12 -07:00
|
|
|
if !has('unix') && !has('gui_running')
|
|
|
|
throw 'Skipped: cannot feed low-level input'
|
|
|
|
endif
|
2022-10-26 06:53:11 -07:00
|
|
|
|
2018-08-22 12:39:38 -07:00
|
|
|
call timer_start(0, 'FeedAndPeek')
|
|
|
|
let intr = timer_start(100, 'Interrupt')
|
|
|
|
let c = getchar()
|
|
|
|
call assert_equal(char2nr('a'), c)
|
2021-11-01 09:26:19 -07:00
|
|
|
eval intr->timer_stop()
|
2018-08-22 12:39:38 -07:00
|
|
|
endfunc
|
2017-04-06 05:56:53 -07:00
|
|
|
|
2022-07-07 19:05:03 -07:00
|
|
|
func Test_timer_getchar_zero()
|
2020-01-03 20:58:09 -07:00
|
|
|
if has('win32') && !has('gui_running')
|
2022-10-26 07:13:12 -07:00
|
|
|
throw 'Skipped: cannot feed low-level input'
|
2020-01-03 20:47:38 -07:00
|
|
|
endif
|
2022-10-26 07:13:12 -07:00
|
|
|
CheckFunction reltimefloat
|
2020-01-03 20:47:38 -07:00
|
|
|
|
2020-01-03 20:48:53 -07:00
|
|
|
" Measure the elapsed time to avoid a hang when it fails.
|
|
|
|
let start = reltime()
|
2020-01-03 20:58:09 -07:00
|
|
|
let id = timer_start(20, {-> feedkeys('x', 'L')})
|
2020-01-03 20:43:06 -07:00
|
|
|
let c = 0
|
2020-01-03 20:48:53 -07:00
|
|
|
while c == 0 && reltimefloat(reltime(start)) < 0.2
|
2020-01-03 20:43:06 -07:00
|
|
|
let c = getchar(0)
|
|
|
|
sleep 10m
|
|
|
|
endwhile
|
|
|
|
call assert_equal('x', nr2char(c))
|
2020-01-03 20:47:38 -07:00
|
|
|
call timer_stop(id)
|
2020-01-03 20:43:06 -07:00
|
|
|
endfunc
|
|
|
|
|
2022-07-07 19:05:03 -07:00
|
|
|
func Test_timer_ex_mode()
|
2019-09-19 22:31:01 -07:00
|
|
|
" Function with an empty line.
|
|
|
|
func Foo(...)
|
|
|
|
|
|
|
|
endfunc
|
2020-01-03 20:47:38 -07:00
|
|
|
let timer = timer_start(40, function('g:Foo'), {'repeat':-1})
|
2019-09-19 22:31:01 -07:00
|
|
|
" This used to throw error E749.
|
2022-07-04 22:54:03 -07:00
|
|
|
exe "normal Qsleep 100m\rvi\r"
|
2019-09-19 22:31:01 -07:00
|
|
|
call timer_stop(timer)
|
|
|
|
endfunc
|
|
|
|
|
2022-07-07 19:05:03 -07:00
|
|
|
func Test_timer_restore_count()
|
2022-11-04 17:07:06 -07:00
|
|
|
CheckRunVimInTerminal
|
2020-01-03 18:08:13 -07:00
|
|
|
" Check that v:count is saved and restored, not changed by a timer.
|
|
|
|
call writefile([
|
|
|
|
\ 'nnoremap <expr><silent> L v:count ? v:count . "l" : "l"',
|
|
|
|
\ 'func Doit(id)',
|
|
|
|
\ ' normal 3j',
|
|
|
|
\ 'endfunc',
|
|
|
|
\ 'call timer_start(100, "Doit")',
|
|
|
|
\ ], 'Xtrcscript')
|
|
|
|
call writefile([
|
|
|
|
\ '1-1234',
|
|
|
|
\ '2-1234',
|
|
|
|
\ '3-1234',
|
|
|
|
\ ], 'Xtrctext')
|
|
|
|
let buf = RunVimInTerminal('-S Xtrcscript Xtrctext', {})
|
|
|
|
|
|
|
|
" Wait for the timer to move the cursor to the third line.
|
|
|
|
call WaitForAssert({-> assert_equal(3, term_getcursor(buf)[0])})
|
|
|
|
call assert_equal(1, term_getcursor(buf)[1])
|
|
|
|
" Now check that v:count has not been set to 3
|
|
|
|
call term_sendkeys(buf, 'L')
|
|
|
|
call WaitForAssert({-> assert_equal(2, term_getcursor(buf)[1])})
|
|
|
|
|
|
|
|
call StopVimInTerminal(buf)
|
|
|
|
call delete('Xtrcscript')
|
|
|
|
call delete('Xtrctext')
|
|
|
|
endfunc
|
|
|
|
|
2020-01-05 08:40:02 -07:00
|
|
|
" Test that the garbage collector isn't triggered if a timer callback invokes
|
|
|
|
" vgetc().
|
2022-07-22 23:18:43 -07:00
|
|
|
func Test_nocatch_timer_garbage_collect()
|
2022-07-07 17:26:25 -07:00
|
|
|
" skipped: Nvim does not support test_garbagecollect_soon(), test_override()
|
|
|
|
return
|
2020-01-05 08:40:02 -07:00
|
|
|
" 'uptimetime. must be bigger than the timer timeout
|
|
|
|
set ut=200
|
|
|
|
call test_garbagecollect_soon()
|
|
|
|
call test_override('no_wait_return', 0)
|
|
|
|
func CauseAnError(id)
|
|
|
|
" This will show an error and wait for Enter.
|
|
|
|
let a = {'foo', 'bar'}
|
|
|
|
endfunc
|
|
|
|
func FeedChar(id)
|
2022-09-23 17:10:49 -07:00
|
|
|
call feedkeys(":\<CR>", 't')
|
2020-01-05 08:40:02 -07:00
|
|
|
endfunc
|
|
|
|
call timer_start(300, 'FeedChar')
|
|
|
|
call timer_start(100, 'CauseAnError')
|
2022-09-23 17:10:49 -07:00
|
|
|
let x = getchar() " wait for error in timer
|
|
|
|
let x = getchar(0) " read any remaining chars
|
|
|
|
let x = getchar(0)
|
2020-01-05 08:40:02 -07:00
|
|
|
|
|
|
|
set ut&
|
|
|
|
call test_override('no_wait_return', 1)
|
|
|
|
delfunc CauseAnError
|
|
|
|
delfunc FeedChar
|
|
|
|
endfunc
|
|
|
|
|
2022-07-07 19:05:03 -07:00
|
|
|
func Test_timer_error_in_timer_callback()
|
2020-10-05 21:53:55 -07:00
|
|
|
if !has('terminal') || (has('win32') && has('gui_running'))
|
2020-09-26 09:03:20 -07:00
|
|
|
throw 'Skipped: cannot run Vim in a terminal window'
|
|
|
|
endif
|
|
|
|
|
|
|
|
let lines =<< trim [CODE]
|
|
|
|
func Func(timer)
|
|
|
|
" fail to create list
|
|
|
|
let x = [
|
|
|
|
endfunc
|
|
|
|
set updatetime=50
|
|
|
|
call timer_start(1, 'Func')
|
|
|
|
[CODE]
|
|
|
|
call writefile(lines, 'Xtest.vim')
|
|
|
|
|
2020-10-05 21:53:55 -07:00
|
|
|
let buf = term_start(GetVimCommandCleanTerm() .. ' -S Xtest.vim', {'term_rows': 8})
|
2020-09-26 09:03:20 -07:00
|
|
|
let job = term_getjob(buf)
|
|
|
|
call WaitForAssert({-> assert_notequal('', term_getline(buf, 8))})
|
|
|
|
|
|
|
|
" GC must not run during timer callback, which can make Vim crash.
|
|
|
|
call term_wait(buf, 100)
|
|
|
|
call term_sendkeys(buf, "\<CR>")
|
|
|
|
call term_wait(buf, 100)
|
|
|
|
call assert_equal('run', job_status(job))
|
|
|
|
|
|
|
|
call term_sendkeys(buf, ":qall!\<CR>")
|
|
|
|
call WaitFor({-> job_status(job) ==# 'dead'})
|
|
|
|
if has('unix')
|
|
|
|
call assert_equal('', job_info(job).termsig)
|
|
|
|
endif
|
|
|
|
|
|
|
|
call delete('Xtest.vim')
|
|
|
|
exe buf .. 'bwipe!'
|
|
|
|
endfunc
|
|
|
|
|
2022-07-11 16:22:17 -07:00
|
|
|
" Test for garbage collection when a timer is still running
|
|
|
|
func Test_timer_garbage_collect()
|
|
|
|
let timer = timer_start(1000, function('MyHandler'), {'repeat' : 10})
|
|
|
|
call test_garbagecollect_now()
|
|
|
|
let l = timer_info(timer)
|
|
|
|
call assert_equal(function('MyHandler'), l[0].callback)
|
|
|
|
call timer_stop(timer)
|
|
|
|
endfunc
|
|
|
|
|
2020-03-07 21:15:25 -07:00
|
|
|
func Test_timer_invalid_callback()
|
|
|
|
call assert_fails('call timer_start(0, "0")', 'E921')
|
|
|
|
endfunc
|
|
|
|
|
2022-10-23 22:48:51 -07:00
|
|
|
func Test_timer_changing_function_list()
|
|
|
|
CheckRunVimInTerminal
|
|
|
|
|
|
|
|
" Create a large number of functions. Should get the "more" prompt.
|
|
|
|
" The typing "G" triggers the timer, which changes the function table.
|
|
|
|
let lines =<< trim END
|
|
|
|
for func in map(range(1,99), "'Func' .. v:val")
|
|
|
|
exe "func " .. func .. "()"
|
|
|
|
endfunc
|
|
|
|
endfor
|
|
|
|
au CmdlineLeave : call timer_start(0, {-> 0})
|
|
|
|
END
|
|
|
|
call writefile(lines, 'XTest_timerchange')
|
|
|
|
let buf = RunVimInTerminal('-S XTest_timerchange', #{rows: 10})
|
|
|
|
call term_sendkeys(buf, ":fu\<CR>")
|
|
|
|
call WaitForAssert({-> assert_match('-- More --', term_getline(buf, 10))})
|
|
|
|
call term_sendkeys(buf, "G")
|
|
|
|
call WaitForAssert({-> assert_match('E454', term_getline(buf, 9))})
|
|
|
|
call term_sendkeys(buf, "\<Esc>")
|
|
|
|
|
|
|
|
call StopVimInTerminal(buf)
|
|
|
|
call delete('XTest_timerchange')
|
|
|
|
endfunc
|
|
|
|
|
2022-01-20 14:14:40 -07:00
|
|
|
func Test_timer_using_win_execute_undo_sync()
|
|
|
|
let bufnr1 = bufnr()
|
|
|
|
new
|
|
|
|
let g:bufnr2 = bufnr()
|
|
|
|
let g:winid = win_getid()
|
|
|
|
exe "buffer " .. bufnr1
|
|
|
|
wincmd w
|
|
|
|
call setline(1, ['test'])
|
|
|
|
autocmd InsertEnter * call timer_start(100, { -> win_execute(g:winid, 'buffer ' .. g:bufnr2) })
|
|
|
|
call timer_start(200, { -> feedkeys("\<CR>bbbb\<Esc>") })
|
|
|
|
call feedkeys("Oaaaa", 'x!t')
|
|
|
|
" will hang here until the second timer fires
|
|
|
|
call assert_equal(['aaaa', 'bbbb', 'test'], getline(1, '$'))
|
|
|
|
undo
|
|
|
|
call assert_equal(['test'], getline(1, '$'))
|
|
|
|
|
|
|
|
bwipe!
|
|
|
|
bwipe!
|
|
|
|
unlet g:winid
|
|
|
|
unlet g:bufnr2
|
|
|
|
au! InsertEnter
|
|
|
|
endfunc
|
|
|
|
|
2017-03-14 01:58:13 -07:00
|
|
|
" vim: shiftwidth=2 sts=2 expandtab
|