Mercurial > vim
annotate src/testdir/test_user_func.vim @ 32262:854aeaac48b7 v9.0.1462
patch 9.0.1462: recursively calling :defer function if it does :qa
Commit: https://github.com/vim/vim/commit/42994bf678f46dc9ca66e49f512261da8864fff6
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Apr 17 19:23:45 2023 +0100
patch 9.0.1462: recursively calling :defer function if it does :qa
Problem: Recursively calling :defer function if it does :qa.
Solution: Clear the defer entry before calling the function. (closes https://github.com/vim/vim/issues/12266)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 17 Apr 2023 20:30:07 +0200 |
parents | aa45593ec2ca |
children | 83caf07aedd6 |
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 |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
654 func Test_defer_quitall() |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
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 vim9script |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
657 func DeferLevelTwo() |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
658 call writefile(['text'], 'XQuitallTwo', 'D') |
32262
854aeaac48b7
patch 9.0.1462: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents:
31497
diff
changeset
|
659 call writefile(['quit'], 'XQuitallThree', 'a') |
30122
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
660 qa! |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
661 endfunc |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
662 |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
663 def DeferLevelOne() |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
664 call writefile(['text'], 'XQuitallOne', 'D') |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
665 call DeferLevelTwo() |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
666 enddef |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
667 |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
668 DeferLevelOne() |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
669 END |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
670 call writefile(lines, 'XdeferQuitall', 'D') |
30166
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
671 let res = system(GetVimCommand() .. ' -X -S XdeferQuitall') |
30122
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
672 call assert_equal(0, v:shell_error) |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
673 call assert_false(filereadable('XQuitallOne')) |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
674 call assert_false(filereadable('XQuitallTwo')) |
32262
854aeaac48b7
patch 9.0.1462: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents:
31497
diff
changeset
|
675 call assert_equal(['quit'], readfile('XQuitallThree')) |
854aeaac48b7
patch 9.0.1462: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents:
31497
diff
changeset
|
676 |
854aeaac48b7
patch 9.0.1462: recursively calling :defer function if it does :qa
Bram Moolenaar <Bram@vim.org>
parents:
31497
diff
changeset
|
677 call delete('XQuitallThree') |
30122
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
678 endfunc |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
679 |
30140
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
680 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
|
681 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
|
682 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
|
683 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
|
684 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
|
685 qa! |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
686 endif |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
687 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
|
688 enddef |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
689 |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
690 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
|
691 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
|
692 enddef |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
693 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
|
694 END |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
695 call writefile(lines, 'XdeferQuitallExpr', 'D') |
30166
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
696 let res = system(GetVimCommand() .. ' -X -S XdeferQuitallExpr') |
30140
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
697 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
|
698 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
|
699 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
|
700 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
|
701 endfunc |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
702 |
30126
01408b56f093
patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
703 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
|
704 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
|
705 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
|
706 endfunc |
01408b56f093
patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
707 |
01408b56f093
patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
708 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
|
709 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
|
710 return val == 'c' |
01408b56f093
patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
711 enddef |
01408b56f093
patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
712 |
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
|
713 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
|
714 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
|
715 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
|
716 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
|
717 |
30126
01408b56f093
patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
718 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
|
719 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
|
720 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
|
721 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
|
722 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
|
723 |
01408b56f093
patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
724 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
|
725 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
|
726 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
|
727 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
|
728 |
01408b56f093
patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
729 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
|
730 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
|
731 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
|
732 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
|
733 |
01408b56f093
patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
734 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
|
735 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
|
736 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
|
737 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
|
738 |
6575d0bf6061
patch 9.0.0405: arguments in a partial not used by a :def function
Bram Moolenaar <Bram@vim.org>
parents:
30126
diff
changeset
|
739 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
|
740 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
|
741 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
|
742 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
|
743 |
6575d0bf6061
patch 9.0.0405: arguments in a partial not used by a :def function
Bram Moolenaar <Bram@vim.org>
parents:
30126
diff
changeset
|
744 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
|
745 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
|
746 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
|
747 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
|
748 enddef |
01408b56f093
patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
749 |
30166
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
750 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
|
751 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
|
752 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
|
753 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
|
754 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
|
755 |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
756 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
|
757 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
|
758 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
|
759 enddef |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
760 defcompile |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
761 END |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
762 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
|
763 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
|
764 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
|
765 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
|
766 enddef |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
767 defcompile |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
768 END |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
769 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
|
770 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
|
771 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
|
772 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
|
773 enddef |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
774 defcompile |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
775 END |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
776 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
|
777 |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
778 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
|
779 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
|
780 enddef |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
781 |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
782 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
|
783 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
|
784 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
|
785 enddef |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
786 defcompile |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
787 END |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
788 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
|
789 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
|
790 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
|
791 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
|
792 enddef |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
793 defcompile |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
794 END |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
795 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
|
796 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
|
797 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
|
798 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
|
799 enddef |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
800 defcompile |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
801 END |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
802 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
|
803 endfunc |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
804 |
30065
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
28382
diff
changeset
|
805 |
19932
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19689
diff
changeset
|
806 " vim: shiftwidth=2 sts=2 expandtab |