Mercurial > vim
annotate src/testdir/test_nested_function.vim @ 21060:89aba7895bb2 v8.2.1081
patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Commit: https://github.com/vim/vim/commit/a1f9f8666ed3a462eb8a518e78418c57dc41bbd4
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jun 28 22:41:26 2020 +0200
patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Problem: Lua: cannot use table.insert() and table.remove().
Solution: Add the list functions. (Prabir Shrestha, closes https://github.com/vim/vim/issues/6353)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 28 Jun 2020 22:45:04 +0200 |
parents | bd5bec6291cc |
children | 08940efa6b4e |
rev | line source |
---|---|
10068
c577c6a2e88b
commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1 "Tests for nested functions |
c577c6a2e88b
commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2 " |
10381
14a82c6433be
commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
3 func NestedFunc() |
14a82c6433be
commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
4 func! Func1() |
10068
c577c6a2e88b
commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5 let g:text .= 'Func1 ' |
10381
14a82c6433be
commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
6 endfunc |
10068
c577c6a2e88b
commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
7 call Func1() |
10381
14a82c6433be
commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
8 func! s:func2() |
10068
c577c6a2e88b
commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
9 let g:text .= 's:func2 ' |
10381
14a82c6433be
commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
10 endfunc |
10068
c577c6a2e88b
commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
11 call s:func2() |
10381
14a82c6433be
commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
12 func! s:_func3() |
10068
c577c6a2e88b
commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
13 let g:text .= 's:_func3 ' |
10381
14a82c6433be
commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
14 endfunc |
10068
c577c6a2e88b
commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
15 call s:_func3() |
c577c6a2e88b
commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
16 let fn = 'Func4' |
10381
14a82c6433be
commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
17 func! {fn}() |
10068
c577c6a2e88b
commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
18 let g:text .= 'Func4 ' |
10381
14a82c6433be
commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
19 endfunc |
10068
c577c6a2e88b
commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
20 call {fn}() |
c577c6a2e88b
commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
21 let fn = 'func5' |
10381
14a82c6433be
commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
22 func! s:{fn}() |
10068
c577c6a2e88b
commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
23 let g:text .= 's:func5' |
10381
14a82c6433be
commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
24 endfunc |
10068
c577c6a2e88b
commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
25 call s:{fn}() |
10381
14a82c6433be
commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
26 endfunc |
10068
c577c6a2e88b
commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
27 |
10381
14a82c6433be
commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
28 func Test_nested_functions() |
10068
c577c6a2e88b
commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
29 let g:text = '' |
c577c6a2e88b
commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
30 call NestedFunc() |
c577c6a2e88b
commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
31 call assert_equal('Func1 s:func2 s:_func3 Func4 s:func5', g:text) |
c577c6a2e88b
commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
32 endfunction |
10381
14a82c6433be
commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
33 |
14a82c6433be
commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
34 func Test_nested_argument() |
14a82c6433be
commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
35 func g:X() |
14a82c6433be
commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
36 let g:Y = function('sort') |
14a82c6433be
commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
37 endfunc |
14a82c6433be
commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
38 let g:Y = function('sort') |
14a82c6433be
commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
39 echo g:Y([], g:X()) |
14a82c6433be
commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
40 delfunc g:X |
14a82c6433be
commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
41 unlet g:Y |
14a82c6433be
commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
42 endfunc |
10488
89200fa1d174
commit https://github.com/vim/vim/commit/777b30f827bcbe10a40640b1bf0361cb93a16be1
Christian Brabandt <cb@256bit.org>
parents:
10381
diff
changeset
|
43 |
89200fa1d174
commit https://github.com/vim/vim/commit/777b30f827bcbe10a40640b1bf0361cb93a16be1
Christian Brabandt <cb@256bit.org>
parents:
10381
diff
changeset
|
44 func Recurse(count) |
89200fa1d174
commit https://github.com/vim/vim/commit/777b30f827bcbe10a40640b1bf0361cb93a16be1
Christian Brabandt <cb@256bit.org>
parents:
10381
diff
changeset
|
45 if a:count > 0 |
89200fa1d174
commit https://github.com/vim/vim/commit/777b30f827bcbe10a40640b1bf0361cb93a16be1
Christian Brabandt <cb@256bit.org>
parents:
10381
diff
changeset
|
46 call Recurse(a:count - 1) |
89200fa1d174
commit https://github.com/vim/vim/commit/777b30f827bcbe10a40640b1bf0361cb93a16be1
Christian Brabandt <cb@256bit.org>
parents:
10381
diff
changeset
|
47 endif |
89200fa1d174
commit https://github.com/vim/vim/commit/777b30f827bcbe10a40640b1bf0361cb93a16be1
Christian Brabandt <cb@256bit.org>
parents:
10381
diff
changeset
|
48 endfunc |
89200fa1d174
commit https://github.com/vim/vim/commit/777b30f827bcbe10a40640b1bf0361cb93a16be1
Christian Brabandt <cb@256bit.org>
parents:
10381
diff
changeset
|
49 |
89200fa1d174
commit https://github.com/vim/vim/commit/777b30f827bcbe10a40640b1bf0361cb93a16be1
Christian Brabandt <cb@256bit.org>
parents:
10381
diff
changeset
|
50 func Test_max_nesting() |
10496
bd5bec6291cc
commit https://github.com/vim/vim/commit/269aec7e615b7710139a69a4c715dfe534aa3a1a
Christian Brabandt <cb@256bit.org>
parents:
10488
diff
changeset
|
51 " TODO: why does this fail on Windows? Runs out of stack perhaps? |
bd5bec6291cc
commit https://github.com/vim/vim/commit/269aec7e615b7710139a69a4c715dfe534aa3a1a
Christian Brabandt <cb@256bit.org>
parents:
10488
diff
changeset
|
52 if has('win32') |
bd5bec6291cc
commit https://github.com/vim/vim/commit/269aec7e615b7710139a69a4c715dfe534aa3a1a
Christian Brabandt <cb@256bit.org>
parents:
10488
diff
changeset
|
53 return |
bd5bec6291cc
commit https://github.com/vim/vim/commit/269aec7e615b7710139a69a4c715dfe534aa3a1a
Christian Brabandt <cb@256bit.org>
parents:
10488
diff
changeset
|
54 endif |
10488
89200fa1d174
commit https://github.com/vim/vim/commit/777b30f827bcbe10a40640b1bf0361cb93a16be1
Christian Brabandt <cb@256bit.org>
parents:
10381
diff
changeset
|
55 let call_depth_here = 2 |
89200fa1d174
commit https://github.com/vim/vim/commit/777b30f827bcbe10a40640b1bf0361cb93a16be1
Christian Brabandt <cb@256bit.org>
parents:
10381
diff
changeset
|
56 let ex_depth_here = 5 |
89200fa1d174
commit https://github.com/vim/vim/commit/777b30f827bcbe10a40640b1bf0361cb93a16be1
Christian Brabandt <cb@256bit.org>
parents:
10381
diff
changeset
|
57 set mfd& |
89200fa1d174
commit https://github.com/vim/vim/commit/777b30f827bcbe10a40640b1bf0361cb93a16be1
Christian Brabandt <cb@256bit.org>
parents:
10381
diff
changeset
|
58 |
89200fa1d174
commit https://github.com/vim/vim/commit/777b30f827bcbe10a40640b1bf0361cb93a16be1
Christian Brabandt <cb@256bit.org>
parents:
10381
diff
changeset
|
59 call Recurse(99 - call_depth_here) |
89200fa1d174
commit https://github.com/vim/vim/commit/777b30f827bcbe10a40640b1bf0361cb93a16be1
Christian Brabandt <cb@256bit.org>
parents:
10381
diff
changeset
|
60 call assert_fails('call Recurse(' . (100 - call_depth_here) . ')', 'E132:') |
89200fa1d174
commit https://github.com/vim/vim/commit/777b30f827bcbe10a40640b1bf0361cb93a16be1
Christian Brabandt <cb@256bit.org>
parents:
10381
diff
changeset
|
61 |
89200fa1d174
commit https://github.com/vim/vim/commit/777b30f827bcbe10a40640b1bf0361cb93a16be1
Christian Brabandt <cb@256bit.org>
parents:
10381
diff
changeset
|
62 set mfd=210 |
89200fa1d174
commit https://github.com/vim/vim/commit/777b30f827bcbe10a40640b1bf0361cb93a16be1
Christian Brabandt <cb@256bit.org>
parents:
10381
diff
changeset
|
63 call Recurse(209 - ex_depth_here) |
89200fa1d174
commit https://github.com/vim/vim/commit/777b30f827bcbe10a40640b1bf0361cb93a16be1
Christian Brabandt <cb@256bit.org>
parents:
10381
diff
changeset
|
64 call assert_fails('call Recurse(' . (210 - ex_depth_here) . ')', 'E169:') |
89200fa1d174
commit https://github.com/vim/vim/commit/777b30f827bcbe10a40640b1bf0361cb93a16be1
Christian Brabandt <cb@256bit.org>
parents:
10381
diff
changeset
|
65 |
89200fa1d174
commit https://github.com/vim/vim/commit/777b30f827bcbe10a40640b1bf0361cb93a16be1
Christian Brabandt <cb@256bit.org>
parents:
10381
diff
changeset
|
66 set mfd& |
89200fa1d174
commit https://github.com/vim/vim/commit/777b30f827bcbe10a40640b1bf0361cb93a16be1
Christian Brabandt <cb@256bit.org>
parents:
10381
diff
changeset
|
67 endfunc |