annotate src/testdir/test_lambda.vim @ 29868:6ab2c61291ac

Added tag v9.0.0272 for changeset 6eaef7375f17777ce6ba592ed21a22e04bf07d69
author Bram Moolenaar <Bram@vim.org>
date Fri, 26 Aug 2022 13:00:05 +0200
parents 67f005ab37d7
children 58fb880f3607
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
1 " Test for lambda and closure
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
2
21765
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
3 source check.vim
28515
c6aadb2c4cd7 patch 8.2.4782: accessing freed memory
Bram Moolenaar <Bram@vim.org>
parents: 28499
diff changeset
4 import './vim9.vim' as v9
21765
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
5
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
6 func Test_lambda_feature()
9690
4a7a88404076 commit https://github.com/vim/vim/commit/9532fe7fbe1b14531931e83bd9f8054efdcf7509
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
7 call assert_equal(1, has('lambda'))
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
8 endfunc
9690
4a7a88404076 commit https://github.com/vim/vim/commit/9532fe7fbe1b14531931e83bd9f8054efdcf7509
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
9
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
10 func Test_lambda_with_filter()
9527
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 let s:x = 2
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 call assert_equal([2, 3], filter([1, 2, 3], {i, v -> v >= s:x}))
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
13 endfunc
9527
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
15 func Test_lambda_with_map()
9527
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 let s:x = 1
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 call assert_equal([2, 3, 4], map([1, 2, 3], {i, v -> v + s:x}))
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
18 endfunc
9527
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
20 func Test_lambda_with_sort()
9527
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 call assert_equal([1, 2, 3, 4, 7], sort([3,7,2,1,4], {a, b -> a - b}))
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
22 endfunc
9527
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
24 func Test_lambda_with_timer()
21765
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
25 CheckFeature timers
9527
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 let s:n = 0
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 let s:timer_id = 0
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
29 func! s:Foo()
17480
91cac682b09a patch 8.1.1738: testing lambda with timer is slow
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
30 let s:timer_id = timer_start(10, {-> execute("let s:n += 1 | echo s:n", "")}, {"repeat": -1})
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
31 endfunc
9527
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 call s:Foo()
17480
91cac682b09a patch 8.1.1738: testing lambda with timer is slow
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
34 " check timer works
91cac682b09a patch 8.1.1738: testing lambda with timer is slow
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
35 for i in range(0, 10)
91cac682b09a patch 8.1.1738: testing lambda with timer is slow
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
36 if s:n > 0
91cac682b09a patch 8.1.1738: testing lambda with timer is slow
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
37 break
91cac682b09a patch 8.1.1738: testing lambda with timer is slow
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
38 endif
91cac682b09a patch 8.1.1738: testing lambda with timer is slow
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
39 sleep 10m
91cac682b09a patch 8.1.1738: testing lambda with timer is slow
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
40 endfor
91cac682b09a patch 8.1.1738: testing lambda with timer is slow
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
41
9527
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 " do not collect lambda
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 call test_garbagecollect_now()
17480
91cac682b09a patch 8.1.1738: testing lambda with timer is slow
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
44
91cac682b09a patch 8.1.1738: testing lambda with timer is slow
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
45 " check timer still works
9527
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 let m = s:n
17480
91cac682b09a patch 8.1.1738: testing lambda with timer is slow
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
47 for i in range(0, 10)
91cac682b09a patch 8.1.1738: testing lambda with timer is slow
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
48 if s:n > m
91cac682b09a patch 8.1.1738: testing lambda with timer is slow
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
49 break
91cac682b09a patch 8.1.1738: testing lambda with timer is slow
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
50 endif
91cac682b09a patch 8.1.1738: testing lambda with timer is slow
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
51 sleep 10m
91cac682b09a patch 8.1.1738: testing lambda with timer is slow
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
52 endfor
91cac682b09a patch 8.1.1738: testing lambda with timer is slow
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
53
9527
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 call timer_stop(s:timer_id)
17480
91cac682b09a patch 8.1.1738: testing lambda with timer is slow
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
55 call assert_true(s:n > m)
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
56 endfunc
9527
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57
28515
c6aadb2c4cd7 patch 8.2.4782: accessing freed memory
Bram Moolenaar <Bram@vim.org>
parents: 28499
diff changeset
58 func Test_lambda_vim9cmd_linebreak()
c6aadb2c4cd7 patch 8.2.4782: accessing freed memory
Bram Moolenaar <Bram@vim.org>
parents: 28499
diff changeset
59 CheckFeature timers
c6aadb2c4cd7 patch 8.2.4782: accessing freed memory
Bram Moolenaar <Bram@vim.org>
parents: 28499
diff changeset
60
28520
2748a023cc37 patch 8.2.4784: lamba test with timer is flaky
Bram Moolenaar <Bram@vim.org>
parents: 28515
diff changeset
61 let g:test_is_flaky = 1
28515
c6aadb2c4cd7 patch 8.2.4782: accessing freed memory
Bram Moolenaar <Bram@vim.org>
parents: 28499
diff changeset
62 let lines =<< trim END
c6aadb2c4cd7 patch 8.2.4782: accessing freed memory
Bram Moolenaar <Bram@vim.org>
parents: 28499
diff changeset
63 vim9cmd call timer_start(10, (x) => {
c6aadb2c4cd7 patch 8.2.4782: accessing freed memory
Bram Moolenaar <Bram@vim.org>
parents: 28499
diff changeset
64 # comment
c6aadb2c4cd7 patch 8.2.4782: accessing freed memory
Bram Moolenaar <Bram@vim.org>
parents: 28499
diff changeset
65 g:result = 'done'
c6aadb2c4cd7 patch 8.2.4782: accessing freed memory
Bram Moolenaar <Bram@vim.org>
parents: 28499
diff changeset
66 })
c6aadb2c4cd7 patch 8.2.4782: accessing freed memory
Bram Moolenaar <Bram@vim.org>
parents: 28499
diff changeset
67 END
c6aadb2c4cd7 patch 8.2.4782: accessing freed memory
Bram Moolenaar <Bram@vim.org>
parents: 28499
diff changeset
68 call v9.CheckScriptSuccess(lines)
28520
2748a023cc37 patch 8.2.4784: lamba test with timer is flaky
Bram Moolenaar <Bram@vim.org>
parents: 28515
diff changeset
69 " sleep longer on a retry
2748a023cc37 patch 8.2.4784: lamba test with timer is flaky
Bram Moolenaar <Bram@vim.org>
parents: 28515
diff changeset
70 exe 'sleep ' .. [20, 100, 500, 500, 500][g:run_nr] .. 'm'
28515
c6aadb2c4cd7 patch 8.2.4782: accessing freed memory
Bram Moolenaar <Bram@vim.org>
parents: 28499
diff changeset
71 call assert_equal('done', g:result)
c6aadb2c4cd7 patch 8.2.4782: accessing freed memory
Bram Moolenaar <Bram@vim.org>
parents: 28499
diff changeset
72 unlet g:result
28745
67f005ab37d7 patch 8.2.4897: comment inside an expression in lambda ignores the rest
Bram Moolenaar <Bram@vim.org>
parents: 28520
diff changeset
73
67f005ab37d7 patch 8.2.4897: comment inside an expression in lambda ignores the rest
Bram Moolenaar <Bram@vim.org>
parents: 28520
diff changeset
74 let lines =<< trim END
67f005ab37d7 patch 8.2.4897: comment inside an expression in lambda ignores the rest
Bram Moolenaar <Bram@vim.org>
parents: 28520
diff changeset
75 g:result = [0]->map((_, v) =>
67f005ab37d7 patch 8.2.4897: comment inside an expression in lambda ignores the rest
Bram Moolenaar <Bram@vim.org>
parents: 28520
diff changeset
76 1 # inline comment
67f005ab37d7 patch 8.2.4897: comment inside an expression in lambda ignores the rest
Bram Moolenaar <Bram@vim.org>
parents: 28520
diff changeset
77 +
67f005ab37d7 patch 8.2.4897: comment inside an expression in lambda ignores the rest
Bram Moolenaar <Bram@vim.org>
parents: 28520
diff changeset
78 2
67f005ab37d7 patch 8.2.4897: comment inside an expression in lambda ignores the rest
Bram Moolenaar <Bram@vim.org>
parents: 28520
diff changeset
79 )
67f005ab37d7 patch 8.2.4897: comment inside an expression in lambda ignores the rest
Bram Moolenaar <Bram@vim.org>
parents: 28520
diff changeset
80 assert_equal([3], g:result)
67f005ab37d7 patch 8.2.4897: comment inside an expression in lambda ignores the rest
Bram Moolenaar <Bram@vim.org>
parents: 28520
diff changeset
81 END
67f005ab37d7 patch 8.2.4897: comment inside an expression in lambda ignores the rest
Bram Moolenaar <Bram@vim.org>
parents: 28520
diff changeset
82 call v9.CheckDefAndScriptSuccess(lines)
28515
c6aadb2c4cd7 patch 8.2.4782: accessing freed memory
Bram Moolenaar <Bram@vim.org>
parents: 28499
diff changeset
83 endfunc
c6aadb2c4cd7 patch 8.2.4782: accessing freed memory
Bram Moolenaar <Bram@vim.org>
parents: 28499
diff changeset
84
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
85 func Test_lambda_with_partial()
9527
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
86 let l:Cb = function({... -> ['zero', a:1, a:2, a:3]}, ['one', 'two'])
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
87 call assert_equal(['zero', 'one', 'two', 'three'], l:Cb('three'))
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
88 endfunc
9527
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
89
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
90 function Test_lambda_fails()
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
91 call assert_equal(3, {a, b -> a + b}(1, 2))
15456
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
92 call assert_fails('echo {a, a -> a + a}(1, 2)', 'E853:')
19826
293a22b677a8 patch 8.2.0469: Vim9: no error for missing ] after list
Bram Moolenaar <Bram@vim.org>
parents: 19724
diff changeset
93 call assert_fails('echo {a, b -> a + b)}(1, 2)', 'E451:')
19724
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
94 echo assert_fails('echo 10->{a -> a + 2}', 'E107:')
26636
6047c7ea7963 patch 8.2.3847: illegal memory access when using a lambda with an error
Bram Moolenaar <Bram@vim.org>
parents: 25118
diff changeset
95
6047c7ea7963 patch 8.2.3847: illegal memory access when using a lambda with an error
Bram Moolenaar <Bram@vim.org>
parents: 25118
diff changeset
96 call assert_fails('eval 0->(', "E110: Missing ')'")
28499
a35d54d01ade patch 8.2.4774: crash when using a number for lambda name
Bram Moolenaar <Bram@vim.org>
parents: 26636
diff changeset
97 call assert_fails('eval 0->(3)()', "E1275:")
a35d54d01ade patch 8.2.4774: crash when using a number for lambda name
Bram Moolenaar <Bram@vim.org>
parents: 26636
diff changeset
98 call assert_fails('eval 0->([3])()', "E1275:")
a35d54d01ade patch 8.2.4774: crash when using a number for lambda name
Bram Moolenaar <Bram@vim.org>
parents: 26636
diff changeset
99 call assert_fails('eval 0->({"a": 3})()', "E1275:")
a35d54d01ade patch 8.2.4774: crash when using a number for lambda name
Bram Moolenaar <Bram@vim.org>
parents: 26636
diff changeset
100 call assert_fails('eval 0->(xxx)()', "E121:")
9527
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
101 endfunc
9597
3ca0fd9709b1 commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents: 9527
diff changeset
102
3ca0fd9709b1 commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents: 9527
diff changeset
103 func Test_not_lamda()
3ca0fd9709b1 commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents: 9527
diff changeset
104 let x = {'>' : 'foo'}
3ca0fd9709b1 commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents: 9527
diff changeset
105 call assert_equal('foo', x['>'])
3ca0fd9709b1 commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents: 9527
diff changeset
106 endfunc
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
107
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
108 func Test_lambda_capture_by_reference()
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
109 let v = 1
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
110 let l:F = {x -> x + v}
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
111 let v = 2
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
112 call assert_equal(12, l:F(10))
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
113 endfunc
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
114
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
115 func Test_lambda_side_effect()
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
116 func! s:update_and_return(arr)
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
117 let a:arr[1] = 5
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
118 return a:arr
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
119 endfunc
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
120
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
121 func! s:foo(arr)
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
122 return {-> s:update_and_return(a:arr)}
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
123 endfunc
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
124
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
125 let arr = [3,2,1]
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
126 call assert_equal([3, 5, 1], s:foo(arr)())
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
127 endfunc
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
128
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
129 func Test_lambda_refer_local_variable_from_other_scope()
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
130 func! s:foo(X)
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
131 return a:X() " refer l:x in s:bar()
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
132 endfunc
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
133
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
134 func! s:bar()
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
135 let x = 123
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
136 return s:foo({-> x})
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
137 endfunc
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
138
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
139 call assert_equal(123, s:bar())
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
140 endfunc
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
141
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
142 func Test_lambda_do_not_share_local_variable()
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
143 func! s:define_funcs()
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
144 let l:One = {-> split(execute("let a = 'abc' | echo a"))[0]}
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
145 let l:Two = {-> exists("a") ? a : "no"}
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
146 return [l:One, l:Two]
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
147 endfunc
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
148
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
149 let l:F = s:define_funcs()
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
150
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
151 call assert_equal('no', l:F[1]())
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
152 call assert_equal('abc', l:F[0]())
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
153 call assert_equal('no', l:F[1]())
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
154 endfunc
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
155
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
156 func Test_lambda_closure_counter()
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
157 func! s:foo()
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
158 let x = 0
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
159 return {-> [execute("let x += 1"), x][-1]}
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
160 endfunc
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
161
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
162 let l:F = s:foo()
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
163 call test_garbagecollect_now()
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
164 call assert_equal(1, l:F())
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
165 call assert_equal(2, l:F())
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
166 call assert_equal(3, l:F())
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
167 call assert_equal(4, l:F())
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
168 endfunc
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
169
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
170 func Test_lambda_with_a_var()
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
171 func! s:foo()
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
172 let x = 2
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
173 return {... -> a:000 + [x]}
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
174 endfunc
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
175 func! s:bar()
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
176 return s:foo()(1)
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
177 endfunc
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
178
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
179 call assert_equal([1, 2], s:bar())
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
180 endfunc
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
181
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
182 func Test_lambda_call_lambda_from_lambda()
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
183 func! s:foo(x)
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
184 let l:F1 = {-> {-> a:x}}
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
185 return {-> l:F1()}
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
186 endfunc
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
187
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
188 let l:F = s:foo(1)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
189 call assert_equal(1, l:F()())
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
190 endfunc
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
191
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
192 func Test_lambda_delfunc()
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
193 func! s:gen()
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
194 let pl = l:
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
195 let l:Foo = {-> get(pl, "Foo", get(pl, "Bar", {-> 0}))}
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
196 let l:Bar = l:Foo
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
197 delfunction l:Foo
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
198 return l:Bar
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
199 endfunc
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
200
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
201 let l:F = s:gen()
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
202 call assert_fails(':call l:F()', 'E933:')
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
203 endfunc
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
204
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
205 func Test_lambda_scope()
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
206 func! s:NewCounter()
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
207 let c = 0
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
208 return {-> [execute('let c += 1'), c][-1]}
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
209 endfunc
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
210
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
211 func! s:NewCounter2()
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
212 return {-> [execute('let c += 100'), c][-1]}
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
213 endfunc
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
214
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
215 let l:C = s:NewCounter()
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
216 let l:D = s:NewCounter2()
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
217
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
218 call assert_equal(1, l:C())
15456
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
219 call assert_fails(':call l:D()', 'E121:')
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
220 call assert_equal(2, l:C())
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
221 endfunc
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
222
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
223 func Test_lambda_share_scope()
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
224 func! s:New()
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
225 let c = 0
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
226 let l:Inc0 = {-> [execute('let c += 1'), c][-1]}
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
227 let l:Dec0 = {-> [execute('let c -= 1'), c][-1]}
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
228 return [l:Inc0, l:Dec0]
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
229 endfunc
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
230
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
231 let [l:Inc, l:Dec] = s:New()
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
232
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
233 call assert_equal(1, l:Inc())
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
234 call assert_equal(2, l:Inc())
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
235 call assert_equal(1, l:Dec())
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
236 endfunc
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
237
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
238 func Test_lambda_circular_reference()
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
239 func! s:Foo()
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
240 let d = {}
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
241 let d.f = {-> d}
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
242 return d.f
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
243 endfunc
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
244
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
245 call s:Foo()
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
246 call test_garbagecollect_now()
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
247 let i = 0 | while i < 10000 | call s:Foo() | let i+= 1 | endwhile
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
248 call test_garbagecollect_now()
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
249 endfunc
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
250
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
251 func Test_lambda_combination()
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
252 call assert_equal(2, {x -> {x -> x}}(1)(2))
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
253 call assert_equal(10, {y -> {x -> x(y)(10)}({y -> y})}({z -> z}))
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18851
diff changeset
254 if has('float')
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18851
diff changeset
255 call assert_equal(5.0, {x -> {y -> x / y}}(10)(2.0))
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18851
diff changeset
256 endif
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
257 call assert_equal(6, {x -> {y -> {z -> x + y + z}}}(1)(2)(3))
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
258
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
259 call assert_equal(6, {x -> {f -> f(x)}}(3)({x -> x * 2}))
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
260 call assert_equal(6, {f -> {x -> f(x)}}({x -> x * 2})(3))
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
261
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
262 " Z combinator
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
263 let Z = {f -> {x -> f({y -> x(x)(y)})}({x -> f({y -> x(x)(y)})})}
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
264 let Fact = {f -> {x -> x == 0 ? 1 : x * f(x - 1)}}
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9597
diff changeset
265 call assert_equal(120, Z(Fact)(5))
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
266 endfunc
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
267
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
268 func Test_closure_counter()
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
269 func! s:foo()
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
270 let x = 0
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
271 func! s:bar() closure
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
272 let x += 1
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
273 return x
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
274 endfunc
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
275 return function('s:bar')
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
276 endfunc
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
277
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
278 let l:F = s:foo()
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
279 call test_garbagecollect_now()
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
280 call assert_equal(1, l:F())
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
281 call assert_equal(2, l:F())
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
282 call assert_equal(3, l:F())
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
283 call assert_equal(4, l:F())
23108
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
284
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
285 call assert_match("^\n function <SNR>\\d\\+_bar() closure"
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
286 \ .. "\n1 let x += 1"
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
287 \ .. "\n2 return x"
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
288 \ .. "\n endfunction$", execute('func s:bar'))
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
289 endfunc
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
290
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
291 func Test_closure_unlet()
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
292 func! s:foo()
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
293 let x = 1
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
294 func! s:bar() closure
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
295 unlet x
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
296 endfunc
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
297 call s:bar()
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
298 return l:
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
299 endfunc
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
300
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
301 call assert_false(has_key(s:foo(), 'x'))
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
302 call test_garbagecollect_now()
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
303 endfunc
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9690
diff changeset
304
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
305 func LambdaFoo()
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9690
diff changeset
306 let x = 0
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
307 func! LambdaBar() closure
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9690
diff changeset
308 let x += 1
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9690
diff changeset
309 return x
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
310 endfunc
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9690
diff changeset
311 return function('LambdaBar')
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14002
diff changeset
312 endfunc
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9690
diff changeset
313
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9690
diff changeset
314 func Test_closure_refcount()
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9690
diff changeset
315 let g:Count = LambdaFoo()
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9690
diff changeset
316 call test_garbagecollect_now()
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9690
diff changeset
317 call assert_equal(1, g:Count())
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9690
diff changeset
318 let g:Count2 = LambdaFoo()
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9690
diff changeset
319 call test_garbagecollect_now()
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9690
diff changeset
320 call assert_equal(1, g:Count2())
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9690
diff changeset
321 call assert_equal(2, g:Count())
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9690
diff changeset
322 call assert_equal(3, g:Count2())
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9690
diff changeset
323
9727
8436bb5134f5 commit https://github.com/vim/vim/commit/0588d4f9d2741f35a271400a37fddbdd72d84219
Christian Brabandt <cb@256bit.org>
parents: 9723
diff changeset
324 delfunc LambdaFoo
8436bb5134f5 commit https://github.com/vim/vim/commit/0588d4f9d2741f35a271400a37fddbdd72d84219
Christian Brabandt <cb@256bit.org>
parents: 9723
diff changeset
325 delfunc LambdaBar
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9690
diff changeset
326 endfunc
9735
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
327
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
328 func Test_named_function_closure()
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
329 func! Afoo()
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
330 let x = 14
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
331 func! s:Abar() closure
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
332 return x
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
333 endfunc
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
334 call assert_equal(14, s:Abar())
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
335 endfunc
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
336 call Afoo()
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
337 call assert_equal(14, s:Abar())
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
338 call test_garbagecollect_now()
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
339 call assert_equal(14, s:Abar())
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
340 endfunc
14002
ade79e3e3b88 patch 8.1.0019: error when defining a Lambda with index of a function result
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
341
ade79e3e3b88 patch 8.1.0019: error when defining a Lambda with index of a function result
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
342 func Test_lambda_with_index()
ade79e3e3b88 patch 8.1.0019: error when defining a Lambda with index of a function result
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
343 let List = {x -> [x]}
ade79e3e3b88 patch 8.1.0019: error when defining a Lambda with index of a function result
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
344 let Extract = {-> function(List, ['foobar'])()[0]}
ade79e3e3b88 patch 8.1.0019: error when defining a Lambda with index of a function result
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
345 call assert_equal('foobar', Extract())
ade79e3e3b88 patch 8.1.0019: error when defining a Lambda with index of a function result
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
346 endfunc
18851
3cf9529b3a4a patch 8.1.2412: crash when evaluating expression with error
Bram Moolenaar <Bram@vim.org>
parents: 17480
diff changeset
347
3cf9529b3a4a patch 8.1.2412: crash when evaluating expression with error
Bram Moolenaar <Bram@vim.org>
parents: 17480
diff changeset
348 func Test_lambda_error()
3cf9529b3a4a patch 8.1.2412: crash when evaluating expression with error
Bram Moolenaar <Bram@vim.org>
parents: 17480
diff changeset
349 " This was causing a crash
22087
ff21e2962490 patch 8.2.1593: tests do not check the error number properly
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
350 call assert_fails('ec{@{->{d->()()', 'E15:')
18851
3cf9529b3a4a patch 8.1.2412: crash when evaluating expression with error
Bram Moolenaar <Bram@vim.org>
parents: 17480
diff changeset
351 endfunc
19724
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
352
19932
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19826
diff changeset
353 func Test_closure_error()
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19826
diff changeset
354 let l =<< trim END
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19826
diff changeset
355 func F1() closure
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19826
diff changeset
356 return 1
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19826
diff changeset
357 endfunc
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19826
diff changeset
358 END
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19826
diff changeset
359 call writefile(l, 'Xscript')
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19826
diff changeset
360 let caught_932 = 0
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19826
diff changeset
361 try
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19826
diff changeset
362 source Xscript
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19826
diff changeset
363 catch /E932:/
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19826
diff changeset
364 let caught_932 = 1
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19826
diff changeset
365 endtry
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19826
diff changeset
366 call assert_equal(1, caught_932)
25118
12fd67997953 patch 8.2.3096: temp files remain after running tests
Bram Moolenaar <Bram@vim.org>
parents: 23108
diff changeset
367 call delete('Xscript')
19932
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19826
diff changeset
368 endfunc
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19826
diff changeset
369
19724
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
370 " vim: shiftwidth=2 sts=2 expandtab