annotate src/testdir/test_user_func.vim @ 35171:76c328389c46 default tip

Added tag v9.1.0411 for changeset ed3a90cecb19f1d38b0a9bbb9bf6ed60bace72f4
author Christian Brabandt <cb@256bit.org>
date Sun, 12 May 2024 09:30:05 +0200
parents 7de5ae6a0518
children
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
31497
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
182 func Test_method_with_linebreaks()
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
183 let lines =<< trim END
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
184 vim9script
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
185
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
186 export def Scan(ll: list<number>): func(func(number))
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
187 return (Emit: func(number)) => {
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
188 for v in ll
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
189 Emit(v)
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
190 endfor
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
191 }
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
192 enddef
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
193
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
194 export def Build(Cont: func(func(number))): list<number>
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
195 var result: list<number> = []
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
196 Cont((v) => {
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
197 add(result, v)
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
198 })
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
199 return result
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
200 enddef
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
201
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
202 export def Noop(Cont: func(func(number))): func(func(number))
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
203 return (Emit: func(number)) => {
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
204 Cont(Emit)
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
205 }
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
206 enddef
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
207 END
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
208 call writefile(lines, 'Xlib.vim', 'D')
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
209
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
210 let lines =<< trim END
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
211 vim9script
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
212
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
213 import "./Xlib.vim" as lib
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
214
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
215 const x = [1, 2, 3]
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
216
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
217 var result = lib.Scan(x)->lib.Noop()->lib.Build()
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
218 assert_equal([1, 2, 3], result)
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
219
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
220 result = lib.Scan(x)->lib.Noop()
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
221 ->lib.Build()
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
222 assert_equal([1, 2, 3], result)
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
223
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
224 result = lib.Scan(x)
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
225 ->lib.Noop()->lib.Build()
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
226 assert_equal([1, 2, 3], result)
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
227
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
228 result = lib.Scan(x)
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
229 ->lib.Noop()
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
230 ->lib.Build()
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
231 assert_equal([1, 2, 3], result)
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
232 END
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
233 call v9.CheckScriptSuccess(lines)
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
234 endfunc
aa45593ec2ca patch 9.0.1081: using "->" with split lines does not always work
Bram Moolenaar <Bram@vim.org>
parents: 30867
diff changeset
235
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
236 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
237 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
238 endfunc
19932
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
239
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
240 " 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
241 func Test_function_list()
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
242 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
243 endfunc
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
244
19950
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
245 " 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
246 func Test_sfile_in_function()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
247 func Xfunc()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
248 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
249 call assert_equal('2', expand('<slnum>'))
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
250 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
251 call Xfunc()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
252 delfunc Xfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
253 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
254
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
255 " Test trailing text after :endfunction {{{1
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
256 func Test_endfunction_trailing()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
257 call assert_false(exists('*Xtest'))
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
258
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
259 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
260 call assert_true(exists('*Xtest'))
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
261 call assert_equal('yes', done)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
262 delfunc Xtest
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
263 unlet done
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
264
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
265 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
266 call assert_true(exists('*Xtest'))
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
267 call assert_equal('yes', done)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
268 delfunc Xtest
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
269 unlet done
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
270
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
271 " trailing line break
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
272 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
273 call assert_true(exists('*Xtest'))
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
274 delfunc Xtest
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
275
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
276 set verbose=1
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
277 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
278 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
279 call assert_true(exists('*Xtest'))
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
280 delfunc Xtest
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
281
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
282 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
283 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
284 call assert_true(exists('*Xtest'))
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
285 delfunc Xtest
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
286 set verbose=0
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
287
21124
8b4b43b5b4c6 patch 8.2.1113: no test for verbose output of :call
Bram Moolenaar <Bram@vim.org>
parents: 19950
diff changeset
288 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
289 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
290 endfunc
8b4b43b5b4c6 patch 8.2.1113: no test for verbose output of :call
Bram Moolenaar <Bram@vim.org>
parents: 19950
diff changeset
291 set verbose=15
8b4b43b5b4c6 patch 8.2.1113: no test for verbose output of :call
Bram Moolenaar <Bram@vim.org>
parents: 19950
diff changeset
292 redir @a
8b4b43b5b4c6 patch 8.2.1113: no test for verbose output of :call
Bram Moolenaar <Bram@vim.org>
parents: 19950
diff changeset
293 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
294 redir END
8b4b43b5b4c6 patch 8.2.1113: no test for verbose output of :call
Bram Moolenaar <Bram@vim.org>
parents: 19950
diff changeset
295 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
296 delfunc Xtest
8b4b43b5b4c6 patch 8.2.1113: no test for verbose output of :call
Bram Moolenaar <Bram@vim.org>
parents: 19950
diff changeset
297 set verbose=0
8b4b43b5b4c6 patch 8.2.1113: no test for verbose output of :call
Bram Moolenaar <Bram@vim.org>
parents: 19950
diff changeset
298
19950
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
299 function Foo()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
300 echo 'hello'
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
301 endfunction | echo 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
302 delfunc Foo
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
303 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
304
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
305 func Test_delfunction_force()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
306 delfunc! Xtest
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
307 delfunc! Xtest
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
308 func Xtest()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
309 echo 'nothing'
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
310 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
311 delfunc! Xtest
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
312 delfunc! Xtest
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
313
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
314 " Try deleting the current function
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
315 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
316 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
317
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
318 func Test_function_defined_line()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
319 CheckNotGui
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
320
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
321 let lines =<< trim [CODE]
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
322 " F1
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
323 func F1()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
324 " F2
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
325 func F2()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
326 "
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
327 "
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 return
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
330 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
331 " F3
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
332 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
333 " F4
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
334 execute "func F4()\n
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
335 \\n
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
336 \\n
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
337 \\n
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
338 \return\n
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
339 \endfunc"
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
340 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
341 " F5
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
342 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
343 " F6
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
344 execute "func F6()\n
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
345 \\n
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
346 \\n
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
347 \\n
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
348 \return\n
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
349 \endfunc"
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
350 call F1()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
351 verbose func F1
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
352 verbose func F2
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
353 verbose func F3
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
354 verbose func F4
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
355 verbose func F5
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
356 verbose func F6
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
357 qall!
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
358 [CODE]
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
359
30867
0913cd44fdfa patch 9.0.0768: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
360 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
361 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
362 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
363
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
364 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
365 call assert_match(' line 2$', m)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
366
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
367 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
368 call assert_match(' line 4$', m)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
369
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
370 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
371 call assert_match(' line 11$', m)
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 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
374 call assert_match(' line 13$', m)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
375
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
376 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
377 call assert_match(' line 21$', m)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
378
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
379 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
380 call assert_match(' line 23$', m)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
381 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
382
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
383 " 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
384 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
385 let x = g:
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
386 let caught_E862 = 0
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
387 try
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
388 func x.Xfunc()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
389 return 1
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
390 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
391 catch /E862:/
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
392 let caught_E862 = 1
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
393 endtry
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
394 call assert_equal(1, caught_E862)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
395 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
396
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
397 func Test_funccall_garbage_collect()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
398 func Func(x, ...)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
399 call add(a:x, a:000)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
400 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
401 call Func([], [])
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
402 " 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
403 call test_garbagecollect_now()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
404 call assert_true(v:true)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
405 delfunc Func
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
406 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
407
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
408 " Test for script-local function
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
409 func <SID>DoLast()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
410 call append(line('$'), "last line")
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
411 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
412
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
413 func s:DoNothing()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
414 call append(line('$'), "nothing line")
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
415 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
416
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
417 func Test_script_local_func()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
418 set nocp nomore viminfo+=nviminfo
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
419 new
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
420 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
421
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
422 normal _x
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
423 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
424 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
425 close!
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
426
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
427 " 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
428 let lines =<< trim [CODE]
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
429 :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
430 :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
431 :call writefile(v:errors, 'Xresult')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
432 :qall
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
433
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
434 [CODE]
30867
0913cd44fdfa patch 9.0.0768: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
435 call writefile(lines, 'Xscript', 'D')
19950
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
436 if RunVim([], [], '-s Xscript')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
437 call assert_equal([], readfile('Xresult'))
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
438 endif
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
439 call delete('Xresult')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
440 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
441
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
442 " 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
443 func Test_func_def_error()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
444 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
445 call assert_fails('func Xfunc(', 'E125:')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
446 call assert_fails('func xfunc()', 'E128:')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
447
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
448 " 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
449 let caught_E127 = 0
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
450 try
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
451 func! Test_func_def_error()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
452 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
453 catch /E127:/
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
454 let caught_E127 = 1
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
455 endtry
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
456 call assert_equal(1, caught_E127)
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
457
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
458 " 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
459 let d = {}
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
460 let lines =<< trim END
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
461 func d.F1()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
462 return 1
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
463 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
464 END
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
465 let l = join(lines, "\n") . "\n"
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
466 exe l
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
467 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
468 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
469
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
470 " 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
471 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
472 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
473
595ea7f099cd patch 8.2.1736: failure to compile a pattern not tested much
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
474 " 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
475 call assert_fails('function /\%(/', 'E53:')
19950
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
476 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
477
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
478 " Test for deleting a function
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
479 func Test_del_func()
26757
3a2b222107a6 patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 25745
diff changeset
480 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
481 let d = {'a' : 10}
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
482 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
483 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
484 return 1
04205b7d67d5 patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24373
diff changeset
485 endfunc
25745
b916d59f259f patch 8.2.3408: can delete a numbered function
Bram Moolenaar <Bram@vim.org>
parents: 24695
diff changeset
486
b916d59f259f patch 8.2.3408: can delete a numbered function
Bram Moolenaar <Bram@vim.org>
parents: 24695
diff changeset
487 " 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
488 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
489 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
490
24685
04205b7d67d5 patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24373
diff changeset
491 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
492 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
493 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
494
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
495 " 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
496 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
497 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
498 call assert_fails('source Xscript', 'E133:')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
499 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
500
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
501 " 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
502 func Test_func_arg_error()
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
503 " Too many arguments
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
504 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
505 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
506 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
507 \ 'E740:')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
508
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
509 " Missing dict argument
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
510 func Xfunc() dict
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
511 return 1
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
512 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
513 call assert_fails('call Xfunc()', 'E725:')
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
514 delfunc Xfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
515 endfunc
9cbe3a4f1492 patch 8.2.0531: various errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
516
23108
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
517 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
518 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
519 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
520 return len(self)
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
521 endfunc
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
522
24685
04205b7d67d5 patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24373
diff changeset
523 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
524 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
525 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
526 \ .. "\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
527 \ .. "\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
528 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
529 endfunc
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
530
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
531 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
532 new
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
533 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
534 func FuncRange() range
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
535 echo a:firstline
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
536 echo a:lastline
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
537 endfunc
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
538 3
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
539 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
540 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
541 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
542 \ .. "\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
543 \ .. "\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
544 \ .. "\n endfunction",
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
545 \ execute('function FuncRange'))
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
546
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
547 bwipe!
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
548 endfunc
34a74f5f0fb4 patch 8.2.2100: insufficient testing for function range and dict
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
549
28382
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
550 " 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
551 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
552 new
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
553 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
554 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
555 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
556 endfunc
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
557 END
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
558 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
559 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
560 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
561 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
562 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
563 %d _
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
564 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
565 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
566 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
567 enddef
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
568 END
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
569 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
570 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
571 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
572 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
573 "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
574 "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
575 "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
576 "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
577 bw!
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
578 endfunc
f24d4826e6bf patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents: 26757
diff changeset
579
30108
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
580 func AddDefer(arg1, ...)
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
581 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
582 if a:0 == 1
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
583 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
584 endif
30065
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
585 endfunc
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
586
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
587 func WithDeferTwo()
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
588 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
589 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
590 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
591 endfor
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
592 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
593 endfunc
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
594
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
595 func WithDeferOne()
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
596 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
597 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
598 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
599 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
600 call WithDeferTwo()
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
601 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
602 endfunc
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
603
30108
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
604 func WithPartialDefer()
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
605 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
606 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
607 defer Part("arg2")
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
608 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
609 endfunc
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
610
30065
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
611 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
612 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
613 call WithDeferOne()
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
614
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
615 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
616 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
617
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
618 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
619
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
620 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
621 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
622
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
623 let g:deferred = []
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
624 call WithPartialDefer()
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
625 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
626 unlet g:deferred
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
627
0352577f1ba5 patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents: 30065
diff changeset
628 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
629 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
630 endfunc
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
631
30122
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
632 func DeferLevelTwo()
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
633 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
634 throw 'someerror'
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
635 endfunc
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
636
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
637 def DeferLevelOne()
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
638 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
639 call g:DeferLevelTwo()
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
640 enddef
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
641
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
642 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
643 let caught = 'no'
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
644 try
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
645 call DeferLevelOne()
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
646 catch /someerror/
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
647 let caught = 'yes'
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
648 endtry
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
649 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
650 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
651 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
652 endfunc
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
653
32274
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
654 func Test_defer_quitall_func()
30122
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
655 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
656 func DeferLevelTwo()
32274
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
657 call writefile(['text'], 'XQuitallFuncTwo', 'D')
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
658 call writefile(['quit'], 'XQuitallFuncThree', 'a')
30122
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
659 qa!
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
660 endfunc
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
661
32274
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
662 func DeferLevelOne()
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
663 call writefile(['text'], 'XQuitalFunclOne', 'D')
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
664 defer DeferLevelTwo()
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
665 endfunc
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
666
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
667 call DeferLevelOne()
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
668 END
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
669 call writefile(lines, 'XdeferQuitallFunc', 'D')
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
670 call system(GetVimCommand() .. ' -X -S XdeferQuitallFunc')
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
671 call assert_equal(0, v:shell_error)
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
672 call assert_false(filereadable('XQuitallFuncOne'))
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
673 call assert_false(filereadable('XQuitallFuncTwo'))
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
674 call assert_equal(['quit'], readfile('XQuitallFuncThree'))
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
675
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
676 call delete('XQuitallFuncThree')
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
677 endfunc
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
678
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
679 func Test_defer_quitall_def()
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
680 let lines =<< trim END
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
681 vim9script
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
682 def DeferLevelTwo()
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
683 call writefile(['text'], 'XQuitallDefTwo', 'D')
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
684 call writefile(['quit'], 'XQuitallDefThree', 'a')
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
685 qa!
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
686 enddef
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
687
30122
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
688 def DeferLevelOne()
32274
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
689 call writefile(['text'], 'XQuitallDefOne', 'D')
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
690 defer DeferLevelTwo()
30122
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
691 enddef
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
692
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
693 DeferLevelOne()
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
694 END
32274
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
695 call writefile(lines, 'XdeferQuitallDef', 'D')
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
696 call system(GetVimCommand() .. ' -X -S XdeferQuitallDef')
30122
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
697 call assert_equal(0, v:shell_error)
32274
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
698 call assert_false(filereadable('XQuitallDefOne'))
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
699 call assert_false(filereadable('XQuitallDefTwo'))
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
700 call assert_equal(['quit'], readfile('XQuitallDefThree'))
32262
854aeaac48b7 patch 9.0.1462: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 31497
diff changeset
701
32274
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
702 call delete('XQuitallDefThree')
30122
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
703 endfunc
458162398682 patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents: 30108
diff changeset
704
32276
774c94489feb patch 9.0.1469: deferred functions not called from autocommands
Bram Moolenaar <Bram@vim.org>
parents: 32274
diff changeset
705 func Test_defer_quitall_autocmd()
774c94489feb patch 9.0.1469: deferred functions not called from autocommands
Bram Moolenaar <Bram@vim.org>
parents: 32274
diff changeset
706 let lines =<< trim END
32278
f59ad8692734 patch 9.0.1470: deferred functions invoked in unexpected order
Bram Moolenaar <Bram@vim.org>
parents: 32276
diff changeset
707 func DeferLevelFive()
f59ad8692734 patch 9.0.1470: deferred functions invoked in unexpected order
Bram Moolenaar <Bram@vim.org>
parents: 32276
diff changeset
708 defer writefile(['5'], 'XQuitallAutocmd', 'a')
f59ad8692734 patch 9.0.1470: deferred functions invoked in unexpected order
Bram Moolenaar <Bram@vim.org>
parents: 32276
diff changeset
709 qa!
32276
774c94489feb patch 9.0.1469: deferred functions not called from autocommands
Bram Moolenaar <Bram@vim.org>
parents: 32274
diff changeset
710 endfunc
774c94489feb patch 9.0.1469: deferred functions not called from autocommands
Bram Moolenaar <Bram@vim.org>
parents: 32274
diff changeset
711
32278
f59ad8692734 patch 9.0.1470: deferred functions invoked in unexpected order
Bram Moolenaar <Bram@vim.org>
parents: 32276
diff changeset
712 autocmd User DeferAutocmdFive call DeferLevelFive()
f59ad8692734 patch 9.0.1470: deferred functions invoked in unexpected order
Bram Moolenaar <Bram@vim.org>
parents: 32276
diff changeset
713
f59ad8692734 patch 9.0.1470: deferred functions invoked in unexpected order
Bram Moolenaar <Bram@vim.org>
parents: 32276
diff changeset
714 def DeferLevelFour()
f59ad8692734 patch 9.0.1470: deferred functions invoked in unexpected order
Bram Moolenaar <Bram@vim.org>
parents: 32276
diff changeset
715 defer writefile(['4'], 'XQuitallAutocmd', 'a')
f59ad8692734 patch 9.0.1470: deferred functions invoked in unexpected order
Bram Moolenaar <Bram@vim.org>
parents: 32276
diff changeset
716 doautocmd User DeferAutocmdFive
f59ad8692734 patch 9.0.1470: deferred functions invoked in unexpected order
Bram Moolenaar <Bram@vim.org>
parents: 32276
diff changeset
717 enddef
f59ad8692734 patch 9.0.1470: deferred functions invoked in unexpected order
Bram Moolenaar <Bram@vim.org>
parents: 32276
diff changeset
718
f59ad8692734 patch 9.0.1470: deferred functions invoked in unexpected order
Bram Moolenaar <Bram@vim.org>
parents: 32276
diff changeset
719 func DeferLevelThree()
f59ad8692734 patch 9.0.1470: deferred functions invoked in unexpected order
Bram Moolenaar <Bram@vim.org>
parents: 32276
diff changeset
720 defer writefile(['3'], 'XQuitallAutocmd', 'a')
f59ad8692734 patch 9.0.1470: deferred functions invoked in unexpected order
Bram Moolenaar <Bram@vim.org>
parents: 32276
diff changeset
721 call DeferLevelFour()
f59ad8692734 patch 9.0.1470: deferred functions invoked in unexpected order
Bram Moolenaar <Bram@vim.org>
parents: 32276
diff changeset
722 endfunc
32276
774c94489feb patch 9.0.1469: deferred functions not called from autocommands
Bram Moolenaar <Bram@vim.org>
parents: 32274
diff changeset
723
32278
f59ad8692734 patch 9.0.1470: deferred functions invoked in unexpected order
Bram Moolenaar <Bram@vim.org>
parents: 32276
diff changeset
724 autocmd User DeferAutocmdThree ++nested call DeferLevelThree()
f59ad8692734 patch 9.0.1470: deferred functions invoked in unexpected order
Bram Moolenaar <Bram@vim.org>
parents: 32276
diff changeset
725
f59ad8692734 patch 9.0.1470: deferred functions invoked in unexpected order
Bram Moolenaar <Bram@vim.org>
parents: 32276
diff changeset
726 def DeferLevelTwo()
f59ad8692734 patch 9.0.1470: deferred functions invoked in unexpected order
Bram Moolenaar <Bram@vim.org>
parents: 32276
diff changeset
727 defer writefile(['2'], 'XQuitallAutocmd', 'a')
f59ad8692734 patch 9.0.1470: deferred functions invoked in unexpected order
Bram Moolenaar <Bram@vim.org>
parents: 32276
diff changeset
728 doautocmd User DeferAutocmdThree
32276
774c94489feb patch 9.0.1469: deferred functions not called from autocommands
Bram Moolenaar <Bram@vim.org>
parents: 32274
diff changeset
729 enddef
774c94489feb patch 9.0.1469: deferred functions not called from autocommands
Bram Moolenaar <Bram@vim.org>
parents: 32274
diff changeset
730
32278
f59ad8692734 patch 9.0.1470: deferred functions invoked in unexpected order
Bram Moolenaar <Bram@vim.org>
parents: 32276
diff changeset
731 func DeferLevelOne()
f59ad8692734 patch 9.0.1470: deferred functions invoked in unexpected order
Bram Moolenaar <Bram@vim.org>
parents: 32276
diff changeset
732 defer writefile(['1'], 'XQuitallAutocmd', 'a')
f59ad8692734 patch 9.0.1470: deferred functions invoked in unexpected order
Bram Moolenaar <Bram@vim.org>
parents: 32276
diff changeset
733 call DeferLevelTwo()
f59ad8692734 patch 9.0.1470: deferred functions invoked in unexpected order
Bram Moolenaar <Bram@vim.org>
parents: 32276
diff changeset
734 endfunc
f59ad8692734 patch 9.0.1470: deferred functions invoked in unexpected order
Bram Moolenaar <Bram@vim.org>
parents: 32276
diff changeset
735
32276
774c94489feb patch 9.0.1469: deferred functions not called from autocommands
Bram Moolenaar <Bram@vim.org>
parents: 32274
diff changeset
736 autocmd User DeferAutocmdOne ++nested call DeferLevelOne()
774c94489feb patch 9.0.1469: deferred functions not called from autocommands
Bram Moolenaar <Bram@vim.org>
parents: 32274
diff changeset
737
774c94489feb patch 9.0.1469: deferred functions not called from autocommands
Bram Moolenaar <Bram@vim.org>
parents: 32274
diff changeset
738 doautocmd User DeferAutocmdOne
774c94489feb patch 9.0.1469: deferred functions not called from autocommands
Bram Moolenaar <Bram@vim.org>
parents: 32274
diff changeset
739 END
774c94489feb patch 9.0.1469: deferred functions not called from autocommands
Bram Moolenaar <Bram@vim.org>
parents: 32274
diff changeset
740 call writefile(lines, 'XdeferQuitallAutocmd', 'D')
32278
f59ad8692734 patch 9.0.1470: deferred functions invoked in unexpected order
Bram Moolenaar <Bram@vim.org>
parents: 32276
diff changeset
741 call system(GetVimCommand() .. ' -X -S XdeferQuitallAutocmd')
32276
774c94489feb patch 9.0.1469: deferred functions not called from autocommands
Bram Moolenaar <Bram@vim.org>
parents: 32274
diff changeset
742 call assert_equal(0, v:shell_error)
32278
f59ad8692734 patch 9.0.1470: deferred functions invoked in unexpected order
Bram Moolenaar <Bram@vim.org>
parents: 32276
diff changeset
743 call assert_equal(['5', '4', '3', '2', '1'], readfile('XQuitallAutocmd'))
f59ad8692734 patch 9.0.1470: deferred functions invoked in unexpected order
Bram Moolenaar <Bram@vim.org>
parents: 32276
diff changeset
744
f59ad8692734 patch 9.0.1470: deferred functions invoked in unexpected order
Bram Moolenaar <Bram@vim.org>
parents: 32276
diff changeset
745 call delete('XQuitallAutocmd')
32276
774c94489feb patch 9.0.1469: deferred functions not called from autocommands
Bram Moolenaar <Bram@vim.org>
parents: 32274
diff changeset
746 endfunc
774c94489feb patch 9.0.1469: deferred functions not called from autocommands
Bram Moolenaar <Bram@vim.org>
parents: 32274
diff changeset
747
30140
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
748 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
749 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
750 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
751 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
752 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
753 qa!
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
754 endif
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
755 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
756 enddef
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
757
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
758 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
759 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
760 enddef
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
761 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
762 END
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
763 call writefile(lines, 'XdeferQuitallExpr', 'D')
32274
83caf07aedd6 patch 9.0.1468: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents: 32262
diff changeset
764 call 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
765 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
766 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
767 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
768 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
769 endfunc
3b42bdfff7cb patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents: 30138
diff changeset
770
30126
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
771 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
772 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
773 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
774 endfunc
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
775
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
776 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
777 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
778 return val == 'c'
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
779 enddef
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
780
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
781 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
782 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
783 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
784 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
785
30126
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
786 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
787 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
788 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
789 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
790 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
791
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
792 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
793 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
794 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
795 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
796
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
797 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
798 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
799 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
800 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
801
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
802 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
803 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
804 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
805 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
806
6575d0bf6061 patch 9.0.0405: arguments in a partial not used by a :def function
Bram Moolenaar <Bram@vim.org>
parents: 30126
diff changeset
807 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
808 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
809 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
810 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
811
6575d0bf6061 patch 9.0.0405: arguments in a partial not used by a :def function
Bram Moolenaar <Bram@vim.org>
parents: 30126
diff changeset
812 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
813 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
814 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
815 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
816 enddef
01408b56f093 patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents: 30122
diff changeset
817
30166
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
818 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
819 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
820 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
821 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
822 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
823
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
824 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
825 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
826 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
827 enddef
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
828 defcompile
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
829 END
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
830 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
831 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
832 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
833 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
834 enddef
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
835 defcompile
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
836 END
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
837 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
838 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
839 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
840 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
841 enddef
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
842 defcompile
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
843 END
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
844 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
845
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
846 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
847 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
848 enddef
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
849
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
850 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
851 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
852 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
853 enddef
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
854 defcompile
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
855 END
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
856 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
857 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
858 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
859 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
860 enddef
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
861 defcompile
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
862 END
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
863 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
864 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
865 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
866 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
867 enddef
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
868 defcompile
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
869 END
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
870 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
871 endfunc
d1c04b4dc60d patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents: 30140
diff changeset
872
33601
28605af12602 patch 9.0.2044: Vim9: exceptions confuse defered functions
Christian Brabandt <cb@256bit.org>
parents: 32278
diff changeset
873 " Test for calling a deferred function after an exception
28605af12602 patch 9.0.2044: Vim9: exceptions confuse defered functions
Christian Brabandt <cb@256bit.org>
parents: 32278
diff changeset
874 func Test_defer_after_exception()
28605af12602 patch 9.0.2044: Vim9: exceptions confuse defered functions
Christian Brabandt <cb@256bit.org>
parents: 32278
diff changeset
875 let g:callTrace = []
33613
31fb1a760ad6 patch 9.0.2050: Vim9: crash with deferred function call and exception
Christian Brabandt <cb@256bit.org>
parents: 33601
diff changeset
876 func Bar()
31fb1a760ad6 patch 9.0.2050: Vim9: crash with deferred function call and exception
Christian Brabandt <cb@256bit.org>
parents: 33601
diff changeset
877 let g:callTrace += [1]
31fb1a760ad6 patch 9.0.2050: Vim9: crash with deferred function call and exception
Christian Brabandt <cb@256bit.org>
parents: 33601
diff changeset
878 throw 'InnerException'
31fb1a760ad6 patch 9.0.2050: Vim9: crash with deferred function call and exception
Christian Brabandt <cb@256bit.org>
parents: 33601
diff changeset
879 endfunc
31fb1a760ad6 patch 9.0.2050: Vim9: crash with deferred function call and exception
Christian Brabandt <cb@256bit.org>
parents: 33601
diff changeset
880
33601
28605af12602 patch 9.0.2044: Vim9: exceptions confuse defered functions
Christian Brabandt <cb@256bit.org>
parents: 32278
diff changeset
881 func Defer()
33613
31fb1a760ad6 patch 9.0.2050: Vim9: crash with deferred function call and exception
Christian Brabandt <cb@256bit.org>
parents: 33601
diff changeset
882 let g:callTrace += [2]
31fb1a760ad6 patch 9.0.2050: Vim9: crash with deferred function call and exception
Christian Brabandt <cb@256bit.org>
parents: 33601
diff changeset
883 let g:callTrace += [3]
31fb1a760ad6 patch 9.0.2050: Vim9: crash with deferred function call and exception
Christian Brabandt <cb@256bit.org>
parents: 33601
diff changeset
884 try
31fb1a760ad6 patch 9.0.2050: Vim9: crash with deferred function call and exception
Christian Brabandt <cb@256bit.org>
parents: 33601
diff changeset
885 call Bar()
31fb1a760ad6 patch 9.0.2050: Vim9: crash with deferred function call and exception
Christian Brabandt <cb@256bit.org>
parents: 33601
diff changeset
886 catch /InnerException/
31fb1a760ad6 patch 9.0.2050: Vim9: crash with deferred function call and exception
Christian Brabandt <cb@256bit.org>
parents: 33601
diff changeset
887 let g:callTrace += [4]
31fb1a760ad6 patch 9.0.2050: Vim9: crash with deferred function call and exception
Christian Brabandt <cb@256bit.org>
parents: 33601
diff changeset
888 endtry
31fb1a760ad6 patch 9.0.2050: Vim9: crash with deferred function call and exception
Christian Brabandt <cb@256bit.org>
parents: 33601
diff changeset
889 let g:callTrace += [5]
31fb1a760ad6 patch 9.0.2050: Vim9: crash with deferred function call and exception
Christian Brabandt <cb@256bit.org>
parents: 33601
diff changeset
890 let g:callTrace += [6]
33601
28605af12602 patch 9.0.2044: Vim9: exceptions confuse defered functions
Christian Brabandt <cb@256bit.org>
parents: 32278
diff changeset
891 endfunc
28605af12602 patch 9.0.2044: Vim9: exceptions confuse defered functions
Christian Brabandt <cb@256bit.org>
parents: 32278
diff changeset
892
28605af12602 patch 9.0.2044: Vim9: exceptions confuse defered functions
Christian Brabandt <cb@256bit.org>
parents: 32278
diff changeset
893 func Foo()
28605af12602 patch 9.0.2044: Vim9: exceptions confuse defered functions
Christian Brabandt <cb@256bit.org>
parents: 32278
diff changeset
894 defer Defer()
28605af12602 patch 9.0.2044: Vim9: exceptions confuse defered functions
Christian Brabandt <cb@256bit.org>
parents: 32278
diff changeset
895 throw "TestException"
28605af12602 patch 9.0.2044: Vim9: exceptions confuse defered functions
Christian Brabandt <cb@256bit.org>
parents: 32278
diff changeset
896 endfunc
28605af12602 patch 9.0.2044: Vim9: exceptions confuse defered functions
Christian Brabandt <cb@256bit.org>
parents: 32278
diff changeset
897
28605af12602 patch 9.0.2044: Vim9: exceptions confuse defered functions
Christian Brabandt <cb@256bit.org>
parents: 32278
diff changeset
898 try
28605af12602 patch 9.0.2044: Vim9: exceptions confuse defered functions
Christian Brabandt <cb@256bit.org>
parents: 32278
diff changeset
899 call Foo()
28605af12602 patch 9.0.2044: Vim9: exceptions confuse defered functions
Christian Brabandt <cb@256bit.org>
parents: 32278
diff changeset
900 catch /TestException/
33613
31fb1a760ad6 patch 9.0.2050: Vim9: crash with deferred function call and exception
Christian Brabandt <cb@256bit.org>
parents: 33601
diff changeset
901 let g:callTrace += [7]
33601
28605af12602 patch 9.0.2044: Vim9: exceptions confuse defered functions
Christian Brabandt <cb@256bit.org>
parents: 32278
diff changeset
902 endtry
33613
31fb1a760ad6 patch 9.0.2050: Vim9: crash with deferred function call and exception
Christian Brabandt <cb@256bit.org>
parents: 33601
diff changeset
903 call assert_equal([2, 3, 1, 4, 5, 6, 7], g:callTrace)
33601
28605af12602 patch 9.0.2044: Vim9: exceptions confuse defered functions
Christian Brabandt <cb@256bit.org>
parents: 32278
diff changeset
904
28605af12602 patch 9.0.2044: Vim9: exceptions confuse defered functions
Christian Brabandt <cb@256bit.org>
parents: 32278
diff changeset
905 delfunc Defer
28605af12602 patch 9.0.2044: Vim9: exceptions confuse defered functions
Christian Brabandt <cb@256bit.org>
parents: 32278
diff changeset
906 delfunc Foo
33636
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
907 delfunc Bar
33601
28605af12602 patch 9.0.2044: Vim9: exceptions confuse defered functions
Christian Brabandt <cb@256bit.org>
parents: 32278
diff changeset
908 unlet g:callTrace
28605af12602 patch 9.0.2044: Vim9: exceptions confuse defered functions
Christian Brabandt <cb@256bit.org>
parents: 32278
diff changeset
909 endfunc
30065
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 28382
diff changeset
910
33636
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
911 " Test for multiple deferred function which throw exceptions.
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
912 " Exceptions thrown by deferred functions should result in error messages but
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
913 " not propagated into the calling functions.
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
914 func Test_multidefer_with_exception()
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
915 let g:callTrace = []
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
916 func Except()
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
917 let g:callTrace += [1]
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
918 throw 'InnerException'
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
919 let g:callTrace += [2]
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
920 endfunc
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
921
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
922 func FirstDefer()
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
923 let g:callTrace += [3]
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
924 let g:callTrace += [4]
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
925 endfunc
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
926
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
927 func SecondDeferWithExcept()
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
928 let g:callTrace += [5]
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
929 call Except()
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
930 let g:callTrace += [6]
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
931 endfunc
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
932
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
933 func ThirdDefer()
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
934 let g:callTrace += [7]
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
935 let g:callTrace += [8]
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
936 endfunc
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
937
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
938 func Foo()
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
939 let g:callTrace += [9]
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
940 defer FirstDefer()
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
941 defer SecondDeferWithExcept()
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
942 defer ThirdDefer()
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
943 let g:callTrace += [10]
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
944 endfunc
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
945
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
946 let v:errmsg = ''
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
947 try
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
948 let g:callTrace += [11]
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
949 call Foo()
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
950 let g:callTrace += [12]
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
951 catch /TestException/
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
952 let g:callTrace += [13]
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
953 catch
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
954 let g:callTrace += [14]
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
955 finally
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
956 let g:callTrace += [15]
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
957 endtry
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
958 let g:callTrace += [16]
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
959
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
960 call assert_equal('E605: Exception not caught: InnerException', v:errmsg)
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
961 call assert_equal([11, 9, 10, 7, 8, 5, 1, 3, 4, 12, 15, 16], g:callTrace)
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
962
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
963 unlet g:callTrace
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
964 delfunc Except
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
965 delfunc FirstDefer
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
966 delfunc SecondDeferWithExcept
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
967 delfunc ThirdDefer
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
968 delfunc Foo
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
969 endfunc
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33613
diff changeset
970
34567
7de5ae6a0518 patch 9.1.0182: Can define function with invalid name inside 'formatexpr'
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
971 func Test_func_curly_brace_invalid_name()
7de5ae6a0518 patch 9.1.0182: Can define function with invalid name inside 'formatexpr'
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
972 func Fail()
7de5ae6a0518 patch 9.1.0182: Can define function with invalid name inside 'formatexpr'
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
973 func Foo{'()'}bar()
7de5ae6a0518 patch 9.1.0182: Can define function with invalid name inside 'formatexpr'
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
974 endfunc
7de5ae6a0518 patch 9.1.0182: Can define function with invalid name inside 'formatexpr'
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
975 endfunc
7de5ae6a0518 patch 9.1.0182: Can define function with invalid name inside 'formatexpr'
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
976
7de5ae6a0518 patch 9.1.0182: Can define function with invalid name inside 'formatexpr'
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
977 call assert_fails('call Fail()', 'E475: Invalid argument: Foo()bar')
7de5ae6a0518 patch 9.1.0182: Can define function with invalid name inside 'formatexpr'
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
978
7de5ae6a0518 patch 9.1.0182: Can define function with invalid name inside 'formatexpr'
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
979 silent! call Fail()
7de5ae6a0518 patch 9.1.0182: Can define function with invalid name inside 'formatexpr'
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
980 call assert_equal([], getcompletion('Foo', 'function'))
7de5ae6a0518 patch 9.1.0182: Can define function with invalid name inside 'formatexpr'
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
981
7de5ae6a0518 patch 9.1.0182: Can define function with invalid name inside 'formatexpr'
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
982 set formatexpr=Fail()
7de5ae6a0518 patch 9.1.0182: Can define function with invalid name inside 'formatexpr'
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
983 normal! gqq
7de5ae6a0518 patch 9.1.0182: Can define function with invalid name inside 'formatexpr'
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
984 call assert_equal([], getcompletion('Foo', 'function'))
7de5ae6a0518 patch 9.1.0182: Can define function with invalid name inside 'formatexpr'
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
985
7de5ae6a0518 patch 9.1.0182: Can define function with invalid name inside 'formatexpr'
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
986 set formatexpr&
7de5ae6a0518 patch 9.1.0182: Can define function with invalid name inside 'formatexpr'
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
987 delfunc Fail
7de5ae6a0518 patch 9.1.0182: Can define function with invalid name inside 'formatexpr'
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
988 endfunc
7de5ae6a0518 patch 9.1.0182: Can define function with invalid name inside 'formatexpr'
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
989
19932
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
990 " vim: shiftwidth=2 sts=2 expandtab