Mercurial > vim
annotate src/testdir/test_lambda.vim @ 28303:9849df834f1d v8.2.4677
patch 8.2.4677: the Athena GUI support is outdated
Commit: https://github.com/vim/vim/commit/0b962e5685edd41b55d5427b894797e725707639
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Apr 3 18:02:37 2022 +0100
patch 8.2.4677: the Athena GUI support is outdated
Problem: The Athena GUI support is outdated.
Solution: Remove the Athena GUI code.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 03 Apr 2022 19:15:04 +0200 |
parents | 6047c7ea7963 |
children | a35d54d01ade |
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 |
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
4 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
5 func Test_lambda_feature() |
9690
4a7a88404076
commit https://github.com/vim/vim/commit/9532fe7fbe1b14531931e83bd9f8054efdcf7509
Christian Brabandt <cb@256bit.org>
parents:
9688
diff
changeset
|
6 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
|
7 endfunc |
9690
4a7a88404076
commit https://github.com/vim/vim/commit/9532fe7fbe1b14531931e83bd9f8054efdcf7509
Christian Brabandt <cb@256bit.org>
parents:
9688
diff
changeset
|
8 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
9 func Test_lambda_with_filter() |
9527
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
10 let s:x = 2 |
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
11 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
|
12 endfunc |
9527
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
13 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
14 func Test_lambda_with_map() |
9527
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
15 let s:x = 1 |
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
16 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
|
17 endfunc |
9527
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
18 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
19 func Test_lambda_with_sort() |
9527
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
20 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
|
21 endfunc |
9527
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
22 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
23 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
|
24 CheckFeature timers |
9527
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
25 |
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
26 let s:n = 0 |
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
27 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
|
28 func! s:Foo() |
17480
91cac682b09a
patch 8.1.1738: testing lambda with timer is slow
Bram Moolenaar <Bram@vim.org>
parents:
15456
diff
changeset
|
29 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
|
30 endfunc |
9527
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
31 |
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
32 call s:Foo() |
17480
91cac682b09a
patch 8.1.1738: testing lambda with timer is slow
Bram Moolenaar <Bram@vim.org>
parents:
15456
diff
changeset
|
33 " check timer works |
91cac682b09a
patch 8.1.1738: testing lambda with timer is slow
Bram Moolenaar <Bram@vim.org>
parents:
15456
diff
changeset
|
34 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
|
35 if s:n > 0 |
91cac682b09a
patch 8.1.1738: testing lambda with timer is slow
Bram Moolenaar <Bram@vim.org>
parents:
15456
diff
changeset
|
36 break |
91cac682b09a
patch 8.1.1738: testing lambda with timer is slow
Bram Moolenaar <Bram@vim.org>
parents:
15456
diff
changeset
|
37 endif |
91cac682b09a
patch 8.1.1738: testing lambda with timer is slow
Bram Moolenaar <Bram@vim.org>
parents:
15456
diff
changeset
|
38 sleep 10m |
91cac682b09a
patch 8.1.1738: testing lambda with timer is slow
Bram Moolenaar <Bram@vim.org>
parents:
15456
diff
changeset
|
39 endfor |
91cac682b09a
patch 8.1.1738: testing lambda with timer is slow
Bram Moolenaar <Bram@vim.org>
parents:
15456
diff
changeset
|
40 |
9527
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
41 " do not collect lambda |
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
42 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
|
43 |
91cac682b09a
patch 8.1.1738: testing lambda with timer is slow
Bram Moolenaar <Bram@vim.org>
parents:
15456
diff
changeset
|
44 " check timer still works |
9527
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
45 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
|
46 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
|
47 if s:n > m |
91cac682b09a
patch 8.1.1738: testing lambda with timer is slow
Bram Moolenaar <Bram@vim.org>
parents:
15456
diff
changeset
|
48 break |
91cac682b09a
patch 8.1.1738: testing lambda with timer is slow
Bram Moolenaar <Bram@vim.org>
parents:
15456
diff
changeset
|
49 endif |
91cac682b09a
patch 8.1.1738: testing lambda with timer is slow
Bram Moolenaar <Bram@vim.org>
parents:
15456
diff
changeset
|
50 sleep 10m |
91cac682b09a
patch 8.1.1738: testing lambda with timer is slow
Bram Moolenaar <Bram@vim.org>
parents:
15456
diff
changeset
|
51 endfor |
91cac682b09a
patch 8.1.1738: testing lambda with timer is slow
Bram Moolenaar <Bram@vim.org>
parents:
15456
diff
changeset
|
52 |
9527
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
53 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
|
54 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
|
55 endfunc |
9527
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
56 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
57 func Test_lambda_with_partial() |
9527
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
58 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
|
59 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
|
60 endfunc |
9527
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
61 |
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
62 function Test_lambda_fails() |
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
63 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
|
64 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
|
65 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
|
66 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
|
67 |
6047c7ea7963
patch 8.2.3847: illegal memory access when using a lambda with an error
Bram Moolenaar <Bram@vim.org>
parents:
25118
diff
changeset
|
68 call assert_fails('eval 0->(', "E110: Missing ')'") |
9527
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
69 endfunc |
9597
3ca0fd9709b1
commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
70 |
3ca0fd9709b1
commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
71 func Test_not_lamda() |
3ca0fd9709b1
commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
72 let x = {'>' : 'foo'} |
3ca0fd9709b1
commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
73 call assert_equal('foo', x['>']) |
3ca0fd9709b1
commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
74 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
75 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
76 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
|
77 let v = 1 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
78 let l:F = {x -> x + v} |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
79 let v = 2 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
80 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
|
81 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
82 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
83 func Test_lambda_side_effect() |
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
84 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
|
85 let a:arr[1] = 5 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
86 return a:arr |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
87 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
88 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
89 func! s:foo(arr) |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
90 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
|
91 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
92 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
93 let arr = [3,2,1] |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
94 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
|
95 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
96 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
97 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
|
98 func! s:foo(X) |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
99 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
|
100 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
101 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
102 func! s:bar() |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
103 let x = 123 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
104 return s:foo({-> x}) |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
105 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
106 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
107 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
|
108 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
109 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
110 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
|
111 func! s:define_funcs() |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
112 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
|
113 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
|
114 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
|
115 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
116 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
117 let l:F = s:define_funcs() |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
118 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
119 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
|
120 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
|
121 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
|
122 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
123 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
124 func Test_lambda_closure_counter() |
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
125 func! s:foo() |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
126 let x = 0 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
127 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
|
128 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
129 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
130 let l:F = s:foo() |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
131 call test_garbagecollect_now() |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
132 call assert_equal(1, l:F()) |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
133 call assert_equal(2, l:F()) |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
134 call assert_equal(3, l:F()) |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
135 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
|
136 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
137 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
138 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
|
139 func! s:foo() |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
140 let x = 2 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
141 return {... -> a:000 + [x]} |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
142 endfunc |
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
143 func! s:bar() |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
144 return s:foo()(1) |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
145 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
146 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
147 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
|
148 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
149 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
150 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
|
151 func! s:foo(x) |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
152 let l:F1 = {-> {-> a:x}} |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
153 return {-> l:F1()} |
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 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
156 let l:F = s:foo(1) |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
157 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
|
158 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
159 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
160 func Test_lambda_delfunc() |
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
161 func! s:gen() |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
162 let pl = l: |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
163 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
|
164 let l:Bar = l:Foo |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
165 delfunction l:Foo |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
166 return l:Bar |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
167 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
168 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
169 let l:F = s:gen() |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
170 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
|
171 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
172 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
173 func Test_lambda_scope() |
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
174 func! s:NewCounter() |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
175 let c = 0 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
176 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
|
177 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
178 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
179 func! s:NewCounter2() |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
180 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
|
181 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
182 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
183 let l:C = s:NewCounter() |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
184 let l:D = s:NewCounter2() |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
185 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
186 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
|
187 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
|
188 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
|
189 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
190 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
191 func Test_lambda_share_scope() |
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
192 func! s:New() |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
193 let c = 0 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
194 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
|
195 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
|
196 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
|
197 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
198 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
199 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
|
200 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
201 call assert_equal(1, l:Inc()) |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
202 call assert_equal(2, l:Inc()) |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
203 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
|
204 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
205 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
206 func Test_lambda_circular_reference() |
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
207 func! s:Foo() |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
208 let d = {} |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
209 let d.f = {-> d} |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
210 return d.f |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
211 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
212 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
213 call s:Foo() |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
214 call test_garbagecollect_now() |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
215 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
|
216 call test_garbagecollect_now() |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
217 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
218 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
219 func Test_lambda_combination() |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
220 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
|
221 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
|
222 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
|
223 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
|
224 endif |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
225 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
|
226 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
227 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
|
228 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
|
229 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
230 " Z combinator |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
231 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
|
232 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
|
233 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
|
234 endfunc |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
235 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
236 func Test_closure_counter() |
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
237 func! s:foo() |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
238 let x = 0 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
239 func! s:bar() closure |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
240 let x += 1 |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
241 return x |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
242 endfunc |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
243 return function('s:bar') |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
244 endfunc |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
245 |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
246 let l:F = s:foo() |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
247 call test_garbagecollect_now() |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
248 call assert_equal(1, l:F()) |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
249 call assert_equal(2, l:F()) |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
250 call assert_equal(3, l:F()) |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
251 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
|
252 |
34a74f5f0fb4
patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents:
22087
diff
changeset
|
253 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
|
254 \ .. "\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
|
255 \ .. "\n2 return x" |
34a74f5f0fb4
patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents:
22087
diff
changeset
|
256 \ .. "\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
|
257 endfunc |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
258 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
259 func Test_closure_unlet() |
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
260 func! s:foo() |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
261 let x = 1 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
262 func! s:bar() closure |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
263 unlet x |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
264 endfunc |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
265 call s:bar() |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
266 return l: |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
267 endfunc |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
268 |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
269 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
|
270 call test_garbagecollect_now() |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
271 endfunc |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
272 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
273 func LambdaFoo() |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
274 let x = 0 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
275 func! LambdaBar() closure |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
276 let x += 1 |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
277 return x |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
278 endfunc |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
279 return function('LambdaBar') |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
280 endfunc |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
281 |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
282 func Test_closure_refcount() |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
283 let g:Count = LambdaFoo() |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
284 call test_garbagecollect_now() |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
285 call assert_equal(1, g:Count()) |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
286 let g:Count2 = LambdaFoo() |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
287 call test_garbagecollect_now() |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
288 call assert_equal(1, g:Count2()) |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
289 call assert_equal(2, g:Count()) |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
290 call assert_equal(3, g:Count2()) |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
291 |
9727
8436bb5134f5
commit https://github.com/vim/vim/commit/0588d4f9d2741f35a271400a37fddbdd72d84219
Christian Brabandt <cb@256bit.org>
parents:
9723
diff
changeset
|
292 delfunc LambdaFoo |
8436bb5134f5
commit https://github.com/vim/vim/commit/0588d4f9d2741f35a271400a37fddbdd72d84219
Christian Brabandt <cb@256bit.org>
parents:
9723
diff
changeset
|
293 delfunc LambdaBar |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
294 endfunc |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
295 |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
296 func Test_named_function_closure() |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
297 func! Afoo() |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
298 let x = 14 |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
299 func! s:Abar() closure |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
300 return x |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
301 endfunc |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
302 call assert_equal(14, s:Abar()) |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
303 endfunc |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
304 call Afoo() |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
305 call assert_equal(14, s:Abar()) |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
306 call test_garbagecollect_now() |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
307 call assert_equal(14, s:Abar()) |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
308 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
|
309 |
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
|
310 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
|
311 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
|
312 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
|
313 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
|
314 endfunc |
18851
3cf9529b3a4a
patch 8.1.2412: crash when evaluating expression with error
Bram Moolenaar <Bram@vim.org>
parents:
17480
diff
changeset
|
315 |
3cf9529b3a4a
patch 8.1.2412: crash when evaluating expression with error
Bram Moolenaar <Bram@vim.org>
parents:
17480
diff
changeset
|
316 func Test_lambda_error() |
3cf9529b3a4a
patch 8.1.2412: crash when evaluating expression with error
Bram Moolenaar <Bram@vim.org>
parents:
17480
diff
changeset
|
317 " 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
|
318 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
|
319 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
|
320 |
19932
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
321 func Test_closure_error() |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
322 let l =<< trim END |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
323 func F1() closure |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
324 return 1 |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
325 endfunc |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
326 END |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
327 call writefile(l, 'Xscript') |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
328 let caught_932 = 0 |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
329 try |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
330 source Xscript |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
331 catch /E932:/ |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
332 let caught_932 = 1 |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
333 endtry |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
334 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
|
335 call delete('Xscript') |
19932
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
336 endfunc |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
337 |
19724
b3e93a05c3ca
patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
19249
diff
changeset
|
338 " vim: shiftwidth=2 sts=2 expandtab |