annotate src/testdir/test_user_func.vim @ 30166:d1c04b4dc60d v9.0.0419

patch 9.0.0419: the :defer command does not check the function arguments Commit: https://github.com/vim/vim/commit/169003289fb4b2ad18fd7f5807e0d05efff0be85 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Sep 8 19:51:45 2022 +0100 patch 9.0.0419: the :defer command does not check the function arguments Problem: The :defer command does not check the function argument count and types. Solution: Check the function arguments when adding a deferred function.
author Bram Moolenaar <Bram@vim.org>
date Thu, 08 Sep 2022 21:00:04 +0200
parents 3b42bdfff7cb
children 029c59bf78f1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12662
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Test for user functions.
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2 " Also test an <expr> mapping calling a function.
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 " Also test that a builtin function cannot be replaced.
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 " Also test for regression when calling arbitrary expression.
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5
19950
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
6 source check.vim
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
7 source shared.vim
30166
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
8 import './vim9.vim' as v9
19950
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
9
12662
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 func Table(title, ...)
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 let ret = a:title
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 let idx = 1
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 while idx <= a:0
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 exe "let ret = ret . a:" . idx
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 let idx = idx + 1
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 endwhile
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 return ret
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 endfunc
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 func Compute(n1, n2, divname)
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 if a:n2 == 0
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 return "fail"
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 endif
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 exe "let g:" . a:divname . " = ". a:n1 / a:n2
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 return "ok"
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 endfunc
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 func Expr1()
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 silent! normal! v
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 return "111"
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 endfunc
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 func Expr2()
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 call search('XX', 'b')
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 return "222"
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 endfunc
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 func ListItem()
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 let g:counter += 1
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 return g:counter . '. '
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 endfunc
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 func ListReset()
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 let g:counter = 0
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 return ''
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 endfunc
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 func FuncWithRef(a)
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 unlet g:FuncRef
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 return a:a
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 endfunc
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 func Test_user_func()
17638
9ffec4eb8d33 patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
54 let g:FuncRef = function("FuncWithRef")
12662
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 let g:counter = 0
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56 inoremap <expr> ( ListItem()
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 inoremap <expr> [ ListReset()
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58 imap <expr> + Expr1()
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59 imap <expr> * Expr2()
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
60 let g:retval = "nop"
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 call assert_equal('xxx4asdf', Table("xxx", 4, "asdf"))
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63 call assert_equal('fail', Compute(45, 0, "retval"))
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64 call assert_equal('nop', g:retval)
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
65 call assert_equal('ok', Compute(45, 5, "retval"))
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66 call assert_equal(9, g:retval)
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67 call assert_equal(333, g:FuncRef(333))
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68
17638
9ffec4eb8d33 patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
69 let g:retval = "nop"
9ffec4eb8d33 patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
70 call assert_equal('xxx4asdf', "xxx"->Table(4, "asdf"))
9ffec4eb8d33 patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
71 call assert_equal('fail', 45->Compute(0, "retval"))
9ffec4eb8d33 patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
72 call assert_equal('nop', g:retval)
9ffec4eb8d33 patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
73 call assert_equal('ok', 45->Compute(5, "retval"))
9ffec4eb8d33 patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
74 call assert_equal(9, g:retval)
9ffec4eb8d33 patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
75 " call assert_equal(333, 333->g:FuncRef())
9ffec4eb8d33 patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
76
12662
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
77 enew
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
78
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79 normal oXX+-XX
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80 call assert_equal('XX111-XX', getline('.'))
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81 normal o---*---
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
82 call assert_equal('---222---', getline('.'))
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
83 normal o(one
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
84 call assert_equal('1. one', getline('.'))
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
85 normal o(two
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
86 call assert_equal('2. two', getline('.'))
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
87 normal o[(one again
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
88 call assert_equal('1. one again', getline('.'))
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
89
19950
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
90 " Try to overwrite a function in the global (g:) scope
12662
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
91 call assert_equal(3, max([1, 2, 3]))
22087
ff21e2962490 patch 8.2.1593: tests do not check the error number properly
Bram Moolenaar <Bram@vim.org>
parents: 21124
diff changeset
92 call assert_fails("call extend(g:, {'max': function('min')})", 'E704:')
12662
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
93 call assert_equal(3, max([1, 2, 3]))
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
94
19689
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19419
diff changeset
95 " Try to overwrite an user defined function with a function reference
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19419
diff changeset
96 call assert_fails("let Expr1 = function('min')", 'E705:')
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19419
diff changeset
97
12662
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
98 " Regression: the first line below used to throw ?E110: Missing ')'?
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
99 " Second is here just to prove that this line is correct when not skipping
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
100 " rhs of &&.
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
101 call assert_equal(0, (0 && (function('tr'))(1, 2, 3)))
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
102 call assert_equal(1, (1 && (function('tr'))(1, 2, 3)))
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
103
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
104 delfunc Table
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
105 delfunc Compute
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
106 delfunc Expr1
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
107 delfunc Expr2
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
108 delfunc ListItem
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
109 delfunc ListReset
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
110 unlet g:retval g:counter
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
111 enew!
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
112 endfunc
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
113
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
114 func Log(val, base = 10)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
115 return log(a:val) / log(a:base)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
116 endfunc
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
117
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
118 func Args(mandatory, optional = v:null, ...)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
119 return deepcopy(a:)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
120 endfunc
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
121
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
122 func Args2(a = 1, b = 2, c = 3)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
123 return deepcopy(a:)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
124 endfunc
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
125
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
126 func MakeBadFunc()
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
127 func s:fcn(a, b=1, c)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
128 endfunc
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
129 endfunc
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
130
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
131 func Test_default_arg()
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
132 if has('float')
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
133 call assert_equal(1.0, Log(10))
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
134 call assert_equal(log(10), Log(10, exp(1)))
22087
ff21e2962490 patch 8.2.1593: tests do not check the error number properly
Bram Moolenaar <Bram@vim.org>
parents: 21124
diff changeset
135 call assert_fails("call Log(1,2,3)", 'E118:')
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
136 endif
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
137
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
138 let res = Args(1)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
139 call assert_equal(res.mandatory, 1)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
140 call assert_equal(res.optional, v:null)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
141 call assert_equal(res['0'], 0)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
142
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
143 let res = Args(1,2)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
144 call assert_equal(res.mandatory, 1)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
145 call assert_equal(res.optional, 2)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
146 call assert_equal(res['0'], 0)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
147
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
148 let res = Args(1,2,3)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
149 call assert_equal(res.mandatory, 1)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
150 call assert_equal(res.optional, 2)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
151 call assert_equal(res['0'], 1)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
152
22087
ff21e2962490 patch 8.2.1593: tests do not check the error number properly
Bram Moolenaar <Bram@vim.org>
parents: 21124
diff changeset
153 call assert_fails("call MakeBadFunc()", 'E989:')
24373
da8b8a320bb3 patch 8.2.2727: function test fails
Bram Moolenaar <Bram@vim.org>
parents: 23108
diff changeset
154 call assert_fails("fu F(a=1 ,) | endf", 'E1068:')
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
155
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
156 let d = Args2(7, v:none, 9)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
157 call assert_equal([7, 2, 9], [d.a, d.b, d.c])
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
158
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
159 call assert_equal("\n"
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
160 \ .. " function Args2(a = 1, b = 2, c = 3)\n"
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
161 \ .. "1 return deepcopy(a:)\n"
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
162 \ .. " endfunction",
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
163 \ execute('func Args2'))
24695
13efbfc53054 patch 8.2.2886: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24685
diff changeset
164
13efbfc53054 patch 8.2.2886: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24685
diff changeset
165 " Error in default argument expression
13efbfc53054 patch 8.2.2886: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24685
diff changeset
166 let l =<< trim END
13efbfc53054 patch 8.2.2886: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24685
diff changeset
167 func F1(x = y)
13efbfc53054 patch 8.2.2886: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24685
diff changeset
168 return a:x * 2
13efbfc53054 patch 8.2.2886: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24685
diff changeset
169 endfunc
13efbfc53054 patch 8.2.2886: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24685
diff changeset
170 echo F1()
13efbfc53054 patch 8.2.2886: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24685
diff changeset
171 END
13efbfc53054 patch 8.2.2886: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24685
diff changeset
172 let @a = l->join("\n")
13efbfc53054 patch 8.2.2886: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24685
diff changeset
173 call assert_fails("exe @a", 'E121:')
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
174 endfunc
17638
9ffec4eb8d33 patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
175
9ffec4eb8d33 patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
176 func s:addFoo(lead)
9ffec4eb8d33 patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
177 return a:lead .. 'foo'
9ffec4eb8d33 patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
178 endfunc
9ffec4eb8d33 patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
179
9ffec4eb8d33 patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
180 func Test_user_method()
9ffec4eb8d33 patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
181 eval 'bar'->s:addFoo()->assert_equal('barfoo')
9ffec4eb8d33 patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
182 endfunc
19419
c6c9d91d8290 patch 8.2.0267: no check for a following cmd when calling a function fails
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
183
c6c9d91d8290 patch 8.2.0267: no check for a following cmd when calling a function fails
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
184 func Test_failed_call_in_try()
c6c9d91d8290 patch 8.2.0267: no check for a following cmd when calling a function fails
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
185 try | call UnknownFunc() | catch | endtry
c6c9d91d8290 patch 8.2.0267: no check for a following cmd when calling a function fails
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
186 endfunc
19932
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
187
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
188 " Test for listing user-defined functions
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
189 func Test_function_list()
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
190 call assert_fails("function Xabc", 'E123:')
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
191 endfunc
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
192
19950
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
193 " Test for <sfile>, <slnum> in a function
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
194 func Test_sfile_in_function()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
195 func Xfunc()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
196 call assert_match('..Test_sfile_in_function\[5]..Xfunc', expand('<sfile>'))
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
197 call assert_equal('2', expand('<slnum>'))
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
198 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
199 call Xfunc()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
200 delfunc Xfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
201 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
202
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
203 " Test trailing text after :endfunction {{{1
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
204 func Test_endfunction_trailing()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
205 call assert_false(exists('*Xtest'))
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
206
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
207 exe "func Xtest()\necho 'hello'\nendfunc\nlet done = 'yes'"
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
208 call assert_true(exists('*Xtest'))
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
209 call assert_equal('yes', done)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
210 delfunc Xtest
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
211 unlet done
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
212
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
213 exe "func Xtest()\necho 'hello'\nendfunc|let done = 'yes'"
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
214 call assert_true(exists('*Xtest'))
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
215 call assert_equal('yes', done)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
216 delfunc Xtest
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
217 unlet done
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
218
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
219 " trailing line break
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
220 exe "func Xtest()\necho 'hello'\nendfunc\n"
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
221 call assert_true(exists('*Xtest'))
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
222 delfunc Xtest
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
223
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
224 set verbose=1
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
225 exe "func Xtest()\necho 'hello'\nendfunc \" garbage"
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
226 call assert_notmatch('W22:', split(execute('1messages'), "\n")[0])
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
227 call assert_true(exists('*Xtest'))
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
228 delfunc Xtest
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
229
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
230 exe "func Xtest()\necho 'hello'\nendfunc garbage"
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
231 call assert_match('W22:', split(execute('1messages'), "\n")[0])
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
232 call assert_true(exists('*Xtest'))
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
233 delfunc Xtest
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
234 set verbose=0
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
235
21124
8b4b43b5b4c6 patch 8.2.1113: no test for verbose output of :call
Bram Moolenaar <Bram@vim.org>
parents: 19950
diff changeset
236 func Xtest(a1, a2)
8b4b43b5b4c6 patch 8.2.1113: no test for verbose output of :call
Bram Moolenaar <Bram@vim.org>
parents: 19950
diff changeset
237 echo a:a1 .. a:a2
8b4b43b5b4c6 patch 8.2.1113: no test for verbose output of :call
Bram Moolenaar <Bram@vim.org>
parents: 19950
diff changeset
238 endfunc
8b4b43b5b4c6 patch 8.2.1113: no test for verbose output of :call
Bram Moolenaar <Bram@vim.org>
parents: 19950
diff changeset
239 set verbose=15
8b4b43b5b4c6 patch 8.2.1113: no test for verbose output of :call
Bram Moolenaar <Bram@vim.org>
parents: 19950
diff changeset
240 redir @a
8b4b43b5b4c6 patch 8.2.1113: no test for verbose output of :call
Bram Moolenaar <Bram@vim.org>
parents: 19950
diff changeset
241 call Xtest(123, repeat('x', 100))
8b4b43b5b4c6 patch 8.2.1113: no test for verbose output of :call
Bram Moolenaar <Bram@vim.org>
parents: 19950
diff changeset
242 redir END
8b4b43b5b4c6 patch 8.2.1113: no test for verbose output of :call
Bram Moolenaar <Bram@vim.org>
parents: 19950
diff changeset
243 call assert_match('calling Xtest(123, ''xxxxxxx.*x\.\.\.x.*xxxx'')', getreg('a'))
8b4b43b5b4c6 patch 8.2.1113: no test for verbose output of :call
Bram Moolenaar <Bram@vim.org>
parents: 19950
diff changeset
244 delfunc Xtest
8b4b43b5b4c6 patch 8.2.1113: no test for verbose output of :call
Bram Moolenaar <Bram@vim.org>
parents: 19950
diff changeset
245 set verbose=0
8b4b43b5b4c6 patch 8.2.1113: no test for verbose output of :call
Bram Moolenaar <Bram@vim.org>
parents: 19950
diff changeset
246
19950
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
247 function Foo()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
248 echo 'hello'
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
249 endfunction | echo 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
250 delfunc Foo
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
251 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
252
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
253 func Test_delfunction_force()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
254 delfunc! Xtest
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
255 delfunc! Xtest
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
256 func Xtest()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
257 echo 'nothing'
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
258 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
259 delfunc! Xtest
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
260 delfunc! Xtest
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
261
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
262 " Try deleting the current function
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
263 call assert_fails('delfunc Test_delfunction_force', 'E131:')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
264 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
265
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
266 func Test_function_defined_line()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
267 CheckNotGui
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
268
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
269 let lines =<< trim [CODE]
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
270 " F1
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
271 func F1()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
272 " F2
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
273 func F2()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
274 "
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
275 "
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
276 "
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
277 return
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
278 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
279 " F3
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
280 execute "func F3()\n\n\n\nreturn\nendfunc"
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
281 " F4
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
282 execute "func F4()\n
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
283 \\n
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
284 \\n
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
285 \\n
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
286 \return\n
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
287 \endfunc"
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
288 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
289 " F5
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
290 execute "func F5()\n\n\n\nreturn\nendfunc"
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
291 " F6
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
292 execute "func F6()\n
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
293 \\n
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
294 \\n
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
295 \\n
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
296 \return\n
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
297 \endfunc"
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
298 call F1()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
299 verbose func F1
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
300 verbose func F2
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
301 verbose func F3
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
302 verbose func F4
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
303 verbose func F5
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
304 verbose func F6
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
305 qall!
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
306 [CODE]
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
307
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
308 call writefile(lines, 'Xtest.vim')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
309 let res = system(GetVimCommandClean() .. ' -es -X -S Xtest.vim')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
310 call assert_equal(0, v:shell_error)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
311
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
312 let m = matchstr(res, 'function F1()[^[:print:]]*[[:print:]]*')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
313 call assert_match(' line 2$', m)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
314
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
315 let m = matchstr(res, 'function F2()[^[:print:]]*[[:print:]]*')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
316 call assert_match(' line 4$', m)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
317
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
318 let m = matchstr(res, 'function F3()[^[:print:]]*[[:print:]]*')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
319 call assert_match(' line 11$', m)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
320
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
321 let m = matchstr(res, 'function F4()[^[:print:]]*[[:print:]]*')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
322 call assert_match(' line 13$', m)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
323
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
324 let m = matchstr(res, 'function F5()[^[:print:]]*[[:print:]]*')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
325 call assert_match(' line 21$', m)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
326
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
327 let m = matchstr(res, 'function F6()[^[:print:]]*[[:print:]]*')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
328 call assert_match(' line 23$', m)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
329
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
330 call delete('Xtest.vim')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
331 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
332
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
333 " Test for defining a function reference in the global scope
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
334 func Test_add_funcref_to_global_scope()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
335 let x = g:
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
336 let caught_E862 = 0
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
337 try
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
338 func x.Xfunc()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
339 return 1
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
340 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
341 catch /E862:/
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
342 let caught_E862 = 1
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
343 endtry
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
344 call assert_equal(1, caught_E862)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
345 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
346
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
347 func Test_funccall_garbage_collect()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
348 func Func(x, ...)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
349 call add(a:x, a:000)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
350 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
351 call Func([], [])
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
352 " Must not crash cause by invalid freeing
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
353 call test_garbagecollect_now()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
354 call assert_true(v:true)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
355 delfunc Func
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
356 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
357
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
358 " Test for script-local function
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
359 func <SID>DoLast()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
360 call append(line('$'), "last line")
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
361 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
362
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
363 func s:DoNothing()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
364 call append(line('$'), "nothing line")
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
365 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
366
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
367 func Test_script_local_func()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
368 set nocp nomore viminfo+=nviminfo
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
369 new
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
370 nnoremap <buffer> _x :call <SID>DoNothing()<bar>call <SID>DoLast()<bar>delfunc <SID>DoNothing<bar>delfunc <SID>DoLast<cr>
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
371
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
372 normal _x
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
373 call assert_equal('nothing line', getline(2))
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
374 call assert_equal('last line', getline(3))
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
375 close!
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
376
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
377 " Try to call a script local function in global scope
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
378 let lines =<< trim [CODE]
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
379 :call assert_fails('call s:Xfunc()', 'E81:')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
380 :call assert_fails('let x = call("<SID>Xfunc", [])', 'E120:')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
381 :call writefile(v:errors, 'Xresult')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
382 :qall
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
383
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
384 [CODE]
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
385 call writefile(lines, 'Xscript')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
386 if RunVim([], [], '-s Xscript')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
387 call assert_equal([], readfile('Xresult'))
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
388 endif
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
389 call delete('Xresult')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
390 call delete('Xscript')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
391 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
392
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
393 " Test for errors in defining new functions
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
394 func Test_func_def_error()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
395 call assert_fails('func Xfunc abc ()', 'E124:')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
396 call assert_fails('func Xfunc(', 'E125:')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
397 call assert_fails('func xfunc()', 'E128:')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
398
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
399 " Try to redefine a function that is in use
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
400 let caught_E127 = 0
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
401 try
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
402 func! Test_func_def_error()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
403 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
404 catch /E127:/
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
405 let caught_E127 = 1
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
406 endtry
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
407 call assert_equal(1, caught_E127)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
408
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
409 " Try to define a function in a dict twice
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
410 let d = {}
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
411 let lines =<< trim END
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
412 func d.F1()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
413 return 1
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
414 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
415 END
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
416 let l = join(lines, "\n") . "\n"
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
417 exe l
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
418 call assert_fails('exe l', 'E717:')
24685
04205b7d67d5 patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24373
diff changeset
419 call assert_fails('call feedkeys(":func d.F1()\<CR>", "xt")', 'E717:')
19950
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
420
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
421 " Define an autoload function with an incorrect file name
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
422 call writefile(['func foo#Bar()', 'return 1', 'endfunc'], 'Xscript')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
423 call assert_fails('source Xscript', 'E746:')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
424 call delete('Xscript')
22375
595ea7f099cd patch 8.2.1736: failure to compile a pattern not tested much
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
425
595ea7f099cd patch 8.2.1736: failure to compile a pattern not tested much
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
426 " Try to list functions using an invalid search pattern
595ea7f099cd patch 8.2.1736: failure to compile a pattern not tested much
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
427 call assert_fails('function /\%(/', 'E53:')
19950
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
428 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
429
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
430 " Test for deleting a function
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
431 func Test_del_func()
26757
3a2b222107a6 patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 25745
diff changeset
432 call assert_fails('delfunction Xabc', 'E117:')
19950
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
433 let d = {'a' : 10}
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
434 call assert_fails('delfunc d.a', 'E718:')
24685
04205b7d67d5 patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24373
diff changeset
435 func d.fn()
04205b7d67d5 patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24373
diff changeset
436 return 1
04205b7d67d5 patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24373
diff changeset
437 endfunc
25745
b916d59f259f patch 8.2.3408: can delete a numbered function
Bram Moolenaar <Bram@vim.org>
parents: 24695
diff changeset
438
b916d59f259f patch 8.2.3408: can delete a numbered function
Bram Moolenaar <Bram@vim.org>
parents: 24695
diff changeset
439 " cannot delete the dict function by number
b916d59f259f patch 8.2.3408: can delete a numbered function
Bram Moolenaar <Bram@vim.org>
parents: 24695
diff changeset
440 let nr = substitute(execute('echo d'), '.*function(''\(\d\+\)'').*', '\1', '')
b916d59f259f patch 8.2.3408: can delete a numbered function
Bram Moolenaar <Bram@vim.org>
parents: 24695
diff changeset
441 call assert_fails('delfunction g:' .. nr, 'E475: Invalid argument: g:')
b916d59f259f patch 8.2.3408: can delete a numbered function
Bram Moolenaar <Bram@vim.org>
parents: 24695
diff changeset
442
24685
04205b7d67d5 patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24373
diff changeset
443 delfunc d.fn
04205b7d67d5 patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24373
diff changeset
444 call assert_equal({'a' : 10}, d)
19950
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
445 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
446
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
447 " Test for calling return outside of a function
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
448 func Test_return_outside_func()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
449 call writefile(['return 10'], 'Xscript')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
450 call assert_fails('source Xscript', 'E133:')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
451 call delete('Xscript')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
452 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
453
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
454 " Test for errors in calling a function
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
455 func Test_func_arg_error()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
456 " Too many arguments
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
457 call assert_fails("call call('min', range(1,20))", 'E118:')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
458 call assert_fails("call call('min', range(1,21))", 'E699:')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
459 call assert_fails('echo min(0,1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,0,1)',
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
460 \ 'E740:')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
461
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
462 " Missing dict argument
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
463 func Xfunc() dict
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
464 return 1
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
465 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
466 call assert_fails('call Xfunc()', 'E725:')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
467 delfunc Xfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
468 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
469
23108
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
470 func Test_func_dict()
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
471 let mydict = {'a': 'b'}
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
472 function mydict.somefunc() dict
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
473 return len(self)
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
474 endfunc
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
475
24685
04205b7d67d5 patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24373
diff changeset
476 call assert_equal("{'a': 'b', 'somefunc': function('3')}", string(mydict))
23108
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
477 call assert_equal(2, mydict.somefunc())
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
478 call assert_match("^\n function \\d\\\+() dict"
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
479 \ .. "\n1 return len(self)"
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
480 \ .. "\n endfunction$", execute('func mydict.somefunc'))
24685
04205b7d67d5 patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24373
diff changeset
481 call assert_fails('call mydict.nonexist()', 'E716:')
23108
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
482 endfunc
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
483
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
484 func Test_func_range()
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
485 new
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
486 call setline(1, range(1, 8))
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
487 func FuncRange() range
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
488 echo a:firstline
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
489 echo a:lastline
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
490 endfunc
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
491 3
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
492 call assert_equal("\n3\n3", execute('call FuncRange()'))
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
493 call assert_equal("\n4\n6", execute('4,6 call FuncRange()'))
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
494 call assert_equal("\n function FuncRange() range"
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
495 \ .. "\n1 echo a:firstline"
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
496 \ .. "\n2 echo a:lastline"
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
497 \ .. "\n endfunction",
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
498 \ execute('function FuncRange'))
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
499
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
500 bwipe!
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
501 endfunc
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
502
28382
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
503 " Test for memory allocation failure when defining a new function
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
504 func Test_funcdef_alloc_failure()
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
505 new
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
506 let lines =<< trim END
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
507 func Xtestfunc()
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
508 return 321
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
509 endfunc
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
510 END
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
511 call setline(1, lines)
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
512 call test_alloc_fail(GetAllocId('get_func'), 0, 0)
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
513 call assert_fails('source', 'E342:')
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
514 call assert_false(exists('*Xtestfunc'))
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
515 call assert_fails('delfunc Xtestfunc', 'E117:')
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
516 %d _
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
517 let lines =<< trim END
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
518 def g:Xvim9func(): number
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
519 return 456
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
520 enddef
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
521 END
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
522 call setline(1, lines)
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
523 call test_alloc_fail(GetAllocId('get_func'), 0, 0)
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
524 call assert_fails('source', 'E342:')
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
525 call assert_false(exists('*Xvim9func'))
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
526 "call test_alloc_fail(GetAllocId('get_func'), 0, 0)
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
527 "call assert_fails('source', 'E342:')
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
528 "call assert_false(exists('*Xtestfunc'))
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
529 "call assert_fails('delfunc Xtestfunc', 'E117:')
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
530 bw!
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
531 endfunc
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
532
30108
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
533 func AddDefer(arg1, ...)
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
534 call extend(g:deferred, [a:arg1])
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
535 if a:0 == 1
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
536 call extend(g:deferred, [a:1])
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
537 endif
30065
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
538 endfunc
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
539
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
540 func WithDeferTwo()
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
541 call extend(g:deferred, ['in Two'])
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
542 for nr in range(3)
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
543 defer AddDefer('Two' .. nr)
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
544 endfor
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
545 call extend(g:deferred, ['end Two'])
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
546 endfunc
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
547
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
548 func WithDeferOne()
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
549 call extend(g:deferred, ['in One'])
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
550 call writefile(['text'], 'Xfuncdefer')
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
551 defer delete('Xfuncdefer')
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
552 defer AddDefer('One')
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
553 call WithDeferTwo()
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
554 call extend(g:deferred, ['end One'])
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
555 endfunc
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
556
30108
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
557 func WithPartialDefer()
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
558 call extend(g:deferred, ['in Partial'])
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
559 let Part = funcref('AddDefer', ['arg1'])
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
560 defer Part("arg2")
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
561 call extend(g:deferred, ['end Partial'])
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
562 endfunc
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
563
30065
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
564 func Test_defer()
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
565 let g:deferred = []
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
566 call WithDeferOne()
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
567
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
568 call assert_equal(['in One', 'in Two', 'end Two', 'Two2', 'Two1', 'Two0', 'end One', 'One'], g:deferred)
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
569 unlet g:deferred
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
570
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
571 call assert_equal('', glob('Xfuncdefer'))
30108
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
572
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
573 call assert_fails('defer delete("Xfuncdefer")->Another()', 'E488:')
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
574 call assert_fails('defer delete("Xfuncdefer").member', 'E488:')
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
575
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
576 let g:deferred = []
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
577 call WithPartialDefer()
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
578 call assert_equal(['in Partial', 'end Partial', 'arg1', 'arg2'], g:deferred)
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
579 unlet g:deferred
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
580
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
581 let Part = funcref('AddDefer', ['arg1'], {})
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
582 call assert_fails('defer Part("arg2")', 'E1300:')
30065
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
583 endfunc
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
584
30122
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
585 func DeferLevelTwo()
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
586 call writefile(['text'], 'XDeleteTwo', 'D')
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
587 throw 'someerror'
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
588 endfunc
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
589
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
590 def DeferLevelOne()
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
591 call writefile(['text'], 'XDeleteOne', 'D')
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
592 call g:DeferLevelTwo()
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
593 enddef
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
594
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
595 func Test_defer_throw()
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
596 let caught = 'no'
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
597 try
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
598 call DeferLevelOne()
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
599 catch /someerror/
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
600 let caught = 'yes'
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
601 endtry
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
602 call assert_equal('yes', caught)
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
603 call assert_false(filereadable('XDeleteOne'))
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
604 call assert_false(filereadable('XDeleteTwo'))
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
605 endfunc
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
606
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
607 func Test_defer_quitall()
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
608 let lines =<< trim END
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
609 vim9script
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
610 func DeferLevelTwo()
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
611 call writefile(['text'], 'XQuitallTwo', 'D')
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
612 qa!
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
613 endfunc
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
614
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
615 def DeferLevelOne()
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
616 call writefile(['text'], 'XQuitallOne', 'D')
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
617 call DeferLevelTwo()
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
618 enddef
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
619
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
620 DeferLevelOne()
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
621 END
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
622 call writefile(lines, 'XdeferQuitall', 'D')
30166
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
623 let res = system(GetVimCommand() .. ' -X -S XdeferQuitall')
30122
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
624 call assert_equal(0, v:shell_error)
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
625 call assert_false(filereadable('XQuitallOne'))
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
626 call assert_false(filereadable('XQuitallTwo'))
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
627 endfunc
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
628
30140
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
629 func Test_defer_quitall_in_expr_func()
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
630 let lines =<< trim END
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
631 def DefIndex(idx: number, val: string): bool
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
632 call writefile([idx .. ': ' .. val], 'Xentry' .. idx, 'D')
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
633 if val == 'b'
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
634 qa!
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
635 endif
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
636 return val == 'c'
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
637 enddef
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
638
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
639 def Test_defer_in_funcref()
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
640 assert_equal(2, indexof(['a', 'b', 'c'], funcref('g:DefIndex')))
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
641 enddef
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
642 call Test_defer_in_funcref()
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
643 END
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
644 call writefile(lines, 'XdeferQuitallExpr', 'D')
30166
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
645 let res = system(GetVimCommand() .. ' -X -S XdeferQuitallExpr')
30140
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
646 call assert_equal(0, v:shell_error)
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
647 call assert_false(filereadable('Xentry0'))
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
648 call assert_false(filereadable('Xentry1'))
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
649 call assert_false(filereadable('Xentry2'))
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
650 endfunc
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
651
30126
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
652 func FuncIndex(idx, val)
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
653 call writefile([a:idx .. ': ' .. a:val], 'Xentry' .. a:idx, 'D')
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
654 return a:val == 'c'
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
655 endfunc
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
656
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
657 def DefIndex(idx: number, val: string): bool
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
658 call writefile([idx .. ': ' .. val], 'Xentry' .. idx, 'D')
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
659 return val == 'c'
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
660 enddef
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
661
30138
6575d0bf6061 patch 9.0.0405: arguments in a partial not used by a :def function
Bram Moolenaar <Bram@vim.org>
parents: 30126
diff changeset
662 def DefIndexXtra(xtra: string, idx: number, val: string): bool
6575d0bf6061 patch 9.0.0405: arguments in a partial not used by a :def function
Bram Moolenaar <Bram@vim.org>
parents: 30126
diff changeset
663 call writefile([idx .. ': ' .. val], 'Xentry' .. idx, 'D')
6575d0bf6061 patch 9.0.0405: arguments in a partial not used by a :def function
Bram Moolenaar <Bram@vim.org>
parents: 30126
diff changeset
664 return val == 'c'
6575d0bf6061 patch 9.0.0405: arguments in a partial not used by a :def function
Bram Moolenaar <Bram@vim.org>
parents: 30126
diff changeset
665 enddef
6575d0bf6061 patch 9.0.0405: arguments in a partial not used by a :def function
Bram Moolenaar <Bram@vim.org>
parents: 30126
diff changeset
666
30126
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
667 def Test_defer_in_funcref()
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
668 assert_equal(2, indexof(['a', 'b', 'c'], function('g:FuncIndex')))
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
669 assert_false(filereadable('Xentry0'))
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
670 assert_false(filereadable('Xentry1'))
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
671 assert_false(filereadable('Xentry2'))
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
672
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
673 assert_equal(2, indexof(['a', 'b', 'c'], g:DefIndex))
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
674 assert_false(filereadable('Xentry0'))
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
675 assert_false(filereadable('Xentry1'))
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
676 assert_false(filereadable('Xentry2'))
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
677
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
678 assert_equal(2, indexof(['a', 'b', 'c'], function('g:DefIndex')))
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
679 assert_false(filereadable('Xentry0'))
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
680 assert_false(filereadable('Xentry1'))
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
681 assert_false(filereadable('Xentry2'))
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
682
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
683 assert_equal(2, indexof(['a', 'b', 'c'], funcref(g:DefIndex)))
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
684 assert_false(filereadable('Xentry0'))
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
685 assert_false(filereadable('Xentry1'))
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
686 assert_false(filereadable('Xentry2'))
30138
6575d0bf6061 patch 9.0.0405: arguments in a partial not used by a :def function
Bram Moolenaar <Bram@vim.org>
parents: 30126
diff changeset
687
6575d0bf6061 patch 9.0.0405: arguments in a partial not used by a :def function
Bram Moolenaar <Bram@vim.org>
parents: 30126
diff changeset
688 assert_equal(2, indexof(['a', 'b', 'c'], function(g:DefIndexXtra, ['xtra'])))
6575d0bf6061 patch 9.0.0405: arguments in a partial not used by a :def function
Bram Moolenaar <Bram@vim.org>
parents: 30126
diff changeset
689 assert_false(filereadable('Xentry0'))
6575d0bf6061 patch 9.0.0405: arguments in a partial not used by a :def function
Bram Moolenaar <Bram@vim.org>
parents: 30126
diff changeset
690 assert_false(filereadable('Xentry1'))
6575d0bf6061 patch 9.0.0405: arguments in a partial not used by a :def function
Bram Moolenaar <Bram@vim.org>
parents: 30126
diff changeset
691 assert_false(filereadable('Xentry2'))
6575d0bf6061 patch 9.0.0405: arguments in a partial not used by a :def function
Bram Moolenaar <Bram@vim.org>
parents: 30126
diff changeset
692
6575d0bf6061 patch 9.0.0405: arguments in a partial not used by a :def function
Bram Moolenaar <Bram@vim.org>
parents: 30126
diff changeset
693 assert_equal(2, indexof(['a', 'b', 'c'], funcref(g:DefIndexXtra, ['xtra'])))
6575d0bf6061 patch 9.0.0405: arguments in a partial not used by a :def function
Bram Moolenaar <Bram@vim.org>
parents: 30126
diff changeset
694 assert_false(filereadable('Xentry0'))
6575d0bf6061 patch 9.0.0405: arguments in a partial not used by a :def function
Bram Moolenaar <Bram@vim.org>
parents: 30126
diff changeset
695 assert_false(filereadable('Xentry1'))
6575d0bf6061 patch 9.0.0405: arguments in a partial not used by a :def function
Bram Moolenaar <Bram@vim.org>
parents: 30126
diff changeset
696 assert_false(filereadable('Xentry2'))
30126
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
697 enddef
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
698
30166
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
699 func Test_defer_wrong_arguments()
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
700 call assert_fails('defer delete()', 'E119:')
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
701 call assert_fails('defer FuncIndex(1)', 'E119:')
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
702 call assert_fails('defer delete(1, 2, 3)', 'E118:')
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
703 call assert_fails('defer FuncIndex(1, 2, 3)', 'E118:')
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
704
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
705 let lines =<< trim END
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
706 def DeferFunc0()
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
707 defer delete()
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
708 enddef
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
709 defcompile
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
710 END
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
711 call v9.CheckScriptFailure(lines, 'E119:')
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
712 let lines =<< trim END
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
713 def DeferFunc3()
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
714 defer delete(1, 2, 3)
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
715 enddef
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
716 defcompile
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
717 END
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
718 call v9.CheckScriptFailure(lines, 'E118:')
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
719 let lines =<< trim END
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
720 def DeferFunc2()
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
721 defer delete(1, 2)
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
722 enddef
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
723 defcompile
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
724 END
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
725 call v9.CheckScriptFailure(lines, 'E1013: Argument 1: type mismatch, expected string but got number')
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
726
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
727 def g:FuncOneArg(arg: string)
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
728 echo arg
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
729 enddef
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
730
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
731 let lines =<< trim END
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
732 def DeferUserFunc0()
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
733 defer g:FuncOneArg()
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
734 enddef
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
735 defcompile
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
736 END
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
737 call v9.CheckScriptFailure(lines, 'E119:')
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
738 let lines =<< trim END
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
739 def DeferUserFunc2()
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
740 defer g:FuncOneArg(1, 2)
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
741 enddef
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
742 defcompile
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
743 END
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
744 call v9.CheckScriptFailure(lines, 'E118:')
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
745 let lines =<< trim END
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
746 def DeferUserFunc1()
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
747 defer g:FuncOneArg(1)
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
748 enddef
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
749 defcompile
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
750 END
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
751 call v9.CheckScriptFailure(lines, 'E1013: Argument 1: type mismatch, expected string but got number')
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
752 endfunc
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
753
30065
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
754
19932
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
755 " vim: shiftwidth=2 sts=2 expandtab