diff options
-rw-r--r-- | src/nvim/testdir/test_timers.vim | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/src/nvim/testdir/test_timers.vim b/src/nvim/testdir/test_timers.vim index bd63d94729..6c336e6fa6 100644 --- a/src/nvim/testdir/test_timers.vim +++ b/src/nvim/testdir/test_timers.vim @@ -5,6 +5,7 @@ if !has('timers') endif source shared.vim +source screendump.vim source load.vim func MyHandler(timer) @@ -252,15 +253,65 @@ func Test_peek_and_get_char() call timer_stop(intr) endfunc +func Test_getchar_zero() + if has('win32') + " Console: no low-level input + " GUI: somehow doesn't work + return + endif + + " Measure the elapsed time to avoid a hang when it fails. + let start = reltime() + let id = timer_start(20, {id -> feedkeys('x', 'L')}) + let c = 0 + while c == 0 && reltimefloat(reltime(start)) < 0.2 + let c = getchar(0) + sleep 10m + endwhile + call assert_equal('x', nr2char(c)) + call timer_stop(id) +endfunc + func Test_ex_mode() " Function with an empty line. func Foo(...) endfunc - let timer = timer_start(40, function('g:Foo'), {'repeat':-1}) + let timer = timer_start(40, function('g:Foo'), {'repeat':-1}) " This used to throw error E749. exe "normal Qsleep 100m\rvi\r" call timer_stop(timer) endfunc +func Test_restore_count() + if !CanRunVimInTerminal() + return + endif + " 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 + " vim: shiftwidth=2 sts=2 expandtab |