annotate src/testdir/test_user_func.vim @ 30867:0913cd44fdfa v9.0.0768

patch 9.0.0768: too many delete() calls in tests Commit: https://github.com/vim/vim/commit/5b148ef2628251b2d79f78c65a614f8aca404329 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Oct 15 21:35:56 2022 +0100 patch 9.0.0768: too many delete() calls in tests Problem: Too many delete() calls in tests. Solution: Use deferred delete where possible.
author Bram Moolenaar <Bram@vim.org>
date Sat, 15 Oct 2022 22:45:02 +0200
parents 029c59bf78f1
children aa45593ec2ca
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()
30310
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 30166
diff changeset
132 call assert_equal(1.0, Log(10))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 30166
diff changeset
133 call assert_equal(log(10), Log(10, exp(1)))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 30166
diff changeset
134 call assert_fails("call Log(1,2,3)", 'E118:')
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
135
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
136 let res = Args(1)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
137 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
138 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
139 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
140
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
141 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
142 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
143 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
144 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
145
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
146 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
147 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
148 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
149 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
150
22087
ff21e2962490 patch 8.2.1593: tests do not check the error number properly
Bram Moolenaar <Bram@vim.org>
parents: 21124
diff changeset
151 call assert_fails("call MakeBadFunc()", 'E989:')
24373
da8b8a320bb3 patch 8.2.2727: function test fails
Bram Moolenaar <Bram@vim.org>
parents: 23108
diff changeset
152 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
153
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
154 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
155 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
156
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
157 call assert_equal("\n"
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
158 \ .. " 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
159 \ .. "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
160 \ .. " endfunction",
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 12662
diff changeset
161 \ 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
162
13efbfc53054 patch 8.2.2886: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24685
diff changeset
163 " 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
164 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
165 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
166 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
167 endfunc
13efbfc53054 patch 8.2.2886: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24685
diff changeset
168 echo F1()
13efbfc53054 patch 8.2.2886: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24685
diff changeset
169 END
13efbfc53054 patch 8.2.2886: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24685
diff changeset
170 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
171 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
172 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
173
9ffec4eb8d33 patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
174 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
175 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
176 endfunc
9ffec4eb8d33 patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
177
9ffec4eb8d33 patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
178 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
179 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
180 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
181
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
182 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
183 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
184 endfunc
19932
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
185
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
186 " 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
187 func Test_function_list()
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
188 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
189 endfunc
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
190
19950
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
191 " 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
192 func Test_sfile_in_function()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
193 func Xfunc()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
194 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
195 call assert_equal('2', expand('<slnum>'))
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
196 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
197 call Xfunc()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
198 delfunc Xfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
199 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
200
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
201 " Test trailing text after :endfunction {{{1
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
202 func Test_endfunction_trailing()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
203 call assert_false(exists('*Xtest'))
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
204
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
205 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
206 call assert_true(exists('*Xtest'))
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
207 call assert_equal('yes', done)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
208 delfunc Xtest
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
209 unlet done
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
210
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
211 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
212 call assert_true(exists('*Xtest'))
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
213 call assert_equal('yes', done)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
214 delfunc Xtest
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
215 unlet done
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
216
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
217 " trailing line break
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
218 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
219 call assert_true(exists('*Xtest'))
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
220 delfunc Xtest
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
221
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
222 set verbose=1
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
223 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
224 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
225 call assert_true(exists('*Xtest'))
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
226 delfunc Xtest
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
227
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
228 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
229 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
230 call assert_true(exists('*Xtest'))
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
231 delfunc Xtest
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
232 set verbose=0
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
233
21124
8b4b43b5b4c6 patch 8.2.1113: no test for verbose output of :call
Bram Moolenaar <Bram@vim.org>
parents: 19950
diff changeset
234 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
235 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
236 endfunc
8b4b43b5b4c6 patch 8.2.1113: no test for verbose output of :call
Bram Moolenaar <Bram@vim.org>
parents: 19950
diff changeset
237 set verbose=15
8b4b43b5b4c6 patch 8.2.1113: no test for verbose output of :call
Bram Moolenaar <Bram@vim.org>
parents: 19950
diff changeset
238 redir @a
8b4b43b5b4c6 patch 8.2.1113: no test for verbose output of :call
Bram Moolenaar <Bram@vim.org>
parents: 19950
diff changeset
239 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
240 redir END
8b4b43b5b4c6 patch 8.2.1113: no test for verbose output of :call
Bram Moolenaar <Bram@vim.org>
parents: 19950
diff changeset
241 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
242 delfunc Xtest
8b4b43b5b4c6 patch 8.2.1113: no test for verbose output of :call
Bram Moolenaar <Bram@vim.org>
parents: 19950
diff changeset
243 set verbose=0
8b4b43b5b4c6 patch 8.2.1113: no test for verbose output of :call
Bram Moolenaar <Bram@vim.org>
parents: 19950
diff changeset
244
19950
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
245 function Foo()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
246 echo 'hello'
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
247 endfunction | echo 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
248 delfunc Foo
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
249 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
250
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
251 func Test_delfunction_force()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
252 delfunc! Xtest
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
253 delfunc! Xtest
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
254 func Xtest()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
255 echo 'nothing'
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
256 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
257 delfunc! Xtest
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
258 delfunc! Xtest
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
259
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
260 " Try deleting the current function
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
261 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
262 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
263
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
264 func Test_function_defined_line()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
265 CheckNotGui
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
266
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
267 let lines =<< trim [CODE]
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
268 " F1
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
269 func F1()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
270 " F2
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
271 func F2()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
272 "
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
273 "
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 return
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
276 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
277 " F3
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
278 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
279 " F4
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
280 execute "func F4()\n
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
281 \\n
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
282 \\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 \return\n
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
285 \endfunc"
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
286 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
287 " F5
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
288 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
289 " F6
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
290 execute "func F6()\n
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
291 \\n
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
292 \\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 \return\n
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
295 \endfunc"
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
296 call F1()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
297 verbose func F1
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
298 verbose func F2
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
299 verbose func F3
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
300 verbose func F4
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
301 verbose func F5
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
302 verbose func F6
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
303 qall!
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
304 [CODE]
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
305
30867
0913cd44fdfa patch 9.0.0768: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
306 call writefile(lines, 'Xtest.vim', 'D')
19950
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
307 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
308 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
309
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
310 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
311 call assert_match(' line 2$', m)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
312
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
313 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
314 call assert_match(' line 4$', m)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
315
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
316 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
317 call assert_match(' line 11$', m)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
318
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
319 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
320 call assert_match(' line 13$', m)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
321
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
322 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
323 call assert_match(' line 21$', m)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
324
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
325 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
326 call assert_match(' line 23$', m)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
327 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
328
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
329 " 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
330 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
331 let x = g:
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
332 let caught_E862 = 0
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
333 try
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
334 func x.Xfunc()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
335 return 1
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
336 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
337 catch /E862:/
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
338 let caught_E862 = 1
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
339 endtry
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
340 call assert_equal(1, caught_E862)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
341 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
342
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
343 func Test_funccall_garbage_collect()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
344 func Func(x, ...)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
345 call add(a:x, a:000)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
346 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
347 call Func([], [])
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
348 " 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
349 call test_garbagecollect_now()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
350 call assert_true(v:true)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
351 delfunc Func
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
352 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
353
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
354 " Test for script-local function
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
355 func <SID>DoLast()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
356 call append(line('$'), "last line")
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
357 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
358
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
359 func s:DoNothing()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
360 call append(line('$'), "nothing 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 Test_script_local_func()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
364 set nocp nomore viminfo+=nviminfo
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
365 new
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
366 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
367
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
368 normal _x
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
369 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
370 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
371 close!
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
372
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
373 " 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
374 let lines =<< trim [CODE]
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
375 :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
376 :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
377 :call writefile(v:errors, 'Xresult')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
378 :qall
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
379
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
380 [CODE]
30867
0913cd44fdfa patch 9.0.0768: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
381 call writefile(lines, 'Xscript', 'D')
19950
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
382 if RunVim([], [], '-s Xscript')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
383 call assert_equal([], readfile('Xresult'))
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
384 endif
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
385 call delete('Xresult')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
386 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
387
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
388 " 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
389 func Test_func_def_error()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
390 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
391 call assert_fails('func Xfunc(', 'E125:')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
392 call assert_fails('func xfunc()', 'E128:')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
393
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
394 " 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
395 let caught_E127 = 0
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
396 try
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
397 func! Test_func_def_error()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
398 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
399 catch /E127:/
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
400 let caught_E127 = 1
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
401 endtry
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
402 call assert_equal(1, caught_E127)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
403
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
404 " 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
405 let d = {}
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
406 let lines =<< trim END
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
407 func d.F1()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
408 return 1
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
409 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
410 END
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
411 let l = join(lines, "\n") . "\n"
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
412 exe l
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
413 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
414 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
415
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
416 " Define an autoload function with an incorrect file name
30867
0913cd44fdfa patch 9.0.0768: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
417 call writefile(['func foo#Bar()', 'return 1', 'endfunc'], 'Xscript', 'D')
19950
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
418 call assert_fails('source Xscript', 'E746:')
22375
595ea7f099cd patch 8.2.1736: failure to compile a pattern not tested much
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
419
595ea7f099cd patch 8.2.1736: failure to compile a pattern not tested much
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
420 " 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
421 call assert_fails('function /\%(/', 'E53:')
19950
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
422 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
423
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
424 " Test for deleting a function
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
425 func Test_del_func()
26757
3a2b222107a6 patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 25745
diff changeset
426 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
427 let d = {'a' : 10}
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
428 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
429 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
430 return 1
04205b7d67d5 patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24373
diff changeset
431 endfunc
25745
b916d59f259f patch 8.2.3408: can delete a numbered function
Bram Moolenaar <Bram@vim.org>
parents: 24695
diff changeset
432
b916d59f259f patch 8.2.3408: can delete a numbered function
Bram Moolenaar <Bram@vim.org>
parents: 24695
diff changeset
433 " 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
434 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
435 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
436
24685
04205b7d67d5 patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24373
diff changeset
437 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
438 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
439 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
440
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
441 " 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
442 func Test_return_outside_func()
30867
0913cd44fdfa patch 9.0.0768: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
443 call writefile(['return 10'], 'Xscript', 'D')
19950
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
444 call assert_fails('source Xscript', 'E133:')
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 errors in calling a function
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
448 func Test_func_arg_error()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
449 " Too many arguments
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
450 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
451 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
452 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
453 \ 'E740:')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
454
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
455 " Missing dict argument
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
456 func Xfunc() dict
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
457 return 1
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
458 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
459 call assert_fails('call Xfunc()', 'E725:')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
460 delfunc Xfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
461 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
462
23108
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
463 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
464 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
465 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
466 return len(self)
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
467 endfunc
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
468
24685
04205b7d67d5 patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24373
diff changeset
469 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
470 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
471 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
472 \ .. "\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
473 \ .. "\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
474 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
475 endfunc
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
476
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
477 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
478 new
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
479 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
480 func FuncRange() range
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
481 echo a:firstline
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
482 echo a:lastline
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
483 endfunc
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
484 3
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
485 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
486 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
487 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
488 \ .. "\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
489 \ .. "\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
490 \ .. "\n endfunction",
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
491 \ execute('function FuncRange'))
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
492
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
493 bwipe!
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
494 endfunc
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
495
28382
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
496 " 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
497 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
498 new
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
499 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
500 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
501 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
502 endfunc
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
503 END
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
504 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
505 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
506 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
507 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
508 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
509 %d _
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
510 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
511 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
512 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
513 enddef
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
514 END
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 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
516 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
517 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
518 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
519 "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
520 "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
521 "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
522 "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
523 bw!
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
524 endfunc
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
525
30108
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
526 func AddDefer(arg1, ...)
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
527 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
528 if a:0 == 1
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
529 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
530 endif
30065
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
531 endfunc
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
532
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
533 func WithDeferTwo()
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
534 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
535 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
536 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
537 endfor
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
538 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
539 endfunc
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
540
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
541 func WithDeferOne()
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
542 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
543 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
544 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
545 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
546 call WithDeferTwo()
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
547 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
548 endfunc
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
549
30108
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
550 func WithPartialDefer()
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
551 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
552 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
553 defer Part("arg2")
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
554 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
555 endfunc
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
556
30065
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
557 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
558 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
559 call WithDeferOne()
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
560
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
561 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
562 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
563
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
564 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
565
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
566 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
567 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
568
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
569 let g:deferred = []
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
570 call WithPartialDefer()
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
571 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
572 unlet g:deferred
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
573
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
574 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
575 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
576 endfunc
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
577
30122
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
578 func DeferLevelTwo()
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
579 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
580 throw 'someerror'
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
581 endfunc
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
582
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
583 def DeferLevelOne()
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
584 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
585 call g:DeferLevelTwo()
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
586 enddef
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
587
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
588 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
589 let caught = 'no'
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
590 try
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
591 call DeferLevelOne()
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
592 catch /someerror/
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
593 let caught = 'yes'
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
594 endtry
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
595 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
596 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
597 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
598 endfunc
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
599
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
600 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
601 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
602 vim9script
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
603 func DeferLevelTwo()
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
604 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
605 qa!
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
606 endfunc
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
607
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
608 def DeferLevelOne()
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
609 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
610 call DeferLevelTwo()
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
611 enddef
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
612
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
613 DeferLevelOne()
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
614 END
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
615 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
616 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
617 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
618 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
619 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
620 endfunc
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
621
30140
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
622 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
623 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
624 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
625 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
626 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
627 qa!
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
628 endif
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
629 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
630 enddef
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
631
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
632 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
633 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
634 enddef
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
635 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
636 END
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
637 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
638 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
639 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
640 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
641 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
642 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
643 endfunc
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
644
30126
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
645 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
646 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
647 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
648 endfunc
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
649
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
650 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
651 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
652 return val == 'c'
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
653 enddef
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
654
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
655 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
656 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
657 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
658 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
659
30126
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
660 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
661 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
662 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
663 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
664 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
665
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
666 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
667 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
668 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
669 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
670
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
671 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
672 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
673 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
674 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
675
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
676 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
677 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
678 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
679 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
680
6575d0bf6061 patch 9.0.0405: arguments in a partial not used by a :def function
Bram Moolenaar <Bram@vim.org>
parents: 30126
diff changeset
681 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
682 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
683 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
684 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
685
6575d0bf6061 patch 9.0.0405: arguments in a partial not used by a :def function
Bram Moolenaar <Bram@vim.org>
parents: 30126
diff changeset
686 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
687 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
688 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
689 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
690 enddef
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
691
30166
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
692 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
693 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
694 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
695 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
696 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
697
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
698 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
699 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
700 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
701 enddef
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
702 defcompile
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
703 END
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
704 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
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 DeferFunc3()
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(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
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, 'E118:')
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 DeferFunc2()
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)
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, '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
719
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 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
721 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
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
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
724 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
725 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
726 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
727 enddef
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
728 defcompile
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
729 END
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
730 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
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 DeferUserFunc2()
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(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
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, 'E118:')
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 DeferUserFunc1()
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)
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, '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
745 endfunc
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
746
30065
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
747
19932
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
748 " vim: shiftwidth=2 sts=2 expandtab