Mercurial > vim
comparison src/testdir/test_vim9_script.vim @ 19860:37c4779ca8f5 v8.2.0486
patch 8.2.0486: Vim9: some code and error messages not tested
Commit: https://github.com/vim/vim/commit/9be61bbb170ed3df0e408c8ac12516e772dc0b75
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Mar 30 22:51:24 2020 +0200
patch 8.2.0486: Vim9: some code and error messages not tested
Problem: Vim9: some code and error messages not tested.
Solution: Add more tests.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 30 Mar 2020 23:00:05 +0200 |
parents | fc3cdc819d80 |
children | 846fbbacce3a |
comparison
equal
deleted
inserted
replaced
19859:904b25746b64 | 19860:37c4779ca8f5 |
---|---|
50 let dict1: dict<bool> = #{one: false, two: true} | 50 let dict1: dict<bool> = #{one: false, two: true} |
51 let dict2: dict<number> = #{one: 1, two: 2} | 51 let dict2: dict<number> = #{one: 1, two: 2} |
52 let dict3: dict<string> = #{key: 'value'} | 52 let dict3: dict<string> = #{key: 'value'} |
53 let dict4: dict<any> = #{one: 1, two: '2'} | 53 let dict4: dict<any> = #{one: 1, two: '2'} |
54 let dict5: dict<blob> = #{one: 0z01, tw: 0z02} | 54 let dict5: dict<blob> = #{one: 0z01, tw: 0z02} |
55 | |
56 let a: number = 6 | |
57 assert_equal(6, a) | |
55 | 58 |
56 if has('channel') | 59 if has('channel') |
57 let chan1: channel | 60 let chan1: channel |
58 let job1: job | 61 let job1: job |
59 let job2: job = job_start('willfail') | 62 let job2: job = job_start('willfail') |
98 call CheckDefFailure(['let var =234'], 'E1004:') | 101 call CheckDefFailure(['let var =234'], 'E1004:') |
99 call CheckDefFailure(['let var= 234'], 'E1004:') | 102 call CheckDefFailure(['let var= 234'], 'E1004:') |
100 | 103 |
101 call CheckDefFailure(['let true = 1'], 'E1034:') | 104 call CheckDefFailure(['let true = 1'], 'E1034:') |
102 call CheckDefFailure(['let false = 1'], 'E1034:') | 105 call CheckDefFailure(['let false = 1'], 'E1034:') |
106 | |
107 call CheckDefFailure(['let [a; b; c] = g:list'], 'E452:') | |
108 | |
109 call CheckDefFailure(['let &option'], 'E1052:') | |
110 call CheckDefFailure(['&g:option = 5'], 'E113:') | |
111 | |
112 call CheckDefFailure(['let $VAR = 5'], 'E1065:') | |
113 | |
114 call CheckDefFailure(['let @~ = 5'], 'E354:') | |
115 call CheckDefFailure(['let @a = 5'], 'E1066:') | |
116 | |
117 call CheckDefFailure(['let g:var = 5'], 'E1016:') | |
118 | |
119 call CheckDefFailure(['let anr = 4', 'anr ..= "text"'], 'E1019:') | |
120 call CheckDefFailure(['let xnr += 4'], 'E1020:') | |
103 | 121 |
104 call CheckScriptFailure(['vim9script', 'def Func()', 'let dummy = s:notfound', 'enddef'], 'E1050:') | 122 call CheckScriptFailure(['vim9script', 'def Func()', 'let dummy = s:notfound', 'enddef'], 'E1050:') |
105 | 123 |
106 call CheckDefFailure(['let var: list<string> = [123]'], 'expected list<string> but got list<number>') | 124 call CheckDefFailure(['let var: list<string> = [123]'], 'expected list<string> but got list<number>') |
107 call CheckDefFailure(['let var: list<number> = ["xx"]'], 'expected list<number> but got list<string>') | 125 call CheckDefFailure(['let var: list<number> = ["xx"]'], 'expected list<number> but got list<string>') |
140 | 158 |
141 func Test_const() | 159 func Test_const() |
142 call CheckDefFailure(['const var = 234', 'var = 99'], 'E1018:') | 160 call CheckDefFailure(['const var = 234', 'var = 99'], 'E1018:') |
143 call CheckDefFailure(['const one = 234', 'let one = 99'], 'E1017:') | 161 call CheckDefFailure(['const one = 234', 'let one = 99'], 'E1017:') |
144 call CheckDefFailure(['const two'], 'E1021:') | 162 call CheckDefFailure(['const two'], 'E1021:') |
163 call CheckDefFailure(['const &option'], 'E996:') | |
145 endfunc | 164 endfunc |
146 | 165 |
147 def Test_block() | 166 def Test_block() |
148 let outer = 1 | 167 let outer = 1 |
149 { | 168 { |
170 | 189 |
171 def ReturnGlobal(): number | 190 def ReturnGlobal(): number |
172 return g:notNumber | 191 return g:notNumber |
173 enddef | 192 enddef |
174 | 193 |
175 def Test_return_string() | 194 def Test_return_something() |
176 assert_equal('string', ReturnString()) | 195 assert_equal('string', ReturnString()) |
177 assert_equal(123, ReturnNumber()) | 196 assert_equal(123, ReturnNumber()) |
178 assert_fails('call ReturnGlobal()', 'E1029: Expected number but got string') | 197 assert_fails('call ReturnGlobal()', 'E1029: Expected number but got string') |
198 enddef | |
199 | |
200 let s:nothing = 0 | |
201 def ReturnNothing() | |
202 s:nothing = 1 | |
203 if true | |
204 return | |
205 endif | |
206 s:nothing = 2 | |
207 enddef | |
208 | |
209 def Test_return_nothing() | |
210 ReturnNothing() | |
211 assert_equal(1, s:nothing) | |
179 enddef | 212 enddef |
180 | 213 |
181 func Increment() | 214 func Increment() |
182 let g:counter += 1 | 215 let g:counter += 1 |
183 endfunc | 216 endfunc |
279 def Test_return_type_wrong() | 312 def Test_return_type_wrong() |
280 CheckScriptFailure(['def Func(): number', 'return "a"', 'enddef'], 'expected number but got string') | 313 CheckScriptFailure(['def Func(): number', 'return "a"', 'enddef'], 'expected number but got string') |
281 CheckScriptFailure(['def Func(): string', 'return 1', 'enddef'], 'expected string but got number') | 314 CheckScriptFailure(['def Func(): string', 'return 1', 'enddef'], 'expected string but got number') |
282 CheckScriptFailure(['def Func(): void', 'return "a"', 'enddef'], 'expected void but got string') | 315 CheckScriptFailure(['def Func(): void', 'return "a"', 'enddef'], 'expected void but got string') |
283 CheckScriptFailure(['def Func()', 'return "a"', 'enddef'], 'expected void but got string') | 316 CheckScriptFailure(['def Func()', 'return "a"', 'enddef'], 'expected void but got string') |
317 | |
318 CheckScriptFailure(['def Func(): number', 'return', 'enddef'], 'E1003:') | |
284 | 319 |
285 CheckScriptFailure(['def Func(): list', 'return []', 'enddef'], 'E1008:') | 320 CheckScriptFailure(['def Func(): list', 'return []', 'enddef'], 'E1008:') |
286 CheckScriptFailure(['def Func(): dict', 'return {}', 'enddef'], 'E1008:') | 321 CheckScriptFailure(['def Func(): dict', 'return {}', 'enddef'], 'E1008:') |
287 enddef | 322 enddef |
288 | 323 |