Mercurial > vim
annotate src/testdir/test_vim9_func.vim @ 21283:1d2c814f4bed v8.2.1192
patch 8.2.1192: Lua test fails with older Lua version
Commit: https://github.com/vim/vim/commit/b898a029b01866b1dbe07521e153d54917b9527d
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jul 12 18:33:53 2020 +0200
patch 8.2.1192: Lua test fails with older Lua version
Problem: Lua test fails with older Lua version.
Solution: Adjust expected error messages. (closes https://github.com/vim/vim/issues/6444)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 12 Jul 2020 18:45:03 +0200 |
parents | 13b1567ae0c6 |
children | 60011b87aae1 |
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 |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
5 source vim9.vim |
21172
96ae8622cfb6
patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents:
21170
diff
changeset
|
6 source screendump.vim |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 func Test_def_basic() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 def SomeFunc(): string |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 return 'yes' |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
11 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 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
|
13 endfunc |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 def ReturnString(): string |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
16 return 'string' |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
17 enddef |
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 def ReturnNumber(): number |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
20 return 123 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
21 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
22 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
23 let g:notNumber = 'string' |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
24 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
25 def ReturnGlobal(): number |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
26 return g:notNumber |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
27 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
28 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
29 def Test_return_something() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
30 assert_equal('string', ReturnString()) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
31 assert_equal(123, ReturnNumber()) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
32 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
|
33 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
34 |
20909
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20903
diff
changeset
|
35 def Test_missing_return() |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20903
diff
changeset
|
36 CheckDefFailure(['def Missing(): number', |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20903
diff
changeset
|
37 ' if g:cond', |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20903
diff
changeset
|
38 ' echo "no return"', |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20903
diff
changeset
|
39 ' else', |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20903
diff
changeset
|
40 ' return 0', |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20903
diff
changeset
|
41 ' endif' |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20903
diff
changeset
|
42 'enddef'], 'E1027:') |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20903
diff
changeset
|
43 CheckDefFailure(['def Missing(): number', |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20903
diff
changeset
|
44 ' if g:cond', |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20903
diff
changeset
|
45 ' return 1', |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20903
diff
changeset
|
46 ' else', |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20903
diff
changeset
|
47 ' echo "no return"', |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20903
diff
changeset
|
48 ' endif' |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20903
diff
changeset
|
49 'enddef'], 'E1027:') |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20903
diff
changeset
|
50 CheckDefFailure(['def Missing(): number', |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20903
diff
changeset
|
51 ' if g:cond', |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20903
diff
changeset
|
52 ' return 1', |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20903
diff
changeset
|
53 ' else', |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20903
diff
changeset
|
54 ' return 2', |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20903
diff
changeset
|
55 ' endif' |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20903
diff
changeset
|
56 ' return 3' |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20903
diff
changeset
|
57 'enddef'], 'E1095:') |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20903
diff
changeset
|
58 enddef |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20903
diff
changeset
|
59 |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
60 let s:nothing = 0 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
61 def ReturnNothing() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
62 s:nothing = 1 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
63 if true |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
64 return |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
65 endif |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
66 s:nothing = 2 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
67 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
68 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
69 def Test_return_nothing() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
70 ReturnNothing() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
71 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
|
72 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
73 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
74 func Increment() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
75 let g:counter += 1 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
76 endfunc |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
77 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
78 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
|
79 g:counter = 1 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
80 Increment() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
81 Increment() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
82 Increment() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
83 " 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
|
84 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
|
85 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
|
86 unlet g:counter |
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 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
|
90 let res = arg |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
91 for s in rest |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
92 res ..= ',' .. s |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
93 endfor |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
94 return res |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
95 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
96 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
97 def Test_call_varargs() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
98 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
|
99 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
|
100 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
|
101 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
102 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
103 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
|
104 return name |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
105 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
106 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
107 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
|
108 assert_equal('string', MyDefaultArgs()) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
109 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
|
110 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
|
111 |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
112 CheckScriptFailure(['def Func(arg: number = asdf)', 'enddef', 'defcompile'], 'E1001:') |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
113 CheckScriptFailure(['def Func(arg: number = "text")', 'enddef', 'defcompile'], 'E1013: argument 1: type mismatch, expected number but got string') |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
114 enddef |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
115 |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
116 def Test_nested_function() |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
117 def Nested(arg: string): string |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
118 return 'nested ' .. arg |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
119 enddef |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
120 assert_equal('nested function', Nested('function')) |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
121 |
20281
ab8c8fd0f868
patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20279
diff
changeset
|
122 CheckDefFailure(['def Nested()', 'enddef', 'Nested(66)'], 'E118:') |
ab8c8fd0f868
patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20279
diff
changeset
|
123 CheckDefFailure(['def Nested(arg: string)', 'enddef', 'Nested()'], 'E119:') |
ab8c8fd0f868
patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20279
diff
changeset
|
124 |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
125 CheckDefFailure(['func Nested()', 'endfunc'], 'E1086:') |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
126 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
127 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
128 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
|
129 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
|
130 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
|
131 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
|
132 endfunc |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
133 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
134 func TakesOneArg(arg) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
135 echo a:arg |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
136 endfunc |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
137 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
138 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
|
139 call CheckDefFailure(['TakesOneArg()'], 'E119:') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
140 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
|
141 call CheckDefFailure(['bufnr(xxx)'], 'E1001:') |
20253
6f9010b6f7f9
patch 8.2.0682: Vim9: parsing function argument type can get stuck
Bram Moolenaar <Bram@vim.org>
parents:
20247
diff
changeset
|
142 call CheckScriptFailure(['def Func(Ref: func(s: string))'], 'E475:') |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
143 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
144 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
145 " Default arg and varargs |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
146 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
|
147 let res = one .. ',' .. two |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
148 for s in rest |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
149 res ..= ',' .. s |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
150 endfor |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
151 return res |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
152 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
153 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
154 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
|
155 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
|
156 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
|
157 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
|
158 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
|
159 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
|
160 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
161 |
19975
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
162 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
|
163 |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
164 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
|
165 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
|
166 enddef |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
167 |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
168 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
|
169 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
|
170 enddef |
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 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
|
173 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
|
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 |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
176 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
|
177 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
|
178 RefDefArg = FuncOneDefArg |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
179 RefDefArg() |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
180 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
|
181 RefDefArg('some') |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
182 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
|
183 |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
184 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
|
185 RefDef2Arg = FuncTwoDefArg |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
186 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
|
187 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
|
188 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
|
189 |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
190 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
|
191 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
|
192 |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
193 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
|
194 RefVarargs = FuncVarargs |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
195 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
|
196 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
|
197 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
|
198 |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
199 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
|
200 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
|
201 enddef |
4e8e0ce576af
patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
202 |
19944
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
203 " Only varargs |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
204 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
|
205 return join(args, ',') |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
206 enddef |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
207 |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
208 def Test_call_varargs_only() |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
209 assert_equal('', MyVarargsOnly()) |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
210 assert_equal('one', MyVarargsOnly('one')) |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
211 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
|
212 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
|
213 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
|
214 enddef |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
215 |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
216 def Test_using_var_as_arg() |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
217 call writefile(['def Func(x: number)', 'let x = 234', 'enddef', 'defcompile'], 'Xdef') |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
218 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
|
219 call delete('Xdef') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
220 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
221 |
20355
fc2d76e0994c
patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents:
20303
diff
changeset
|
222 def DictArg(arg: dict<string>) |
fc2d76e0994c
patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents:
20303
diff
changeset
|
223 arg['key'] = 'value' |
fc2d76e0994c
patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents:
20303
diff
changeset
|
224 enddef |
fc2d76e0994c
patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents:
20303
diff
changeset
|
225 |
fc2d76e0994c
patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents:
20303
diff
changeset
|
226 def ListArg(arg: list<string>) |
fc2d76e0994c
patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents:
20303
diff
changeset
|
227 arg[0] = 'value' |
fc2d76e0994c
patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents:
20303
diff
changeset
|
228 enddef |
fc2d76e0994c
patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents:
20303
diff
changeset
|
229 |
fc2d76e0994c
patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents:
20303
diff
changeset
|
230 def Test_assign_to_argument() |
fc2d76e0994c
patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents:
20303
diff
changeset
|
231 " works for dict and list |
fc2d76e0994c
patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents:
20303
diff
changeset
|
232 let d: dict<string> = {} |
fc2d76e0994c
patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents:
20303
diff
changeset
|
233 DictArg(d) |
fc2d76e0994c
patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents:
20303
diff
changeset
|
234 assert_equal('value', d['key']) |
fc2d76e0994c
patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents:
20303
diff
changeset
|
235 let l: list<string> = [] |
fc2d76e0994c
patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents:
20303
diff
changeset
|
236 ListArg(l) |
fc2d76e0994c
patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents:
20303
diff
changeset
|
237 assert_equal('value', l[0]) |
fc2d76e0994c
patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents:
20303
diff
changeset
|
238 |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
239 call CheckScriptFailure(['def Func(arg: number)', 'arg = 3', 'enddef', 'defcompile'], 'E1090:') |
20355
fc2d76e0994c
patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents:
20303
diff
changeset
|
240 enddef |
fc2d76e0994c
patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents:
20303
diff
changeset
|
241 |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
242 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
|
243 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
|
244 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
|
245 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
246 |
20140
39a18a0df429
patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents:
20029
diff
changeset
|
247 func DefinedLater(arg) |
39a18a0df429
patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents:
20029
diff
changeset
|
248 return a:arg |
39a18a0df429
patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents:
20029
diff
changeset
|
249 endfunc |
39a18a0df429
patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents:
20029
diff
changeset
|
250 |
39a18a0df429
patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents:
20029
diff
changeset
|
251 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
|
252 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
|
253 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
|
254 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
|
255 enddef |
39a18a0df429
patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents:
20029
diff
changeset
|
256 |
39a18a0df429
patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents:
20029
diff
changeset
|
257 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
|
258 let NotAFunc = 'text' |
39a18a0df429
patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents:
20029
diff
changeset
|
259 |
19993
efe864a7ce4f
patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
19985
diff
changeset
|
260 def CombineFuncrefTypes() |
efe864a7ce4f
patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
19985
diff
changeset
|
261 " 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
|
262 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
|
263 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
|
264 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
|
265 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
|
266 |
efe864a7ce4f
patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
19985
diff
changeset
|
267 " 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
|
268 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
|
269 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
|
270 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
|
271 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
|
272 |
efe864a7ce4f
patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
19985
diff
changeset
|
273 " different argument types |
efe864a7ce4f
patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
19985
diff
changeset
|
274 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
|
275 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
|
276 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
|
277 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
|
278 enddef |
efe864a7ce4f
patch 8.2.0552: Vim9: some errors not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
19985
diff
changeset
|
279 |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
280 def FuncWithForwardCall() |
20140
39a18a0df429
patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents:
20029
diff
changeset
|
281 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
|
282 enddef |
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 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
|
285 return arg |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
286 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
287 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
288 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
|
289 " Error in called function requires unwinding the call stack. |
21160
1a393685e7ce
patch 8.2.1131: Vim9: error message for returning a value is not clear
Bram Moolenaar <Bram@vim.org>
parents:
21118
diff
changeset
|
290 assert_fails('call FuncWithForwardCall()', 'E1096') |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
291 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
292 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
293 def Test_return_type_wrong() |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
294 CheckScriptFailure(['def Func(): number', 'return "a"', 'enddef', 'defcompile'], 'expected number but got string') |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
295 CheckScriptFailure(['def Func(): string', 'return 1', 'enddef', 'defcompile'], 'expected string but got number') |
21160
1a393685e7ce
patch 8.2.1131: Vim9: error message for returning a value is not clear
Bram Moolenaar <Bram@vim.org>
parents:
21118
diff
changeset
|
296 CheckScriptFailure(['def Func(): void', 'return "a"', 'enddef', 'defcompile'], 'E1096: Returning a value in a function without a return type') |
1a393685e7ce
patch 8.2.1131: Vim9: error message for returning a value is not clear
Bram Moolenaar <Bram@vim.org>
parents:
21118
diff
changeset
|
297 CheckScriptFailure(['def Func()', 'return "a"', 'enddef', 'defcompile'], 'E1096: Returning a value in a function without a return type') |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
298 |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
299 CheckScriptFailure(['def Func(): number', 'return', 'enddef', 'defcompile'], 'E1003:') |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
300 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
301 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
|
302 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
|
303 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
|
304 enddef |
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 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
|
307 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
|
308 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
|
309 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
|
310 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
|
311 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
312 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
313 def Test_vim9script_call() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
314 let lines =<< trim END |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
315 vim9script |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
316 let var = '' |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
317 def MyFunc(arg: string) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
318 var = arg |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
319 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
320 MyFunc('foobar') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
321 assert_equal('foobar', var) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
322 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
323 let str = 'barfoo' |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
324 str->MyFunc() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
325 assert_equal('barfoo', var) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
326 |
20945
0653b9b72091
patch 8.2.1024: Vim9: no error for using "let g:var = val"
Bram Moolenaar <Bram@vim.org>
parents:
20909
diff
changeset
|
327 g:value = 'value' |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
328 g:value->MyFunc() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
329 assert_equal('value', var) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
330 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
331 let listvar = [] |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
332 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
|
333 listvar = arg |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
334 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
335 [1, 2, 3]->ListFunc() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
336 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
|
337 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
338 let dictvar = {} |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
339 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
|
340 dictvar = arg |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
341 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
342 {'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
|
343 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
|
344 def CompiledDict() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
345 {'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
|
346 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
347 CompiledDict() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
348 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
|
349 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
350 #{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
|
351 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
|
352 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
353 ('text')->MyFunc() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
354 assert_equal('text', var) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
355 ("some")->MyFunc() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
356 assert_equal('some', var) |
21118
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21089
diff
changeset
|
357 |
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21089
diff
changeset
|
358 MyFunc( |
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21089
diff
changeset
|
359 'continued' |
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21089
diff
changeset
|
360 ) |
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21089
diff
changeset
|
361 assert_equal('continued', |
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21089
diff
changeset
|
362 var |
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21089
diff
changeset
|
363 ) |
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21089
diff
changeset
|
364 |
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21089
diff
changeset
|
365 call MyFunc( |
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21089
diff
changeset
|
366 'more' |
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21089
diff
changeset
|
367 .. |
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21089
diff
changeset
|
368 'lines' |
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21089
diff
changeset
|
369 ) |
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21089
diff
changeset
|
370 assert_equal( |
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21089
diff
changeset
|
371 'morelines', |
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21089
diff
changeset
|
372 var) |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
373 END |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
374 writefile(lines, 'Xcall.vim') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
375 source Xcall.vim |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
376 delete('Xcall.vim') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
377 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
378 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
379 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
|
380 let lines =<< trim END |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
381 vim9script |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
382 let var = '' |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
383 def MyFunc(arg: string) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
384 let var = 123 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
385 enddef |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
386 defcompile |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
387 END |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
388 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
|
389 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
|
390 delete('Xcall_decl.vim') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
391 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
392 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
393 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
|
394 let lines =<< trim END |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
395 vim9script |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
396 const var = '' |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
397 def MyFunc(arg: string) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
398 var = 'asdf' |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
399 enddef |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
400 defcompile |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
401 END |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
402 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
|
403 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
|
404 delete('Xcall_const.vim') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
405 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
406 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
407 " 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
|
408 " recognized. |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
409 func Test_function_python() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
410 CheckFeature python3 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
411 let py = 'python3' |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
412 execute py "<< EOF" |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
413 def do_something(): |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
414 return 1 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
415 EOF |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
416 endfunc |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
417 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
418 def Test_delfunc() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
419 let lines =<< trim END |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
420 vim9script |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
421 def g:GoneSoon() |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
422 echo 'hello' |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
423 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
424 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
425 def CallGoneSoon() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
426 GoneSoon() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
427 enddef |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
428 defcompile |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
429 |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
430 delfunc g:GoneSoon |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
431 CallGoneSoon() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
432 END |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
433 writefile(lines, 'XToDelFunc') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
434 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
|
435 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
|
436 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
437 delete('XToDelFunc') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
438 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
439 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
440 def Test_redef_failure() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
441 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
|
442 so Xdef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
443 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
|
444 so Xdef |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
445 call writefile(['def! Func0(): string', 'enddef', 'defcompile'], 'Xdef') |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
446 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
|
447 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
|
448 so Xdef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
449 call delete('Xdef') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
450 |
20140
39a18a0df429
patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents:
20029
diff
changeset
|
451 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
|
452 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
|
453 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
|
454 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
455 delfunc! Func0 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
456 delfunc! Func1 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
457 delfunc! Func2 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
458 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
459 |
20142
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
460 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
|
461 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
|
462 vim9script |
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
463 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
|
464 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
|
465 endfunc |
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
466 Func('text') |
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
467 END |
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
468 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
|
469 so XVim9Func |
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
470 |
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
471 delete('XVim9Func') |
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
472 enddef |
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
473 |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
474 " 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
|
475 func Test_InternalFuncRetType() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
476 let lines =<< trim END |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
477 def RetFloat(): float |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
478 return ceil(1.456) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
479 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
480 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
481 def RetListAny(): list<any> |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
482 return items({'k' : 'v'}) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
483 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
484 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
485 def RetListString(): list<string> |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
486 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
|
487 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
488 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
489 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
|
490 return getbufinfo() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
491 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
492 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
493 def RetDictNumber(): dict<number> |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
494 return wordcount() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
495 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
496 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
497 def RetDictString(): dict<string> |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
498 return environ() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
499 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
500 END |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
501 call writefile(lines, 'Xscript') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
502 source Xscript |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
503 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
504 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
|
505 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
|
506 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
|
507 call assert_notequal([], RetListDictAny()) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
508 call assert_notequal({}, RetDictNumber()) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
509 call assert_notequal({}, RetDictString()) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
510 call delete('Xscript') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
511 endfunc |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
512 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
513 " 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
|
514 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
|
515 let l =<< trim END |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
516 def! FArgErr(): float |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
517 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
|
518 enddef |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
519 defcompile |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
520 END |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
521 call writefile(l, 'Xinvalidarg') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
522 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
|
523 let l =<< trim END |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
524 def! FArgErr(): float |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
525 return ceil() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
526 enddef |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
527 defcompile |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
528 END |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
529 call writefile(l, 'Xinvalidarg') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
530 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
|
531 call delete('Xinvalidarg') |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
532 endfunc |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
533 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
534 let s:funcResult = 0 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
535 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
536 def FuncNoArgNoRet() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
537 funcResult = 11 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
538 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
539 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
540 def FuncNoArgRetNumber(): number |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
541 funcResult = 22 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
542 return 1234 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
543 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
544 |
19942
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
545 def FuncNoArgRetString(): string |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
546 funcResult = 45 |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
547 return 'text' |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
548 enddef |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
549 |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
550 def FuncOneArgNoRet(arg: number) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
551 funcResult = arg |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
552 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
553 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
554 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
|
555 funcResult = arg |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
556 return arg |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
557 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
558 |
19985
f863aa96cae5
patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents:
19975
diff
changeset
|
559 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
|
560 funcResult = two |
f863aa96cae5
patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents:
19975
diff
changeset
|
561 enddef |
f863aa96cae5
patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents:
19975
diff
changeset
|
562 |
19942
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
563 def FuncOneArgRetString(arg: string): string |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
564 return arg |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
565 enddef |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
566 |
19926
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
567 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
|
568 return arg |
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
569 enddef |
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
570 |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
571 def Test_func_type() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
572 let Ref1: func() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
573 funcResult = 0 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
574 Ref1 = FuncNoArgNoRet |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
575 Ref1() |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
576 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
|
577 |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
578 let Ref2: func |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
579 funcResult = 0 |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
580 Ref2 = FuncNoArgNoRet |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
581 Ref2() |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
582 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
|
583 |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
584 funcResult = 0 |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
585 Ref2 = FuncOneArgNoRet |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
586 Ref2(12) |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
587 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
|
588 |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
589 funcResult = 0 |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
590 Ref2 = FuncNoArgRetNumber |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
591 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
|
592 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
|
593 |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
594 funcResult = 0 |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
595 Ref2 = FuncOneArgRetNumber |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
596 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
|
597 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
|
598 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
599 |
21162
3158cc2384cc
patch 8.2.1132: Vim9: return type of repeat() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents:
21160
diff
changeset
|
600 def Test_repeat_return_type() |
3158cc2384cc
patch 8.2.1132: Vim9: return type of repeat() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents:
21160
diff
changeset
|
601 let res = 0 |
3158cc2384cc
patch 8.2.1132: Vim9: return type of repeat() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents:
21160
diff
changeset
|
602 for n in repeat([1], 3) |
3158cc2384cc
patch 8.2.1132: Vim9: return type of repeat() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents:
21160
diff
changeset
|
603 res += n |
3158cc2384cc
patch 8.2.1132: Vim9: return type of repeat() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents:
21160
diff
changeset
|
604 endfor |
3158cc2384cc
patch 8.2.1132: Vim9: return type of repeat() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents:
21160
diff
changeset
|
605 assert_equal(3, res) |
21164
4a190861f0cc
patch 8.2.1133: Vim9: return type of add() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents:
21162
diff
changeset
|
606 |
4a190861f0cc
patch 8.2.1133: Vim9: return type of add() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents:
21162
diff
changeset
|
607 res = 0 |
4a190861f0cc
patch 8.2.1133: Vim9: return type of add() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents:
21162
diff
changeset
|
608 for n in add([1, 2], 3) |
4a190861f0cc
patch 8.2.1133: Vim9: return type of add() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents:
21162
diff
changeset
|
609 res += n |
4a190861f0cc
patch 8.2.1133: Vim9: return type of add() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents:
21162
diff
changeset
|
610 endfor |
4a190861f0cc
patch 8.2.1133: Vim9: return type of add() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents:
21162
diff
changeset
|
611 assert_equal(6, res) |
21162
3158cc2384cc
patch 8.2.1132: Vim9: return type of repeat() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents:
21160
diff
changeset
|
612 enddef |
3158cc2384cc
patch 8.2.1132: Vim9: return type of repeat() is not specific enough
Bram Moolenaar <Bram@vim.org>
parents:
21160
diff
changeset
|
613 |
21170
8c494353c6bc
patch 8.2.1136: Vim9: return type of argv() is always any
Bram Moolenaar <Bram@vim.org>
parents:
21164
diff
changeset
|
614 def Test_argv_return_type() |
8c494353c6bc
patch 8.2.1136: Vim9: return type of argv() is always any
Bram Moolenaar <Bram@vim.org>
parents:
21164
diff
changeset
|
615 next fileone filetwo |
8c494353c6bc
patch 8.2.1136: Vim9: return type of argv() is always any
Bram Moolenaar <Bram@vim.org>
parents:
21164
diff
changeset
|
616 let res = '' |
8c494353c6bc
patch 8.2.1136: Vim9: return type of argv() is always any
Bram Moolenaar <Bram@vim.org>
parents:
21164
diff
changeset
|
617 for name in argv() |
8c494353c6bc
patch 8.2.1136: Vim9: return type of argv() is always any
Bram Moolenaar <Bram@vim.org>
parents:
21164
diff
changeset
|
618 res ..= name |
8c494353c6bc
patch 8.2.1136: Vim9: return type of argv() is always any
Bram Moolenaar <Bram@vim.org>
parents:
21164
diff
changeset
|
619 endfor |
8c494353c6bc
patch 8.2.1136: Vim9: return type of argv() is always any
Bram Moolenaar <Bram@vim.org>
parents:
21164
diff
changeset
|
620 assert_equal('fileonefiletwo', res) |
8c494353c6bc
patch 8.2.1136: Vim9: return type of argv() is always any
Bram Moolenaar <Bram@vim.org>
parents:
21164
diff
changeset
|
621 enddef |
8c494353c6bc
patch 8.2.1136: Vim9: return type of argv() is always any
Bram Moolenaar <Bram@vim.org>
parents:
21164
diff
changeset
|
622 |
19942
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
623 def Test_func_type_part() |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
624 let RefVoid: func: void |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
625 RefVoid = FuncNoArgNoRet |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
626 RefVoid = FuncOneArgNoRet |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
627 CheckDefFailure(['let RefVoid: func: void', 'RefVoid = FuncNoArgRetNumber'], 'E1013: type mismatch, expected func() but got func(): number') |
20532
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
628 CheckDefFailure(['let RefVoid: func: void', 'RefVoid = FuncNoArgRetString'], 'E1013: type mismatch, expected func() but got func(): string') |
19942
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
629 |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
630 let RefAny: func(): any |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
631 RefAny = FuncNoArgRetNumber |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
632 RefAny = FuncNoArgRetString |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
633 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
|
634 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
|
635 |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
636 let RefNr: func: number |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
637 RefNr = FuncNoArgRetNumber |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
638 RefNr = FuncOneArgRetNumber |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
639 CheckDefFailure(['let RefNr: func: number', 'RefNr = FuncNoArgNoRet'], 'E1013: type mismatch, expected func(): number but got func()') |
20532
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
640 CheckDefFailure(['let RefNr: func: number', 'RefNr = FuncNoArgRetString'], 'E1013: type mismatch, expected func(): number but got func(): string') |
19942
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
641 |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
642 let RefStr: func: string |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
643 RefStr = FuncNoArgRetString |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
644 RefStr = FuncOneArgRetString |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
645 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
|
646 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
|
647 enddef |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19932
diff
changeset
|
648 |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
649 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
|
650 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
|
651 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
652 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
|
653 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
|
654 CheckDefFailure(['let Ref1: func()', 'Ref1 = FuncOneArgRetNumber'], 'E1013: type mismatch, expected func() but got func(number): number') |
20532
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
655 CheckDefFailure(['let Ref1: func(bool)', 'Ref1 = FuncTwoArgNoRet'], 'E1013: type mismatch, expected func(bool) but got func(bool, number)') |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
656 CheckDefFailure(['let Ref1: func(?bool)', 'Ref1 = FuncTwoArgNoRet'], 'E1013: type mismatch, expected func(?bool) but got func(bool, number)') |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
657 CheckDefFailure(['let Ref1: func(...bool)', 'Ref1 = FuncTwoArgNoRet'], 'E1013: type mismatch, expected func(...bool) but got func(bool, number)') |
19985
f863aa96cae5
patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents:
19975
diff
changeset
|
658 |
f863aa96cae5
patch 8.2.0548: Vim9: not all possible func type errors tested
Bram Moolenaar <Bram@vim.org>
parents:
19975
diff
changeset
|
659 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
|
660 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
|
661 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
|
662 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
|
663 enddef |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
664 |
19926
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
665 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
|
666 let nr: number |
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
667 nr = FuncNoArgRetNumber() |
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
668 assert_equal(1234, nr) |
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
669 |
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
670 nr = FuncOneArgRetAny(122) |
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
671 assert_equal(122, nr) |
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
672 |
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
673 let str: string |
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
674 str = FuncOneArgRetAny('yes') |
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
675 assert_equal('yes', str) |
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
676 |
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
677 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
|
678 enddef |
d286bfc44149
patch 8.2.0519: Vim9: return type not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
679 |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
680 def MultiLine( |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
681 arg1: string, |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
682 arg2 = 1234, |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
683 ...rest: list<string> |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
684 ): string |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
685 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
|
686 enddef |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
687 |
20023
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20017
diff
changeset
|
688 def MultiLineComment( |
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20017
diff
changeset
|
689 arg1: string, # comment |
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20017
diff
changeset
|
690 arg2 = 1234, # comment |
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20017
diff
changeset
|
691 ...rest: list<string> # comment |
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20017
diff
changeset
|
692 ): string # comment |
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20017
diff
changeset
|
693 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
|
694 enddef |
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20017
diff
changeset
|
695 |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
696 def Test_multiline() |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
697 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
|
698 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
|
699 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
|
700 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
|
701 enddef |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
702 |
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
|
703 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
|
704 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
|
705 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
|
706 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
|
707 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
|
708 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
|
709 |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
710 |
19932
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
711 " 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
|
712 " of E1056. |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
713 func Test_E1056_1059() |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
714 let caught_1056 = 0 |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
715 try |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
716 def F(): |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
717 return 1 |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
718 enddef |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
719 catch /E1056:/ |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
720 let caught_1056 = 1 |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
721 endtry |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
722 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
|
723 |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
724 let caught_1059 = 0 |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
725 try |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
726 def F5(items : list) |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
727 echo 'a' |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
728 enddef |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
729 catch /E1059:/ |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
730 let caught_1059 = 1 |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
731 endtry |
2c4d9ca33769
patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
732 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
|
733 endfunc |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
734 |
20287
ce1b73835822
patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents:
20281
diff
changeset
|
735 func DelMe() |
ce1b73835822
patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents:
20281
diff
changeset
|
736 echo 'DelMe' |
ce1b73835822
patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents:
20281
diff
changeset
|
737 endfunc |
ce1b73835822
patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents:
20281
diff
changeset
|
738 |
ce1b73835822
patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents:
20281
diff
changeset
|
739 def Test_deleted_function() |
ce1b73835822
patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents:
20281
diff
changeset
|
740 CheckDefExecFailure([ |
ce1b73835822
patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents:
20281
diff
changeset
|
741 'let RefMe: func = function("g:DelMe")', |
ce1b73835822
patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents:
20281
diff
changeset
|
742 'delfunc g:DelMe', |
ce1b73835822
patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents:
20281
diff
changeset
|
743 'echo RefMe()'], 'E117:') |
ce1b73835822
patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents:
20281
diff
changeset
|
744 enddef |
ce1b73835822
patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents:
20281
diff
changeset
|
745 |
ce1b73835822
patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents:
20281
diff
changeset
|
746 def Test_unknown_function() |
ce1b73835822
patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents:
20281
diff
changeset
|
747 CheckDefExecFailure([ |
ce1b73835822
patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents:
20281
diff
changeset
|
748 'let Ref: func = function("NotExist")', |
21265
6a4806e326dd
patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents:
21263
diff
changeset
|
749 'delfunc g:NotExist'], 'E700:') |
20287
ce1b73835822
patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents:
20281
diff
changeset
|
750 enddef |
ce1b73835822
patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents:
20281
diff
changeset
|
751 |
20244
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20189
diff
changeset
|
752 def RefFunc(Ref: func(string): string): string |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20189
diff
changeset
|
753 return Ref('more') |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20189
diff
changeset
|
754 enddef |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20189
diff
changeset
|
755 |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20189
diff
changeset
|
756 def Test_closure_simple() |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20189
diff
changeset
|
757 let local = 'some ' |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20189
diff
changeset
|
758 assert_equal('some more', RefFunc({s -> local .. s})) |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20189
diff
changeset
|
759 enddef |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20189
diff
changeset
|
760 |
20247
e46e72aaff74
patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20244
diff
changeset
|
761 def MakeRef() |
e46e72aaff74
patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20244
diff
changeset
|
762 let local = 'some ' |
e46e72aaff74
patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20244
diff
changeset
|
763 g:Ref = {s -> local .. s} |
e46e72aaff74
patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20244
diff
changeset
|
764 enddef |
e46e72aaff74
patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20244
diff
changeset
|
765 |
e46e72aaff74
patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20244
diff
changeset
|
766 def Test_closure_ref_after_return() |
e46e72aaff74
patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20244
diff
changeset
|
767 MakeRef() |
e46e72aaff74
patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20244
diff
changeset
|
768 assert_equal('some thing', g:Ref('thing')) |
e46e72aaff74
patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20244
diff
changeset
|
769 unlet g:Ref |
e46e72aaff74
patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20244
diff
changeset
|
770 enddef |
e46e72aaff74
patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20244
diff
changeset
|
771 |
20255
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
772 def MakeTwoRefs() |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
773 let local = ['some'] |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
774 g:Extend = {s -> local->add(s)} |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
775 g:Read = {-> local} |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
776 enddef |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
777 |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
778 def Test_closure_two_refs() |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
779 MakeTwoRefs() |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
780 assert_equal('some', join(g:Read(), ' ')) |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
781 g:Extend('more') |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
782 assert_equal('some more', join(g:Read(), ' ')) |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
783 g:Extend('even') |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
784 assert_equal('some more even', join(g:Read(), ' ')) |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
785 |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
786 unlet g:Extend |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
787 unlet g:Read |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
788 enddef |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
789 |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
790 def ReadRef(Ref: func(): list<string>): string |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
791 return join(Ref(), ' ') |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
792 enddef |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
793 |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
794 def ExtendRef(Ref: func(string), add: string) |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
795 Ref(add) |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
796 enddef |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
797 |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
798 def Test_closure_two_indirect_refs() |
20257
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20255
diff
changeset
|
799 MakeTwoRefs() |
20255
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
800 assert_equal('some', ReadRef(g:Read)) |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
801 ExtendRef(g:Extend, 'more') |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
802 assert_equal('some more', ReadRef(g:Read)) |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
803 ExtendRef(g:Extend, 'even') |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
804 assert_equal('some more even', ReadRef(g:Read)) |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
805 |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
806 unlet g:Extend |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
807 unlet g:Read |
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
808 enddef |
20247
e46e72aaff74
patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20244
diff
changeset
|
809 |
20275
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
810 def MakeArgRefs(theArg: string) |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
811 let local = 'loc_val' |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
812 g:UseArg = {s -> theArg .. '/' .. local .. '/' .. s} |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
813 enddef |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
814 |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
815 def MakeArgRefsVarargs(theArg: string, ...rest: list<string>) |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
816 let local = 'the_loc' |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
817 g:UseVararg = {s -> theArg .. '/' .. local .. '/' .. s .. '/' .. join(rest)} |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
818 enddef |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
819 |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
820 def Test_closure_using_argument() |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
821 MakeArgRefs('arg_val') |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
822 assert_equal('arg_val/loc_val/call_val', g:UseArg('call_val')) |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
823 |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
824 MakeArgRefsVarargs('arg_val', 'one', 'two') |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
825 assert_equal('arg_val/the_loc/call_val/one two', g:UseVararg('call_val')) |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
826 |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
827 unlet g:UseArg |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
828 unlet g:UseVararg |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
829 enddef |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
830 |
20295
bc2c9ea94ec1
patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents:
20287
diff
changeset
|
831 def MakeGetAndAppendRefs() |
bc2c9ea94ec1
patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents:
20287
diff
changeset
|
832 let local = 'a' |
bc2c9ea94ec1
patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents:
20287
diff
changeset
|
833 |
bc2c9ea94ec1
patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents:
20287
diff
changeset
|
834 def Append(arg: string) |
bc2c9ea94ec1
patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents:
20287
diff
changeset
|
835 local ..= arg |
bc2c9ea94ec1
patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents:
20287
diff
changeset
|
836 enddef |
bc2c9ea94ec1
patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents:
20287
diff
changeset
|
837 g:Append = Append |
bc2c9ea94ec1
patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents:
20287
diff
changeset
|
838 |
bc2c9ea94ec1
patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents:
20287
diff
changeset
|
839 def Get(): string |
bc2c9ea94ec1
patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents:
20287
diff
changeset
|
840 return local |
bc2c9ea94ec1
patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents:
20287
diff
changeset
|
841 enddef |
bc2c9ea94ec1
patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents:
20287
diff
changeset
|
842 g:Get = Get |
bc2c9ea94ec1
patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents:
20287
diff
changeset
|
843 enddef |
bc2c9ea94ec1
patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents:
20287
diff
changeset
|
844 |
bc2c9ea94ec1
patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents:
20287
diff
changeset
|
845 def Test_closure_append_get() |
bc2c9ea94ec1
patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents:
20287
diff
changeset
|
846 MakeGetAndAppendRefs() |
bc2c9ea94ec1
patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents:
20287
diff
changeset
|
847 assert_equal('a', g:Get()) |
bc2c9ea94ec1
patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents:
20287
diff
changeset
|
848 g:Append('-b') |
bc2c9ea94ec1
patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents:
20287
diff
changeset
|
849 assert_equal('a-b', g:Get()) |
bc2c9ea94ec1
patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents:
20287
diff
changeset
|
850 g:Append('-c') |
bc2c9ea94ec1
patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents:
20287
diff
changeset
|
851 assert_equal('a-b-c', g:Get()) |
bc2c9ea94ec1
patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents:
20287
diff
changeset
|
852 |
bc2c9ea94ec1
patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents:
20287
diff
changeset
|
853 unlet g:Append |
bc2c9ea94ec1
patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents:
20287
diff
changeset
|
854 unlet g:Get |
bc2c9ea94ec1
patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents:
20287
diff
changeset
|
855 enddef |
bc2c9ea94ec1
patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents:
20287
diff
changeset
|
856 |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
857 def Test_nested_closure() |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
858 let local = 'text' |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
859 def Closure(arg: string): string |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
860 return local .. arg |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
861 enddef |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
862 assert_equal('text!!!', Closure('!!!')) |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
863 enddef |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
864 |
20433
5950284a517f
patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents:
20355
diff
changeset
|
865 func GetResult(Ref) |
5950284a517f
patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents:
20355
diff
changeset
|
866 return a:Ref('some') |
5950284a517f
patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents:
20355
diff
changeset
|
867 endfunc |
5950284a517f
patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents:
20355
diff
changeset
|
868 |
5950284a517f
patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents:
20355
diff
changeset
|
869 def Test_call_closure_not_compiled() |
5950284a517f
patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents:
20355
diff
changeset
|
870 let text = 'text' |
5950284a517f
patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents:
20355
diff
changeset
|
871 g:Ref = {s -> s .. text} |
5950284a517f
patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents:
20355
diff
changeset
|
872 assert_equal('sometext', GetResult(g:Ref)) |
5950284a517f
patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents:
20355
diff
changeset
|
873 enddef |
5950284a517f
patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents:
20355
diff
changeset
|
874 |
20903
54ffae914876
patch 8.2.1003: Vim9: return type of sort() is too generic
Bram Moolenaar <Bram@vim.org>
parents:
20532
diff
changeset
|
875 def Test_sort_return_type() |
54ffae914876
patch 8.2.1003: Vim9: return type of sort() is too generic
Bram Moolenaar <Bram@vim.org>
parents:
20532
diff
changeset
|
876 let res: list<number> |
54ffae914876
patch 8.2.1003: Vim9: return type of sort() is too generic
Bram Moolenaar <Bram@vim.org>
parents:
20532
diff
changeset
|
877 res = [1, 2, 3]->sort() |
54ffae914876
patch 8.2.1003: Vim9: return type of sort() is too generic
Bram Moolenaar <Bram@vim.org>
parents:
20532
diff
changeset
|
878 enddef |
54ffae914876
patch 8.2.1003: Vim9: return type of sort() is too generic
Bram Moolenaar <Bram@vim.org>
parents:
20532
diff
changeset
|
879 |
21089
d69ead03ba93
patch 8.2.1096: Vim9: return type of getqflist() is wrong
Bram Moolenaar <Bram@vim.org>
parents:
20972
diff
changeset
|
880 def Test_getqflist_return_type() |
d69ead03ba93
patch 8.2.1096: Vim9: return type of getqflist() is wrong
Bram Moolenaar <Bram@vim.org>
parents:
20972
diff
changeset
|
881 let l = getqflist() |
d69ead03ba93
patch 8.2.1096: Vim9: return type of getqflist() is wrong
Bram Moolenaar <Bram@vim.org>
parents:
20972
diff
changeset
|
882 assert_equal([], l) |
d69ead03ba93
patch 8.2.1096: Vim9: return type of getqflist() is wrong
Bram Moolenaar <Bram@vim.org>
parents:
20972
diff
changeset
|
883 |
d69ead03ba93
patch 8.2.1096: Vim9: return type of getqflist() is wrong
Bram Moolenaar <Bram@vim.org>
parents:
20972
diff
changeset
|
884 let d = getqflist(#{items: 0}) |
d69ead03ba93
patch 8.2.1096: Vim9: return type of getqflist() is wrong
Bram Moolenaar <Bram@vim.org>
parents:
20972
diff
changeset
|
885 assert_equal(#{items: []}, d) |
d69ead03ba93
patch 8.2.1096: Vim9: return type of getqflist() is wrong
Bram Moolenaar <Bram@vim.org>
parents:
20972
diff
changeset
|
886 enddef |
d69ead03ba93
patch 8.2.1096: Vim9: return type of getqflist() is wrong
Bram Moolenaar <Bram@vim.org>
parents:
20972
diff
changeset
|
887 |
d69ead03ba93
patch 8.2.1096: Vim9: return type of getqflist() is wrong
Bram Moolenaar <Bram@vim.org>
parents:
20972
diff
changeset
|
888 def Test_getloclist_return_type() |
d69ead03ba93
patch 8.2.1096: Vim9: return type of getqflist() is wrong
Bram Moolenaar <Bram@vim.org>
parents:
20972
diff
changeset
|
889 let l = getloclist(1) |
d69ead03ba93
patch 8.2.1096: Vim9: return type of getqflist() is wrong
Bram Moolenaar <Bram@vim.org>
parents:
20972
diff
changeset
|
890 assert_equal([], l) |
d69ead03ba93
patch 8.2.1096: Vim9: return type of getqflist() is wrong
Bram Moolenaar <Bram@vim.org>
parents:
20972
diff
changeset
|
891 |
d69ead03ba93
patch 8.2.1096: Vim9: return type of getqflist() is wrong
Bram Moolenaar <Bram@vim.org>
parents:
20972
diff
changeset
|
892 let d = getloclist(1, #{items: 0}) |
d69ead03ba93
patch 8.2.1096: Vim9: return type of getqflist() is wrong
Bram Moolenaar <Bram@vim.org>
parents:
20972
diff
changeset
|
893 assert_equal(#{items: []}, d) |
d69ead03ba93
patch 8.2.1096: Vim9: return type of getqflist() is wrong
Bram Moolenaar <Bram@vim.org>
parents:
20972
diff
changeset
|
894 enddef |
d69ead03ba93
patch 8.2.1096: Vim9: return type of getqflist() is wrong
Bram Moolenaar <Bram@vim.org>
parents:
20972
diff
changeset
|
895 |
21174
95abb4b22905
patch 8.2.1138: Vim9: return type of copy() and deepcopy() is any
Bram Moolenaar <Bram@vim.org>
parents:
21172
diff
changeset
|
896 def Test_copy_return_type() |
95abb4b22905
patch 8.2.1138: Vim9: return type of copy() and deepcopy() is any
Bram Moolenaar <Bram@vim.org>
parents:
21172
diff
changeset
|
897 let l = copy([1, 2, 3]) |
95abb4b22905
patch 8.2.1138: Vim9: return type of copy() and deepcopy() is any
Bram Moolenaar <Bram@vim.org>
parents:
21172
diff
changeset
|
898 let res = 0 |
95abb4b22905
patch 8.2.1138: Vim9: return type of copy() and deepcopy() is any
Bram Moolenaar <Bram@vim.org>
parents:
21172
diff
changeset
|
899 for n in l |
95abb4b22905
patch 8.2.1138: Vim9: return type of copy() and deepcopy() is any
Bram Moolenaar <Bram@vim.org>
parents:
21172
diff
changeset
|
900 res += n |
95abb4b22905
patch 8.2.1138: Vim9: return type of copy() and deepcopy() is any
Bram Moolenaar <Bram@vim.org>
parents:
21172
diff
changeset
|
901 endfor |
95abb4b22905
patch 8.2.1138: Vim9: return type of copy() and deepcopy() is any
Bram Moolenaar <Bram@vim.org>
parents:
21172
diff
changeset
|
902 assert_equal(6, res) |
95abb4b22905
patch 8.2.1138: Vim9: return type of copy() and deepcopy() is any
Bram Moolenaar <Bram@vim.org>
parents:
21172
diff
changeset
|
903 |
95abb4b22905
patch 8.2.1138: Vim9: return type of copy() and deepcopy() is any
Bram Moolenaar <Bram@vim.org>
parents:
21172
diff
changeset
|
904 let dl = deepcopy([1, 2, 3]) |
95abb4b22905
patch 8.2.1138: Vim9: return type of copy() and deepcopy() is any
Bram Moolenaar <Bram@vim.org>
parents:
21172
diff
changeset
|
905 res = 0 |
95abb4b22905
patch 8.2.1138: Vim9: return type of copy() and deepcopy() is any
Bram Moolenaar <Bram@vim.org>
parents:
21172
diff
changeset
|
906 for n in dl |
95abb4b22905
patch 8.2.1138: Vim9: return type of copy() and deepcopy() is any
Bram Moolenaar <Bram@vim.org>
parents:
21172
diff
changeset
|
907 res += n |
95abb4b22905
patch 8.2.1138: Vim9: return type of copy() and deepcopy() is any
Bram Moolenaar <Bram@vim.org>
parents:
21172
diff
changeset
|
908 endfor |
95abb4b22905
patch 8.2.1138: Vim9: return type of copy() and deepcopy() is any
Bram Moolenaar <Bram@vim.org>
parents:
21172
diff
changeset
|
909 assert_equal(6, res) |
95abb4b22905
patch 8.2.1138: Vim9: return type of copy() and deepcopy() is any
Bram Moolenaar <Bram@vim.org>
parents:
21172
diff
changeset
|
910 enddef |
95abb4b22905
patch 8.2.1138: Vim9: return type of copy() and deepcopy() is any
Bram Moolenaar <Bram@vim.org>
parents:
21172
diff
changeset
|
911 |
21178
fab2085e417f
patch 8.2.1140: Vim9: return type of extend() is any
Bram Moolenaar <Bram@vim.org>
parents:
21176
diff
changeset
|
912 def Test_extend_return_type() |
fab2085e417f
patch 8.2.1140: Vim9: return type of extend() is any
Bram Moolenaar <Bram@vim.org>
parents:
21176
diff
changeset
|
913 let l = extend([1, 2], [3]) |
fab2085e417f
patch 8.2.1140: Vim9: return type of extend() is any
Bram Moolenaar <Bram@vim.org>
parents:
21176
diff
changeset
|
914 let res = 0 |
fab2085e417f
patch 8.2.1140: Vim9: return type of extend() is any
Bram Moolenaar <Bram@vim.org>
parents:
21176
diff
changeset
|
915 for n in l |
fab2085e417f
patch 8.2.1140: Vim9: return type of extend() is any
Bram Moolenaar <Bram@vim.org>
parents:
21176
diff
changeset
|
916 res += n |
fab2085e417f
patch 8.2.1140: Vim9: return type of extend() is any
Bram Moolenaar <Bram@vim.org>
parents:
21176
diff
changeset
|
917 endfor |
fab2085e417f
patch 8.2.1140: Vim9: return type of extend() is any
Bram Moolenaar <Bram@vim.org>
parents:
21176
diff
changeset
|
918 assert_equal(6, res) |
fab2085e417f
patch 8.2.1140: Vim9: return type of extend() is any
Bram Moolenaar <Bram@vim.org>
parents:
21176
diff
changeset
|
919 enddef |
fab2085e417f
patch 8.2.1140: Vim9: return type of extend() is any
Bram Moolenaar <Bram@vim.org>
parents:
21176
diff
changeset
|
920 |
21182
7289c8b9a620
patch 8.2.1142: Vim9: return type of insert() is any
Bram Moolenaar <Bram@vim.org>
parents:
21180
diff
changeset
|
921 def Test_insert_return_type() |
7289c8b9a620
patch 8.2.1142: Vim9: return type of insert() is any
Bram Moolenaar <Bram@vim.org>
parents:
21180
diff
changeset
|
922 let l = insert([2, 1], 3) |
7289c8b9a620
patch 8.2.1142: Vim9: return type of insert() is any
Bram Moolenaar <Bram@vim.org>
parents:
21180
diff
changeset
|
923 let res = 0 |
7289c8b9a620
patch 8.2.1142: Vim9: return type of insert() is any
Bram Moolenaar <Bram@vim.org>
parents:
21180
diff
changeset
|
924 for n in l |
7289c8b9a620
patch 8.2.1142: Vim9: return type of insert() is any
Bram Moolenaar <Bram@vim.org>
parents:
21180
diff
changeset
|
925 res += n |
7289c8b9a620
patch 8.2.1142: Vim9: return type of insert() is any
Bram Moolenaar <Bram@vim.org>
parents:
21180
diff
changeset
|
926 endfor |
7289c8b9a620
patch 8.2.1142: Vim9: return type of insert() is any
Bram Moolenaar <Bram@vim.org>
parents:
21180
diff
changeset
|
927 assert_equal(6, res) |
7289c8b9a620
patch 8.2.1142: Vim9: return type of insert() is any
Bram Moolenaar <Bram@vim.org>
parents:
21180
diff
changeset
|
928 enddef |
7289c8b9a620
patch 8.2.1142: Vim9: return type of insert() is any
Bram Moolenaar <Bram@vim.org>
parents:
21180
diff
changeset
|
929 |
21186
34667dc9207b
patch 8.2.1144: Vim9: return type of reverse() is any
Bram Moolenaar <Bram@vim.org>
parents:
21184
diff
changeset
|
930 def Test_reverse_return_type() |
34667dc9207b
patch 8.2.1144: Vim9: return type of reverse() is any
Bram Moolenaar <Bram@vim.org>
parents:
21184
diff
changeset
|
931 let l = reverse([1, 2, 3]) |
34667dc9207b
patch 8.2.1144: Vim9: return type of reverse() is any
Bram Moolenaar <Bram@vim.org>
parents:
21184
diff
changeset
|
932 let res = 0 |
34667dc9207b
patch 8.2.1144: Vim9: return type of reverse() is any
Bram Moolenaar <Bram@vim.org>
parents:
21184
diff
changeset
|
933 for n in l |
34667dc9207b
patch 8.2.1144: Vim9: return type of reverse() is any
Bram Moolenaar <Bram@vim.org>
parents:
21184
diff
changeset
|
934 res += n |
34667dc9207b
patch 8.2.1144: Vim9: return type of reverse() is any
Bram Moolenaar <Bram@vim.org>
parents:
21184
diff
changeset
|
935 endfor |
34667dc9207b
patch 8.2.1144: Vim9: return type of reverse() is any
Bram Moolenaar <Bram@vim.org>
parents:
21184
diff
changeset
|
936 assert_equal(6, res) |
34667dc9207b
patch 8.2.1144: Vim9: return type of reverse() is any
Bram Moolenaar <Bram@vim.org>
parents:
21184
diff
changeset
|
937 enddef |
34667dc9207b
patch 8.2.1144: Vim9: return type of reverse() is any
Bram Moolenaar <Bram@vim.org>
parents:
21184
diff
changeset
|
938 |
21184
2113e94dc726
patch 8.2.1143: Vim9: return type of remove() is any
Bram Moolenaar <Bram@vim.org>
parents:
21182
diff
changeset
|
939 def Test_remove_return_type() |
2113e94dc726
patch 8.2.1143: Vim9: return type of remove() is any
Bram Moolenaar <Bram@vim.org>
parents:
21182
diff
changeset
|
940 let l = remove(#{one: [1, 2], two: [3, 4]}, 'one') |
2113e94dc726
patch 8.2.1143: Vim9: return type of remove() is any
Bram Moolenaar <Bram@vim.org>
parents:
21182
diff
changeset
|
941 let res = 0 |
2113e94dc726
patch 8.2.1143: Vim9: return type of remove() is any
Bram Moolenaar <Bram@vim.org>
parents:
21182
diff
changeset
|
942 for n in l |
2113e94dc726
patch 8.2.1143: Vim9: return type of remove() is any
Bram Moolenaar <Bram@vim.org>
parents:
21182
diff
changeset
|
943 res += n |
2113e94dc726
patch 8.2.1143: Vim9: return type of remove() is any
Bram Moolenaar <Bram@vim.org>
parents:
21182
diff
changeset
|
944 endfor |
2113e94dc726
patch 8.2.1143: Vim9: return type of remove() is any
Bram Moolenaar <Bram@vim.org>
parents:
21182
diff
changeset
|
945 assert_equal(3, res) |
2113e94dc726
patch 8.2.1143: Vim9: return type of remove() is any
Bram Moolenaar <Bram@vim.org>
parents:
21182
diff
changeset
|
946 enddef |
2113e94dc726
patch 8.2.1143: Vim9: return type of remove() is any
Bram Moolenaar <Bram@vim.org>
parents:
21182
diff
changeset
|
947 |
21180
dde4c2e84f5c
patch 8.2.1141: Vim9: return type of filter() is any
Bram Moolenaar <Bram@vim.org>
parents:
21178
diff
changeset
|
948 def Test_filter_return_type() |
dde4c2e84f5c
patch 8.2.1141: Vim9: return type of filter() is any
Bram Moolenaar <Bram@vim.org>
parents:
21178
diff
changeset
|
949 let l = filter([1, 2, 3], {-> 1}) |
dde4c2e84f5c
patch 8.2.1141: Vim9: return type of filter() is any
Bram Moolenaar <Bram@vim.org>
parents:
21178
diff
changeset
|
950 let res = 0 |
dde4c2e84f5c
patch 8.2.1141: Vim9: return type of filter() is any
Bram Moolenaar <Bram@vim.org>
parents:
21178
diff
changeset
|
951 for n in l |
dde4c2e84f5c
patch 8.2.1141: Vim9: return type of filter() is any
Bram Moolenaar <Bram@vim.org>
parents:
21178
diff
changeset
|
952 res += n |
dde4c2e84f5c
patch 8.2.1141: Vim9: return type of filter() is any
Bram Moolenaar <Bram@vim.org>
parents:
21178
diff
changeset
|
953 endfor |
dde4c2e84f5c
patch 8.2.1141: Vim9: return type of filter() is any
Bram Moolenaar <Bram@vim.org>
parents:
21178
diff
changeset
|
954 assert_equal(6, res) |
dde4c2e84f5c
patch 8.2.1141: Vim9: return type of filter() is any
Bram Moolenaar <Bram@vim.org>
parents:
21178
diff
changeset
|
955 enddef |
dde4c2e84f5c
patch 8.2.1141: Vim9: return type of filter() is any
Bram Moolenaar <Bram@vim.org>
parents:
21178
diff
changeset
|
956 |
20972
d561e3c6cd65
patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
957 def Line_continuation_in_def(dir: string = ''): string |
d561e3c6cd65
patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
958 let path: string = empty(dir) |
d561e3c6cd65
patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
959 \ ? 'empty' |
d561e3c6cd65
patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
960 \ : 'full' |
d561e3c6cd65
patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
961 return path |
d561e3c6cd65
patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
962 enddef |
d561e3c6cd65
patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
963 |
d561e3c6cd65
patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
964 def Test_line_continuation_in_def() |
d561e3c6cd65
patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
965 assert_equal('full', Line_continuation_in_def('.')) |
d561e3c6cd65
patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
966 enddef |
d561e3c6cd65
patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
967 |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21186
diff
changeset
|
968 def Line_continuation_in_lambda(): list<number> |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21186
diff
changeset
|
969 let x = range(97, 100) |
21263
71bd2f9adb61
patch 8.2.1182: Vim9: no check for whitespace after comma in lambda
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
970 ->map({_, v -> nr2char(v) |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21186
diff
changeset
|
971 ->toupper()}) |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21186
diff
changeset
|
972 ->reverse() |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21186
diff
changeset
|
973 return x |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21186
diff
changeset
|
974 enddef |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21186
diff
changeset
|
975 |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21186
diff
changeset
|
976 def Test_line_continuation_in_lambda() |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21186
diff
changeset
|
977 assert_equal(['D', 'C', 'B', 'A'], Line_continuation_in_lambda()) |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21186
diff
changeset
|
978 enddef |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21186
diff
changeset
|
979 |
21176
54c665ad2db3
patch 8.2.1139: Vim9: test for silent echo fails in some environments
Bram Moolenaar <Bram@vim.org>
parents:
21174
diff
changeset
|
980 func Test_silent_echo() |
21172
96ae8622cfb6
patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents:
21170
diff
changeset
|
981 CheckScreendump |
96ae8622cfb6
patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents:
21170
diff
changeset
|
982 |
96ae8622cfb6
patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents:
21170
diff
changeset
|
983 let lines =<< trim END |
96ae8622cfb6
patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents:
21170
diff
changeset
|
984 vim9script |
96ae8622cfb6
patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents:
21170
diff
changeset
|
985 def EchoNothing() |
96ae8622cfb6
patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents:
21170
diff
changeset
|
986 silent echo '' |
96ae8622cfb6
patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents:
21170
diff
changeset
|
987 enddef |
96ae8622cfb6
patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents:
21170
diff
changeset
|
988 defcompile |
96ae8622cfb6
patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents:
21170
diff
changeset
|
989 END |
21176
54c665ad2db3
patch 8.2.1139: Vim9: test for silent echo fails in some environments
Bram Moolenaar <Bram@vim.org>
parents:
21174
diff
changeset
|
990 call writefile(lines, 'XTest_silent_echo') |
21172
96ae8622cfb6
patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents:
21170
diff
changeset
|
991 |
96ae8622cfb6
patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents:
21170
diff
changeset
|
992 " Check that the balloon shows up after a mouse move |
96ae8622cfb6
patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents:
21170
diff
changeset
|
993 let buf = RunVimInTerminal('-S XTest_silent_echo', {'rows': 6}) |
21176
54c665ad2db3
patch 8.2.1139: Vim9: test for silent echo fails in some environments
Bram Moolenaar <Bram@vim.org>
parents:
21174
diff
changeset
|
994 call term_sendkeys(buf, ":abc") |
21172
96ae8622cfb6
patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents:
21170
diff
changeset
|
995 call VerifyScreenDump(buf, 'Test_vim9_silent_echo', {}) |
96ae8622cfb6
patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents:
21170
diff
changeset
|
996 |
96ae8622cfb6
patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents:
21170
diff
changeset
|
997 " clean up |
96ae8622cfb6
patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents:
21170
diff
changeset
|
998 call StopVimInTerminal(buf) |
96ae8622cfb6
patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents:
21170
diff
changeset
|
999 call delete('XTest_silent_echo') |
21176
54c665ad2db3
patch 8.2.1139: Vim9: test for silent echo fails in some environments
Bram Moolenaar <Bram@vim.org>
parents:
21174
diff
changeset
|
1000 endfunc |
21172
96ae8622cfb6
patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents:
21170
diff
changeset
|
1001 |
21281
13b1567ae0c6
patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
1002 def Fibonacci(n: number): number |
13b1567ae0c6
patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
1003 if n < 2 |
13b1567ae0c6
patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
1004 return n |
13b1567ae0c6
patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
1005 else |
13b1567ae0c6
patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
1006 return Fibonacci(n - 1) + Fibonacci(n - 2) |
13b1567ae0c6
patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
1007 endif |
13b1567ae0c6
patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
1008 enddef |
13b1567ae0c6
patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
1009 |
13b1567ae0c6
patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
1010 def Test_recursive_call() |
13b1567ae0c6
patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
1011 assert_equal(6765, Fibonacci(20)) |
13b1567ae0c6
patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
1012 enddef |
13b1567ae0c6
patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
1013 |
20257
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20255
diff
changeset
|
1014 |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1015 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker |