summaryrefslogtreecommitdiff
path: root/src/testdir/test_timers.vim
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-05-12 15:38:26 +0200
committerBram Moolenaar <Bram@vim.org>2018-05-12 15:38:26 +0200
commitb0f42ba60d9e6d101d103421ba0c351811615c15 (patch)
tree083b82fcd12fc95a90d779898a6a2b9939ef7837 /src/testdir/test_timers.vim
parentff3be4fe1e2e723de48b826cb992c798e296c41e (diff)
downloadvim-git-b0f42ba60d9e6d101d103421ba0c351811615c15.tar.gz
patch 8.0.1817: a timer may change v:count unexpectedlyv8.0.1817
Problem: A timer may change v:count unexpectedly. Solution: Save and restore v:count and similar variables when a timer callback is invoked. (closes #2897)
Diffstat (limited to 'src/testdir/test_timers.vim')
-rw-r--r--src/testdir/test_timers.vim32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/testdir/test_timers.vim b/src/testdir/test_timers.vim
index 79a5ba58c..bccd31b93 100644
--- a/src/testdir/test_timers.vim
+++ b/src/testdir/test_timers.vim
@@ -5,6 +5,7 @@ if !has('timers')
endif
source shared.vim
+source screendump.vim
func MyHandler(timer)
let g:val += 1
@@ -260,4 +261,35 @@ func Test_ex_mode()
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