Mercurial > vim
annotate src/testdir/test_lambda.vim @ 30930:cbfbf0e17cd0 v9.0.0799
patch 9.0.0799: in compiled function ->() on next line not recognized
Commit: https://github.com/vim/vim/commit/d0fbb41eaa737dd64877c8cebaff19854e2d504f
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Oct 19 18:04:49 2022 +0100
patch 9.0.0799: in compiled function ->() on next line not recognized
Problem: In compiled function ->() on next line not recognized.
Solution: Also check for "(". (closes https://github.com/vim/vim/issues/11405)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 19 Oct 2022 19:15:03 +0200 |
parents | f08ed0738f7a |
children |
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 |
30930
cbfbf0e17cd0
patch 9.0.0799: in compiled function ->() on next line not recognized
Bram Moolenaar <Bram@vim.org>
parents:
30580
diff
changeset
|
85 def Test_lamba_compiled_linebreak() |
cbfbf0e17cd0
patch 9.0.0799: in compiled function ->() on next line not recognized
Bram Moolenaar <Bram@vim.org>
parents:
30580
diff
changeset
|
86 var lines =<< trim END |
cbfbf0e17cd0
patch 9.0.0799: in compiled function ->() on next line not recognized
Bram Moolenaar <Bram@vim.org>
parents:
30580
diff
changeset
|
87 vim9script |
cbfbf0e17cd0
patch 9.0.0799: in compiled function ->() on next line not recognized
Bram Moolenaar <Bram@vim.org>
parents:
30580
diff
changeset
|
88 |
cbfbf0e17cd0
patch 9.0.0799: in compiled function ->() on next line not recognized
Bram Moolenaar <Bram@vim.org>
parents:
30580
diff
changeset
|
89 def Echo(what: any) |
cbfbf0e17cd0
patch 9.0.0799: in compiled function ->() on next line not recognized
Bram Moolenaar <Bram@vim.org>
parents:
30580
diff
changeset
|
90 assert_equal('hello world', what) |
cbfbf0e17cd0
patch 9.0.0799: in compiled function ->() on next line not recognized
Bram Moolenaar <Bram@vim.org>
parents:
30580
diff
changeset
|
91 enddef |
cbfbf0e17cd0
patch 9.0.0799: in compiled function ->() on next line not recognized
Bram Moolenaar <Bram@vim.org>
parents:
30580
diff
changeset
|
92 def That() |
cbfbf0e17cd0
patch 9.0.0799: in compiled function ->() on next line not recognized
Bram Moolenaar <Bram@vim.org>
parents:
30580
diff
changeset
|
93 printf("hello ") |
cbfbf0e17cd0
patch 9.0.0799: in compiled function ->() on next line not recognized
Bram Moolenaar <Bram@vim.org>
parents:
30580
diff
changeset
|
94 ->((x) => x .. "world")() |
cbfbf0e17cd0
patch 9.0.0799: in compiled function ->() on next line not recognized
Bram Moolenaar <Bram@vim.org>
parents:
30580
diff
changeset
|
95 ->Echo() |
cbfbf0e17cd0
patch 9.0.0799: in compiled function ->() on next line not recognized
Bram Moolenaar <Bram@vim.org>
parents:
30580
diff
changeset
|
96 enddef |
cbfbf0e17cd0
patch 9.0.0799: in compiled function ->() on next line not recognized
Bram Moolenaar <Bram@vim.org>
parents:
30580
diff
changeset
|
97 That() |
cbfbf0e17cd0
patch 9.0.0799: in compiled function ->() on next line not recognized
Bram Moolenaar <Bram@vim.org>
parents:
30580
diff
changeset
|
98 END |
cbfbf0e17cd0
patch 9.0.0799: in compiled function ->() on next line not recognized
Bram Moolenaar <Bram@vim.org>
parents:
30580
diff
changeset
|
99 v9.CheckScriptSuccess(lines) |
cbfbf0e17cd0
patch 9.0.0799: in compiled function ->() on next line not recognized
Bram Moolenaar <Bram@vim.org>
parents:
30580
diff
changeset
|
100 enddef |
cbfbf0e17cd0
patch 9.0.0799: in compiled function ->() on next line not recognized
Bram Moolenaar <Bram@vim.org>
parents:
30580
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 Test_lambda_with_partial() |
9527
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
103 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
|
104 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
|
105 endfunc |
9527
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
106 |
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
107 function Test_lambda_fails() |
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
108 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
|
109 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
|
110 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
|
111 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
|
112 |
6047c7ea7963
patch 8.2.3847: illegal memory access when using a lambda with an error
Bram Moolenaar <Bram@vim.org>
parents:
25118
diff
changeset
|
113 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
|
114 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
|
115 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
|
116 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
|
117 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
|
118 endfunc |
9597
3ca0fd9709b1
commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
119 |
3ca0fd9709b1
commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
120 func Test_not_lamda() |
3ca0fd9709b1
commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
121 let x = {'>' : 'foo'} |
3ca0fd9709b1
commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
122 call assert_equal('foo', x['>']) |
3ca0fd9709b1
commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
123 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
124 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
125 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
|
126 let v = 1 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
127 let l:F = {x -> x + v} |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
128 let v = 2 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
129 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
|
130 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
131 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
132 func Test_lambda_side_effect() |
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
133 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
|
134 let a:arr[1] = 5 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
135 return a:arr |
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! s:foo(arr) |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
139 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
|
140 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
141 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
142 let arr = [3,2,1] |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
143 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
|
144 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
145 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
146 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
|
147 func! s:foo(X) |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
148 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
|
149 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
150 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
151 func! s:bar() |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
152 let x = 123 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
153 return s:foo({-> x}) |
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 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
|
157 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
158 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
159 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
|
160 func! s:define_funcs() |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
161 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
|
162 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
|
163 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
|
164 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
165 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
166 let l:F = s:define_funcs() |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
167 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
168 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
|
169 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
|
170 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
|
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_closure_counter() |
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
174 func! s:foo() |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
175 let x = 0 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
176 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
|
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 let l:F = s:foo() |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
180 call test_garbagecollect_now() |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
181 call assert_equal(1, l:F()) |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
182 call assert_equal(2, l:F()) |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
183 call assert_equal(3, l:F()) |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
184 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
|
185 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
186 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
187 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
|
188 func! s:foo() |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
189 let x = 2 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
190 return {... -> a:000 + [x]} |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
191 endfunc |
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
192 func! s:bar() |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
193 return s:foo()(1) |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
194 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
195 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
196 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
|
197 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
198 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
199 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
|
200 func! s:foo(x) |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
201 let l:F1 = {-> {-> a:x}} |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
202 return {-> l:F1()} |
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 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
205 let l:F = s:foo(1) |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
206 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
|
207 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
208 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
209 func Test_lambda_delfunc() |
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
210 func! s:gen() |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
211 let pl = l: |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
212 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
|
213 let l:Bar = l:Foo |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
214 delfunction l:Foo |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
215 return l:Bar |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
216 endfunc |
9686
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 let l:F = s:gen() |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
219 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
|
220 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
221 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
222 func Test_lambda_scope() |
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
223 func! s:NewCounter() |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
224 let c = 0 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
225 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
|
226 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
227 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
228 func! s:NewCounter2() |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
229 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
|
230 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
231 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
232 let l:C = s:NewCounter() |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
233 let l:D = s:NewCounter2() |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
234 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
235 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
|
236 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
|
237 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
|
238 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
239 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
240 func Test_lambda_share_scope() |
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
241 func! s:New() |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
242 let c = 0 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
243 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
|
244 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
|
245 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
|
246 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
247 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
248 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
|
249 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
250 call assert_equal(1, l:Inc()) |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
251 call assert_equal(2, l:Inc()) |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
252 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
|
253 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
254 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
255 func Test_lambda_circular_reference() |
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
256 func! s:Foo() |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
257 let d = {} |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
258 let d.f = {-> d} |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
259 return d.f |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
260 endfunc |
9686
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 call s:Foo() |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
263 call test_garbagecollect_now() |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
264 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
|
265 call test_garbagecollect_now() |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
266 endfunc |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
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_lambda_combination() |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
269 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
|
270 call assert_equal(10, {y -> {x -> x(y)(10)}({y -> y})}({z -> z})) |
30325
58fb880f3607
patch 9.0.0498: various small issues
Bram Moolenaar <Bram@vim.org>
parents:
28745
diff
changeset
|
271 call assert_equal(5.0, {x -> {y -> x / y}}(10)(2.0)) |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
272 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
|
273 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
274 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
|
275 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
|
276 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
277 " Z combinator |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9597
diff
changeset
|
278 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
|
279 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
|
280 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
|
281 endfunc |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
282 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
283 func Test_closure_counter() |
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
284 func! s:foo() |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
285 let x = 0 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
286 func! s:bar() closure |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
287 let x += 1 |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
288 return x |
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 return function('s:bar') |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
291 endfunc |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
292 |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
293 let l:F = s:foo() |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
294 call test_garbagecollect_now() |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
295 call assert_equal(1, l:F()) |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
296 call assert_equal(2, l:F()) |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
297 call assert_equal(3, l:F()) |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
298 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
|
299 |
34a74f5f0fb4
patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents:
22087
diff
changeset
|
300 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
|
301 \ .. "\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
|
302 \ .. "\n2 return x" |
34a74f5f0fb4
patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents:
22087
diff
changeset
|
303 \ .. "\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
|
304 endfunc |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
305 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
306 func Test_closure_unlet() |
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
307 func! s:foo() |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
308 let x = 1 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
309 func! s:bar() closure |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
310 unlet x |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
311 endfunc |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
312 call s:bar() |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
313 return l: |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
314 endfunc |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
315 |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
316 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
|
317 call test_garbagecollect_now() |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
318 endfunc |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
319 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
320 func LambdaFoo() |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
321 let x = 0 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
322 func! LambdaBar() closure |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
323 let x += 1 |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
324 return x |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
325 endfunc |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
326 return function('LambdaBar') |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
14002
diff
changeset
|
327 endfunc |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
328 |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
329 func Test_closure_refcount() |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
330 let g:Count = LambdaFoo() |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
331 call test_garbagecollect_now() |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
332 call assert_equal(1, g:Count()) |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
333 let g:Count2 = LambdaFoo() |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
334 call test_garbagecollect_now() |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
335 call assert_equal(1, g:Count2()) |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
336 call assert_equal(2, g:Count()) |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
337 call assert_equal(3, g:Count2()) |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
338 |
9727
8436bb5134f5
commit https://github.com/vim/vim/commit/0588d4f9d2741f35a271400a37fddbdd72d84219
Christian Brabandt <cb@256bit.org>
parents:
9723
diff
changeset
|
339 delfunc LambdaFoo |
8436bb5134f5
commit https://github.com/vim/vim/commit/0588d4f9d2741f35a271400a37fddbdd72d84219
Christian Brabandt <cb@256bit.org>
parents:
9723
diff
changeset
|
340 delfunc LambdaBar |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9690
diff
changeset
|
341 endfunc |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
342 |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
343 func Test_named_function_closure() |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
344 func! Afoo() |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
345 let x = 14 |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
346 func! s:Abar() closure |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
347 return x |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
348 endfunc |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
349 call assert_equal(14, s:Abar()) |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
350 endfunc |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
351 call Afoo() |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
352 call assert_equal(14, s:Abar()) |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
353 call test_garbagecollect_now() |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
354 call assert_equal(14, s:Abar()) |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
355 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
|
356 |
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
|
357 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
|
358 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
|
359 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
|
360 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
|
361 endfunc |
18851
3cf9529b3a4a
patch 8.1.2412: crash when evaluating expression with error
Bram Moolenaar <Bram@vim.org>
parents:
17480
diff
changeset
|
362 |
3cf9529b3a4a
patch 8.1.2412: crash when evaluating expression with error
Bram Moolenaar <Bram@vim.org>
parents:
17480
diff
changeset
|
363 func Test_lambda_error() |
3cf9529b3a4a
patch 8.1.2412: crash when evaluating expression with error
Bram Moolenaar <Bram@vim.org>
parents:
17480
diff
changeset
|
364 " 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
|
365 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
|
366 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
|
367 |
19932
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
368 func Test_closure_error() |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
369 let l =<< trim END |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
370 func F1() closure |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
371 return 1 |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
372 endfunc |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
373 END |
30580
f08ed0738f7a
patch 9.0.0625: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
30325
diff
changeset
|
374 call writefile(l, 'Xscript', 'D') |
19932
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
375 let caught_932 = 0 |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
376 try |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
377 source Xscript |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
378 catch /E932:/ |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
379 let caught_932 = 1 |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
380 endtry |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
381 call assert_equal(1, caught_932) |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
382 endfunc |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
383 |
19724
b3e93a05c3ca
patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
19249
diff
changeset
|
384 " vim: shiftwidth=2 sts=2 expandtab |