annotate src/testdir/test_timers.vim @ 8734:986f7c00d43d v7.4.1656

commit https://github.com/vim/vim/commit/92e35efaf6a3278e4729115648997f09cd4005f5 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Mar 26 18:20:41 2016 +0100 patch 7.4.1656 Problem: Crash when using partial with a timer. Solution: Increment partial reference count. (Hirohito Higashi)
author Christian Brabandt <cb@256bit.org>
date Sat, 26 Mar 2016 18:30:06 +0100
parents 63dc856bd13d
children c2fe86f2bda1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8577
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Test for timers
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 if !has('timers')
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 finish
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 endif
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 func MyHandler(timer)
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 let s:val += 1
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 endfunc
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 func Test_oneshot()
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 let s:val = 0
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 let timer = timer_start(50, 'MyHandler')
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 sleep 200m
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 call assert_equal(1, s:val)
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 endfunc
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 func Test_repeat_three()
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 let s:val = 0
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 let timer = timer_start(50, 'MyHandler', {'repeat': 3})
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 sleep 500m
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 call assert_equal(3, s:val)
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 endfunc
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 func Test_repeat_many()
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 let s:val = 0
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 let timer = timer_start(50, 'MyHandler', {'repeat': -1})
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 sleep 200m
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 call timer_stop(timer)
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 call assert_true(s:val > 1)
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 call assert_true(s:val < 5)
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 endfunc
8734
986f7c00d43d commit https://github.com/vim/vim/commit/92e35efaf6a3278e4729115648997f09cd4005f5
Christian Brabandt <cb@256bit.org>
parents: 8577
diff changeset
33
986f7c00d43d commit https://github.com/vim/vim/commit/92e35efaf6a3278e4729115648997f09cd4005f5
Christian Brabandt <cb@256bit.org>
parents: 8577
diff changeset
34 func Test_with_partial_callback()
986f7c00d43d commit https://github.com/vim/vim/commit/92e35efaf6a3278e4729115648997f09cd4005f5
Christian Brabandt <cb@256bit.org>
parents: 8577
diff changeset
35 let s:val = 0
986f7c00d43d commit https://github.com/vim/vim/commit/92e35efaf6a3278e4729115648997f09cd4005f5
Christian Brabandt <cb@256bit.org>
parents: 8577
diff changeset
36 let s:meow = {}
986f7c00d43d commit https://github.com/vim/vim/commit/92e35efaf6a3278e4729115648997f09cd4005f5
Christian Brabandt <cb@256bit.org>
parents: 8577
diff changeset
37 function s:meow.bite(...)
986f7c00d43d commit https://github.com/vim/vim/commit/92e35efaf6a3278e4729115648997f09cd4005f5
Christian Brabandt <cb@256bit.org>
parents: 8577
diff changeset
38 let s:val += 1
986f7c00d43d commit https://github.com/vim/vim/commit/92e35efaf6a3278e4729115648997f09cd4005f5
Christian Brabandt <cb@256bit.org>
parents: 8577
diff changeset
39 endfunction
986f7c00d43d commit https://github.com/vim/vim/commit/92e35efaf6a3278e4729115648997f09cd4005f5
Christian Brabandt <cb@256bit.org>
parents: 8577
diff changeset
40
986f7c00d43d commit https://github.com/vim/vim/commit/92e35efaf6a3278e4729115648997f09cd4005f5
Christian Brabandt <cb@256bit.org>
parents: 8577
diff changeset
41 call timer_start(50, s:meow.bite)
986f7c00d43d commit https://github.com/vim/vim/commit/92e35efaf6a3278e4729115648997f09cd4005f5
Christian Brabandt <cb@256bit.org>
parents: 8577
diff changeset
42 sleep 200m
986f7c00d43d commit https://github.com/vim/vim/commit/92e35efaf6a3278e4729115648997f09cd4005f5
Christian Brabandt <cb@256bit.org>
parents: 8577
diff changeset
43 call assert_equal(1, s:val)
986f7c00d43d commit https://github.com/vim/vim/commit/92e35efaf6a3278e4729115648997f09cd4005f5
Christian Brabandt <cb@256bit.org>
parents: 8577
diff changeset
44 endfunc
986f7c00d43d commit https://github.com/vim/vim/commit/92e35efaf6a3278e4729115648997f09cd4005f5
Christian Brabandt <cb@256bit.org>
parents: 8577
diff changeset
45 " vim: ts=2 sw=0 et