comparison src/testdir/test_lambda.vim @ 17480:91cac682b09a v8.1.1738

patch 8.1.1738: testing lambda with timer is slow commit https://github.com/vim/vim/commit/9bc4dde45d45df732953491d0f2c3fd3b10a627e Author: Bram Moolenaar <Bram@vim.org> Date: Wed Jul 24 13:08:29 2019 +0200 patch 8.1.1738: testing lambda with timer is slow Problem: Testing lambda with timer is slow. Solution: Do not test timer accuracy, only that it works. (Daniel Hahler, closes #4723)
author Bram Moolenaar <Bram@vim.org>
date Wed, 24 Jul 2019 13:15:06 +0200
parents f01eb1aed348
children 3cf9529b3a4a
comparison
equal deleted inserted replaced
17479:35b73ec0ba25 17480:91cac682b09a
24 endif 24 endif
25 25
26 let s:n = 0 26 let s:n = 0
27 let s:timer_id = 0 27 let s:timer_id = 0
28 func! s:Foo() 28 func! s:Foo()
29 "let n = 0 29 let s:timer_id = timer_start(10, {-> execute("let s:n += 1 | echo s:n", "")}, {"repeat": -1})
30 let s:timer_id = timer_start(50, {-> execute("let s:n += 1 | echo s:n", "")}, {"repeat": -1})
31 endfunc 30 endfunc
32 31
33 call s:Foo() 32 call s:Foo()
34 sleep 200ms 33 " check timer works
34 for i in range(0, 10)
35 if s:n > 0
36 break
37 endif
38 sleep 10m
39 endfor
40
35 " do not collect lambda 41 " do not collect lambda
36 call test_garbagecollect_now() 42 call test_garbagecollect_now()
43
44 " check timer still works
37 let m = s:n 45 let m = s:n
38 sleep 200ms 46 for i in range(0, 10)
47 if s:n > m
48 break
49 endif
50 sleep 10m
51 endfor
52
39 call timer_stop(s:timer_id) 53 call timer_stop(s:timer_id)
40 call assert_true(m > 1) 54 call assert_true(s:n > m)
41 call assert_true(s:n > m + 1)
42 call assert_true(s:n < 9)
43 endfunc 55 endfunc
44 56
45 func Test_lambda_with_partial() 57 func Test_lambda_with_partial()
46 let l:Cb = function({... -> ['zero', a:1, a:2, a:3]}, ['one', 'two']) 58 let l:Cb = function({... -> ['zero', a:1, a:2, a:3]}, ['one', 'two'])
47 call assert_equal(['zero', 'one', 'two', 'three'], l:Cb('three')) 59 call assert_equal(['zero', 'one', 'two', 'three'], l:Cb('three'))