Mercurial > vim
annotate src/testdir/test_vim9_func.vim @ 20182:c07406a4d7f1
Added tag v8.2.0646 for changeset 0ab9d7469ce78a956effe09e7cc165bb8a291437
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 26 Apr 2020 17:00:04 +0200 |
parents | fe8d0a4344df |
children | 63cc54100ae4 |
rev | line source |
---|---|
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 " Test various aspects of the Vim9 script language. |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3 source check.vim |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4 source view_util.vim |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6 " Check that "lines" inside ":def" results in an "error" message. |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 func CheckDefFailure(lines, error) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 call writefile(['def Func()'] + a:lines + ['enddef'], 'Xdef') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 call assert_fails('so Xdef', a:error, a:lines) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 call delete('Xdef') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
11 endfunc |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 func CheckScriptFailure(lines, error) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 call writefile(a:lines, 'Xdef') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 call assert_fails('so Xdef', a:error, a:lines) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
16 call delete('Xdef') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
17 endfunc |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
19 func Test_def_basic() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
20 def SomeFunc(): string |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
21 return 'yes' |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
22 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
23 call assert_equal('yes', SomeFunc()) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
24 endfunc |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
25 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
26 def ReturnString(): string |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
27 return 'string' |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
28 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
29 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
30 def ReturnNumber(): number |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
31 return 123 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
32 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
33 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
34 let g:notNumber = 'string' |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
35 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
36 def ReturnGlobal(): number |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
37 return g:notNumber |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
38 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
39 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
40 def Test_return_something() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
41 assert_equal('string', ReturnString()) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
42 assert_equal(123, ReturnNumber()) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
43 assert_fails('call ReturnGlobal()', 'E1029: Expected number but got string') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
44 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
45 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
46 let s:nothing = 0 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
47 def ReturnNothing() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
48 s:nothing = 1 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
49 if true |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
50 return |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
51 endif |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
52 s:nothing = 2 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
53 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
54 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
55 def Test_return_nothing() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
56 ReturnNothing() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
57 assert_equal(1, s:nothing) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
58 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
59 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
60 func Increment() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
61 let g:counter += 1 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
62 endfunc |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
63 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
64 def Test_call_ufunc_count() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
65 g:counter = 1 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
66 Increment() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
67 Increment() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
68 Increment() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
69 " works with and without :call |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
70 assert_equal(4, g:counter) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
71 call assert_equal(4, g:counter) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
72 unlet g:counter |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
73 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
74 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
75 def MyVarargs(arg: string, ...rest: list<string>): string |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
76 let res = arg |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
77 for s in rest |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
78 res ..= ',' .. s |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
79 endfor |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
80 return res |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
81 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
82 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
83 def Test_call_varargs() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
84 assert_equal('one', MyVarargs('one')) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
85 assert_equal('one,two', MyVarargs('one', 'two')) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
86 assert_equal('one,two,three', MyVarargs('one', 'two', 'three')) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
87 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
88 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
89 def MyDefaultArgs(name = 'string'): string |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
90 return name |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
91 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
92 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
93 def Test_call_default_args() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
94 assert_equal('string', MyDefaultArgs()) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
95 assert_equal('one', MyDefaultArgs('one')) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
96 assert_fails('call MyDefaultArgs("one", "two")', 'E118:') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
97 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
98 call CheckScriptFailure(['def Func(arg: number = asdf)', 'enddef'], 'E1001:') |
19993
efe864a7ce4f
patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
19985
diff
changeset
|
99 call CheckScriptFailure(['def Func(arg: number = "text")', 'enddef'], 'E1013: argument 1: type mismatch, expected number but got string') |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
100 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
101 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
102 func Test_call_default_args_from_func() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
103 call assert_equal('string', MyDefaultArgs()) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
104 call assert_equal('one', MyDefaultArgs('one')) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
105 call assert_fails('call MyDefaultArgs("one", "two")', 'E118:') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
106 endfunc |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
107 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
108 func TakesOneArg(arg) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
109 echo a:arg |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
110 endfunc |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
111 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
112 def Test_call_wrong_args() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
113 call CheckDefFailure(['TakesOneArg()'], 'E119:') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
114 call CheckDefFailure(['TakesOneArg(11, 22)'], 'E118:') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
115 call CheckDefFailure(['bufnr(xxx)'], 'E1001:') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
116 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
117 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
118 " Default arg and varargs |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
119 def MyDefVarargs(one: string, two = 'foo', ...rest: list<string>): string |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
120 let res = one .. ',' .. two |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
121 for s in rest |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
122 res ..= ',' .. s |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
123 endfor |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
124 return res |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
125 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
126 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
127 def Test_call_def_varargs() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
128 call assert_fails('call MyDefVarargs()', 'E119:') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
129 assert_equal('one,foo', MyDefVarargs('one')) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
130 assert_equal('one,two', MyDefVarargs('one', 'two')) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
131 assert_equal('one,two,three', MyDefVarargs('one', 'two', 'three')) |
19946
8466e62a2481
patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents:
19944
diff
changeset
|
132 call CheckDefFailure(['MyDefVarargs("one", 22)'], 'E1013: argument 2: type mismatch, expected string but got number') |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
133 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
134 |
19975
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
135 let s:value = '' |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
136 |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
137 def FuncOneDefArg(opt = 'text') |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
138 s:value = opt |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
139 enddef |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
140 |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
141 def FuncTwoDefArg(nr = 123, opt = 'text'): string |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
142 return nr .. opt |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
143 enddef |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
144 |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
145 def FuncVarargs(...arg: list<string>): string |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
146 return join(arg, ',') |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
147 enddef |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
148 |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
149 def Test_func_type_varargs() |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
150 let RefDefArg: func(?string) |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
151 RefDefArg = FuncOneDefArg |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
152 RefDefArg() |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
153 assert_equal('text', s:value) |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
154 RefDefArg('some') |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
155 assert_equal('some', s:value) |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
156 |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
157 let RefDef2Arg: func(?number, ?string): string |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
158 RefDef2Arg = FuncTwoDefArg |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
159 assert_equal('123text', RefDef2Arg()) |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
160 assert_equal('99text', RefDef2Arg(99)) |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
161 assert_equal('77some', RefDef2Arg(77, 'some')) |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
162 |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
163 call CheckDefFailure(['let RefWrong: func(string?)'], 'E1010:') |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
164 call CheckDefFailure(['let RefWrong: func(?string, string)'], 'E1007:') |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
165 |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
166 let RefVarargs: func(...list<string>): string |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
167 RefVarargs = FuncVarargs |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
168 assert_equal('', RefVarargs()) |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
169 assert_equal('one', RefVarargs('one')) |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
170 assert_equal('one,two', RefVarargs('one', 'two')) |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
171 |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
172 call CheckDefFailure(['let RefWrong: func(...list<string>, string)'], 'E110:') |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
173 call CheckDefFailure(['let RefWrong: func(...list<string>, ?string)'], 'E110:') |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
174 enddef |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
175 |
19944
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
176 " Only varargs |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
177 def MyVarargsOnly(...args: list<string>): string |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
178 return join(args, ',') |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
179 enddef |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
180 |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
181 def Test_call_varargs_only() |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
182 assert_equal('', MyVarargsOnly()) |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
183 assert_equal('one', MyVarargsOnly('one')) |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
184 assert_equal('one,two', MyVarargsOnly('one', 'two')) |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
185 call CheckDefFailure(['MyVarargsOnly(1)'], 'E1013: argument 1: type mismatch, expected string but got number') |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
186 call CheckDefFailure(['MyVarargsOnly("one", 2)'], 'E1013: argument 2: type mismatch, expected string but got number') |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
187 enddef |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
188 |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
189 def Test_using_var_as_arg() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
190 call writefile(['def Func(x: number)', 'let x = 234', 'enddef'], 'Xdef') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
191 call assert_fails('so Xdef', 'E1006:') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
192 call delete('Xdef') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
193 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
194 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
195 def Test_call_func_defined_later() |
20140
39a18a0df429
patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents:
20029
diff
changeset
|
196 call assert_equal('one', g:DefinedLater('one')) |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
197 call assert_fails('call NotDefined("one")', 'E117:') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
198 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
199 |
20140
39a18a0df429
patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents:
20029
diff
changeset
|
200 func DefinedLater(arg) |
39a18a0df429
patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents:
20029
diff
changeset
|
201 return a:arg |
39a18a0df429
patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents:
20029
diff
changeset
|
202 endfunc |
39a18a0df429
patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents:
20029
diff
changeset
|
203 |
39a18a0df429
patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents:
20029
diff
changeset
|
204 def Test_call_funcref() |
39a18a0df429
patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents:
20029
diff
changeset
|
205 assert_equal(3, g:SomeFunc('abc')) |
39a18a0df429
patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents:
20029
diff
changeset
|
206 assert_fails('NotAFunc()', 'E117:') |
39a18a0df429
patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents:
20029
diff
changeset
|
207 assert_fails('g:NotAFunc()', 'E117:') |
39a18a0df429
patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents:
20029
diff
changeset
|
208 enddef |
39a18a0df429
patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents:
20029
diff
changeset
|
209 |
39a18a0df429
patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents:
20029
diff
changeset
|
210 let SomeFunc = function('len') |
39a18a0df429
patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents:
20029
diff
changeset
|
211 let NotAFunc = 'text' |
39a18a0df429
patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents:
20029
diff
changeset
|
212 |
19993
efe864a7ce4f
patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
19985
diff
changeset
|
213 def CombineFuncrefTypes() |
efe864a7ce4f
patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
19985
diff
changeset
|
214 " same arguments, different return type |
efe864a7ce4f
patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
19985
diff
changeset
|
215 let Ref1: func(bool): string |
efe864a7ce4f
patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
19985
diff
changeset
|
216 let Ref2: func(bool): number |
efe864a7ce4f
patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
19985
diff
changeset
|
217 let Ref3: func(bool): any |
efe864a7ce4f
patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
19985
diff
changeset
|
218 Ref3 = g:cond ? Ref1 : Ref2 |
efe864a7ce4f
patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
19985
diff
changeset
|
219 |
efe864a7ce4f
patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
19985
diff
changeset
|
220 " different number of arguments |
efe864a7ce4f
patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
19985
diff
changeset
|
221 let Refa1: func(bool): number |
efe864a7ce4f
patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
19985
diff
changeset
|
222 let Refa2: func(bool, number): number |
efe864a7ce4f
patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
19985
diff
changeset
|
223 let Refa3: func: number |
efe864a7ce4f
patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
19985
diff
changeset
|
224 Refa3 = g:cond ? Refa1 : Refa2 |
efe864a7ce4f
patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
19985
diff
changeset
|
225 |
efe864a7ce4f
patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
19985
diff
changeset
|
226 " different argument types |
efe864a7ce4f
patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
19985
diff
changeset
|
227 let Refb1: func(bool, string): number |
efe864a7ce4f
patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
19985
diff
changeset
|
228 let Refb2: func(string, number): number |
efe864a7ce4f
patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
19985
diff
changeset
|
229 let Refb3: func(any, any): number |
efe864a7ce4f
patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
19985
diff
changeset
|
230 Refb3 = g:cond ? Refb1 : Refb2 |
efe864a7ce4f
patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
19985
diff
changeset
|
231 enddef |
efe864a7ce4f
patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
19985
diff
changeset
|
232 |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
233 def FuncWithForwardCall() |
20140
39a18a0df429
patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents:
20029
diff
changeset
|
234 return g:DefinedEvenLater("yes") |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
235 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
236 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
237 def DefinedEvenLater(arg: string): string |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
238 return arg |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
239 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
240 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
241 def Test_error_in_nested_function() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
242 " Error in called function requires unwinding the call stack. |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
243 assert_fails('call FuncWithForwardCall()', 'E1029') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
244 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
245 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
246 def Test_return_type_wrong() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
247 CheckScriptFailure(['def Func(): number', 'return "a"', 'enddef'], 'expected number but got string') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
248 CheckScriptFailure(['def Func(): string', 'return 1', 'enddef'], 'expected string but got number') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
249 CheckScriptFailure(['def Func(): void', 'return "a"', 'enddef'], 'expected void but got string') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
250 CheckScriptFailure(['def Func()', 'return "a"', 'enddef'], 'expected void but got string') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
251 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
252 CheckScriptFailure(['def Func(): number', 'return', 'enddef'], 'E1003:') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
253 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
254 CheckScriptFailure(['def Func(): list', 'return []', 'enddef'], 'E1008:') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
255 CheckScriptFailure(['def Func(): dict', 'return {}', 'enddef'], 'E1008:') |
19932
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
256 CheckScriptFailure(['def Func()', 'return 1'], 'E1057:') |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
257 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
258 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
259 def Test_arg_type_wrong() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
260 CheckScriptFailure(['def Func3(items: list)', 'echo "a"', 'enddef'], 'E1008: Missing <type>') |
19932
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
261 CheckScriptFailure(['def Func4(...)', 'echo "a"', 'enddef'], 'E1055: Missing name after ...') |
20142
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
262 CheckScriptFailure(['def Func5(items:string)', 'echo "a"'], 'E1069:') |
20029
8fb1cf4c44d5
patch 8.2.0570: Vim9: no error when omitting type from argument
Bram Moolenaar <Bram@vim.org>
parents:
20023
diff
changeset
|
263 CheckScriptFailure(['def Func5(items)', 'echo "a"'], 'E1077:') |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
264 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
265 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
266 def Test_vim9script_call() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
267 let lines =<< trim END |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
268 vim9script |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
269 let var = '' |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
270 def MyFunc(arg: string) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
271 var = arg |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
272 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
273 MyFunc('foobar') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
274 assert_equal('foobar', var) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
275 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
276 let str = 'barfoo' |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
277 str->MyFunc() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
278 assert_equal('barfoo', var) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
279 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
280 let g:value = 'value' |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
281 g:value->MyFunc() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
282 assert_equal('value', var) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
283 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
284 let listvar = [] |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
285 def ListFunc(arg: list<number>) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
286 listvar = arg |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
287 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
288 [1, 2, 3]->ListFunc() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
289 assert_equal([1, 2, 3], listvar) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
290 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
291 let dictvar = {} |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
292 def DictFunc(arg: dict<number>) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
293 dictvar = arg |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
294 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
295 {'a': 1, 'b': 2}->DictFunc() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
296 assert_equal(#{a: 1, b: 2}, dictvar) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
297 def CompiledDict() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
298 {'a': 3, 'b': 4}->DictFunc() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
299 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
300 CompiledDict() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
301 assert_equal(#{a: 3, b: 4}, dictvar) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
302 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
303 #{a: 3, b: 4}->DictFunc() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
304 assert_equal(#{a: 3, b: 4}, dictvar) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
305 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
306 ('text')->MyFunc() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
307 assert_equal('text', var) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
308 ("some")->MyFunc() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
309 assert_equal('some', var) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
310 END |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
311 writefile(lines, 'Xcall.vim') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
312 source Xcall.vim |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
313 delete('Xcall.vim') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
314 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
315 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
316 def Test_vim9script_call_fail_decl() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
317 let lines =<< trim END |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
318 vim9script |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
319 let var = '' |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
320 def MyFunc(arg: string) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
321 let var = 123 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
322 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
323 END |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
324 writefile(lines, 'Xcall_decl.vim') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
325 assert_fails('source Xcall_decl.vim', 'E1054:') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
326 delete('Xcall_decl.vim') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
327 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
328 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
329 def Test_vim9script_call_fail_const() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
330 let lines =<< trim END |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
331 vim9script |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
332 const var = '' |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
333 def MyFunc(arg: string) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
334 var = 'asdf' |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
335 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
336 END |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
337 writefile(lines, 'Xcall_const.vim') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
338 assert_fails('source Xcall_const.vim', 'E46:') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
339 delete('Xcall_const.vim') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
340 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
341 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
342 " Test that inside :function a Python function can be defined, :def is not |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
343 " recognized. |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
344 func Test_function_python() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
345 CheckFeature python3 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
346 let py = 'python3' |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
347 execute py "<< EOF" |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
348 def do_something(): |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
349 return 1 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
350 EOF |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
351 endfunc |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
352 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
353 def Test_delfunc() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
354 let lines =<< trim END |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
355 vim9script |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
356 def GoneSoon() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
357 echo 'hello' |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
358 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
359 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
360 def CallGoneSoon() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
361 GoneSoon() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
362 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
363 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
364 delfunc GoneSoon |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
365 CallGoneSoon() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
366 END |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
367 writefile(lines, 'XToDelFunc') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
368 assert_fails('so XToDelFunc', 'E933') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
369 assert_fails('so XToDelFunc', 'E933') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
370 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
371 delete('XToDelFunc') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
372 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
373 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
374 def Test_redef_failure() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
375 call writefile(['def Func0(): string', 'return "Func0"', 'enddef'], 'Xdef') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
376 so Xdef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
377 call writefile(['def Func1(): string', 'return "Func1"', 'enddef'], 'Xdef') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
378 so Xdef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
379 call writefile(['def! Func0(): string', 'enddef'], 'Xdef') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
380 call assert_fails('so Xdef', 'E1027:') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
381 call writefile(['def Func2(): string', 'return "Func2"', 'enddef'], 'Xdef') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
382 so Xdef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
383 call delete('Xdef') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
384 |
20140
39a18a0df429
patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents:
20029
diff
changeset
|
385 call assert_equal(0, g:Func0()) |
39a18a0df429
patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents:
20029
diff
changeset
|
386 call assert_equal('Func1', g:Func1()) |
39a18a0df429
patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents:
20029
diff
changeset
|
387 call assert_equal('Func2', g:Func2()) |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
388 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
389 delfunc! Func0 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
390 delfunc! Func1 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
391 delfunc! Func2 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
392 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
393 |
20142
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
394 def Test_vim9script_func() |
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
395 let lines =<< trim END |
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
396 vim9script |
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
397 func Func(arg) |
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
398 echo a:arg |
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
399 endfunc |
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
400 Func('text') |
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
401 END |
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
402 writefile(lines, 'XVim9Func') |
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
403 so XVim9Func |
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
404 |
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
405 delete('XVim9Func') |
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
406 enddef |
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
407 |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
408 " Test for internal functions returning different types |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
409 func Test_InternalFuncRetType() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
410 let lines =<< trim END |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
411 def RetFloat(): float |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
412 return ceil(1.456) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
413 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
414 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
415 def RetListAny(): list<any> |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
416 return items({'k' : 'v'}) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
417 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
418 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
419 def RetListString(): list<string> |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
420 return split('a:b:c', ':') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
421 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
422 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
423 def RetListDictAny(): list<dict<any>> |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
424 return getbufinfo() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
425 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
426 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
427 def RetDictNumber(): dict<number> |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
428 return wordcount() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
429 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
430 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
431 def RetDictString(): dict<string> |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
432 return environ() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
433 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
434 END |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
435 call writefile(lines, 'Xscript') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
436 source Xscript |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
437 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
438 call assert_equal(2.0, RetFloat()) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
439 call assert_equal([['k', 'v']], RetListAny()) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
440 call assert_equal(['a', 'b', 'c'], RetListString()) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
441 call assert_notequal([], RetListDictAny()) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
442 call assert_notequal({}, RetDictNumber()) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
443 call assert_notequal({}, RetDictString()) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
444 call delete('Xscript') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
445 endfunc |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
446 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
447 " Test for passing too many or too few arguments to internal functions |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
448 func Test_internalfunc_arg_error() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
449 let l =<< trim END |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
450 def! FArgErr(): float |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
451 return ceil(1.1, 2) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
452 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
453 END |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
454 call writefile(l, 'Xinvalidarg') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
455 call assert_fails('so Xinvalidarg', 'E118:') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
456 let l =<< trim END |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
457 def! FArgErr(): float |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
458 return ceil() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
459 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
460 END |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
461 call writefile(l, 'Xinvalidarg') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
462 call assert_fails('so Xinvalidarg', 'E119:') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
463 call delete('Xinvalidarg') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
464 endfunc |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
465 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
466 let s:funcResult = 0 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
467 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
468 def FuncNoArgNoRet() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
469 funcResult = 11 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
470 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
471 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
472 def FuncNoArgRetNumber(): number |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
473 funcResult = 22 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
474 return 1234 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
475 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
476 |
19942
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
477 def FuncNoArgRetString(): string |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
478 funcResult = 45 |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
479 return 'text' |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
480 enddef |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
481 |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
482 def FuncOneArgNoRet(arg: number) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
483 funcResult = arg |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
484 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
485 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
486 def FuncOneArgRetNumber(arg: number): number |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
487 funcResult = arg |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
488 return arg |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
489 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
490 |
19985
f863aa96cae5
patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents:
19975
diff
changeset
|
491 def FuncTwoArgNoRet(one: bool, two: number) |
f863aa96cae5
patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents:
19975
diff
changeset
|
492 funcResult = two |
f863aa96cae5
patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents:
19975
diff
changeset
|
493 enddef |
f863aa96cae5
patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents:
19975
diff
changeset
|
494 |
19942
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
495 def FuncOneArgRetString(arg: string): string |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
496 return arg |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
497 enddef |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
498 |
19926
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
499 def FuncOneArgRetAny(arg: any): any |
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
500 return arg |
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
501 enddef |
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
502 |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
503 def Test_func_type() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
504 let Ref1: func() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
505 funcResult = 0 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
506 Ref1 = FuncNoArgNoRet |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
507 Ref1() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
508 assert_equal(11, funcResult) |
19922
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
509 |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
510 let Ref2: func |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
511 funcResult = 0 |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
512 Ref2 = FuncNoArgNoRet |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
513 Ref2() |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
514 assert_equal(11, funcResult) |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
515 |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
516 funcResult = 0 |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
517 Ref2 = FuncOneArgNoRet |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
518 Ref2(12) |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
519 assert_equal(12, funcResult) |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
520 |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
521 funcResult = 0 |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
522 Ref2 = FuncNoArgRetNumber |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
523 assert_equal(1234, Ref2()) |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
524 assert_equal(22, funcResult) |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
525 |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
526 funcResult = 0 |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
527 Ref2 = FuncOneArgRetNumber |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
528 assert_equal(13, Ref2(13)) |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
529 assert_equal(13, funcResult) |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
530 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
531 |
19942
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
532 def Test_func_type_part() |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
533 let RefVoid: func: void |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
534 RefVoid = FuncNoArgNoRet |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
535 RefVoid = FuncOneArgNoRet |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
536 CheckDefFailure(['let RefVoid: func: void', 'RefVoid = FuncNoArgRetNumber'], 'E1013: type mismatch, expected func() but got func(): number') |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
537 CheckDefFailure(['let RefVoid: func: void', 'RefVoid = FuncNoArgRetString'], 'E1013: type mismatch, expected func() but got func(): string') |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
538 |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
539 let RefAny: func(): any |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
540 RefAny = FuncNoArgRetNumber |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
541 RefAny = FuncNoArgRetString |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
542 CheckDefFailure(['let RefAny: func(): any', 'RefAny = FuncNoArgNoRet'], 'E1013: type mismatch, expected func(): any but got func()') |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
543 CheckDefFailure(['let RefAny: func(): any', 'RefAny = FuncOneArgNoRet'], 'E1013: type mismatch, expected func(): any but got func(number)') |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
544 |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
545 let RefNr: func: number |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
546 RefNr = FuncNoArgRetNumber |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
547 RefNr = FuncOneArgRetNumber |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
548 CheckDefFailure(['let RefNr: func: number', 'RefNr = FuncNoArgNoRet'], 'E1013: type mismatch, expected func(): number but got func()') |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
549 CheckDefFailure(['let RefNr: func: number', 'RefNr = FuncNoArgRetString'], 'E1013: type mismatch, expected func(): number but got func(): string') |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
550 |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
551 let RefStr: func: string |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
552 RefStr = FuncNoArgRetString |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
553 RefStr = FuncOneArgRetString |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
554 CheckDefFailure(['let RefStr: func: string', 'RefStr = FuncNoArgNoRet'], 'E1013: type mismatch, expected func(): string but got func()') |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
555 CheckDefFailure(['let RefStr: func: string', 'RefStr = FuncNoArgRetNumber'], 'E1013: type mismatch, expected func(): string but got func(): number') |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
556 enddef |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
557 |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
558 def Test_func_type_fails() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
559 CheckDefFailure(['let ref1: func()'], 'E704:') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
560 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
561 CheckDefFailure(['let Ref1: func()', 'Ref1 = FuncNoArgRetNumber'], 'E1013: type mismatch, expected func() but got func(): number') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
562 CheckDefFailure(['let Ref1: func()', 'Ref1 = FuncOneArgNoRet'], 'E1013: type mismatch, expected func() but got func(number)') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
563 CheckDefFailure(['let Ref1: func()', 'Ref1 = FuncOneArgRetNumber'], 'E1013: type mismatch, expected func() but got func(number): number') |
19985
f863aa96cae5
patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents:
19975
diff
changeset
|
564 CheckDefFailure(['let Ref1: func(bool)', 'Ref1 = FuncTwoArgNoRet'], 'E1013: type mismatch, expected func(bool) but got func(bool, number)') |
f863aa96cae5
patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents:
19975
diff
changeset
|
565 CheckDefFailure(['let Ref1: func(?bool)', 'Ref1 = FuncTwoArgNoRet'], 'E1013: type mismatch, expected func(?bool) but got func(bool, number)') |
f863aa96cae5
patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents:
19975
diff
changeset
|
566 CheckDefFailure(['let Ref1: func(...bool)', 'Ref1 = FuncTwoArgNoRet'], 'E1013: type mismatch, expected func(...bool) but got func(bool, number)') |
f863aa96cae5
patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents:
19975
diff
changeset
|
567 |
f863aa96cae5
patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents:
19975
diff
changeset
|
568 call CheckDefFailure(['let RefWrong: func(string ,number)'], 'E1068:') |
f863aa96cae5
patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents:
19975
diff
changeset
|
569 call CheckDefFailure(['let RefWrong: func(string,number)'], 'E1069:') |
f863aa96cae5
patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents:
19975
diff
changeset
|
570 call CheckDefFailure(['let RefWrong: func(bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool)'], 'E740:') |
f863aa96cae5
patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents:
19975
diff
changeset
|
571 call CheckDefFailure(['let RefWrong: func(bool):string'], 'E1069:') |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
572 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
573 |
19926
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
574 def Test_func_return_type() |
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
575 let nr: number |
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
576 nr = FuncNoArgRetNumber() |
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
577 assert_equal(1234, nr) |
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
578 |
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
579 nr = FuncOneArgRetAny(122) |
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
580 assert_equal(122, nr) |
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
581 |
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
582 let str: string |
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
583 str = FuncOneArgRetAny('yes') |
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
584 assert_equal('yes', str) |
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
585 |
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
586 CheckDefFailure(['let str: string', 'str = FuncNoArgRetNumber()'], 'E1013: type mismatch, expected string but got number') |
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
587 enddef |
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
588 |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
589 def MultiLine( |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
590 arg1: string, |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
591 arg2 = 1234, |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
592 ...rest: list<string> |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
593 ): string |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
594 return arg1 .. arg2 .. join(rest, '-') |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
595 enddef |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
596 |
20023
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20017
diff
changeset
|
597 def MultiLineComment( |
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20017
diff
changeset
|
598 arg1: string, # comment |
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20017
diff
changeset
|
599 arg2 = 1234, # comment |
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20017
diff
changeset
|
600 ...rest: list<string> # comment |
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20017
diff
changeset
|
601 ): string # comment |
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20017
diff
changeset
|
602 return arg1 .. arg2 .. join(rest, '-') |
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20017
diff
changeset
|
603 enddef |
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20017
diff
changeset
|
604 |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
605 def Test_multiline() |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
606 assert_equal('text1234', MultiLine('text')) |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
607 assert_equal('text777', MultiLine('text', 777)) |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
608 assert_equal('text777one', MultiLine('text', 777, 'one')) |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
609 assert_equal('text777one-two', MultiLine('text', 777, 'one', 'two')) |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
610 enddef |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
611 |
20017
ee823254dda5
patch 8.2.0564: Vim9: calling a def function from non-vim9 may fail
Bram Moolenaar <Bram@vim.org>
parents:
20015
diff
changeset
|
612 func Test_multiline_not_vim9() |
ee823254dda5
patch 8.2.0564: Vim9: calling a def function from non-vim9 may fail
Bram Moolenaar <Bram@vim.org>
parents:
20015
diff
changeset
|
613 call assert_equal('text1234', MultiLine('text')) |
ee823254dda5
patch 8.2.0564: Vim9: calling a def function from non-vim9 may fail
Bram Moolenaar <Bram@vim.org>
parents:
20015
diff
changeset
|
614 call assert_equal('text777', MultiLine('text', 777)) |
ee823254dda5
patch 8.2.0564: Vim9: calling a def function from non-vim9 may fail
Bram Moolenaar <Bram@vim.org>
parents:
20015
diff
changeset
|
615 call assert_equal('text777one', MultiLine('text', 777, 'one')) |
ee823254dda5
patch 8.2.0564: Vim9: calling a def function from non-vim9 may fail
Bram Moolenaar <Bram@vim.org>
parents:
20015
diff
changeset
|
616 call assert_equal('text777one-two', MultiLine('text', 777, 'one', 'two')) |
ee823254dda5
patch 8.2.0564: Vim9: calling a def function from non-vim9 may fail
Bram Moolenaar <Bram@vim.org>
parents:
20015
diff
changeset
|
617 endfunc |
ee823254dda5
patch 8.2.0564: Vim9: calling a def function from non-vim9 may fail
Bram Moolenaar <Bram@vim.org>
parents:
20015
diff
changeset
|
618 |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
619 |
19932
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
620 " When using CheckScriptFailure() for the below test, E1010 is generated instead |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
621 " of E1056. |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
622 func Test_E1056_1059() |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
623 let caught_1056 = 0 |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
624 try |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
625 def F(): |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
626 return 1 |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
627 enddef |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
628 catch /E1056:/ |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
629 let caught_1056 = 1 |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
630 endtry |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
631 call assert_equal(1, caught_1056) |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
632 |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
633 let caught_1059 = 0 |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
634 try |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
635 def F5(items : list) |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
636 echo 'a' |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
637 enddef |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
638 catch /E1059:/ |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
639 let caught_1059 = 1 |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
640 endtry |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
641 call assert_equal(1, caught_1059) |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
642 endfunc |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
643 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
644 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker |