Mercurial > vim
comparison src/testdir/test_vim9_disassemble.vim @ 20019:e9af5a09a55b v8.2.0565
patch 8.2.0565: Vim9: tests contain superfluous line continuation
Commit: https://github.com/vim/vim/commit/675f716efb534798a3bdb651cdb272302127602a
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Apr 12 22:53:54 2020 +0200
patch 8.2.0565: Vim9: tests contain superfluous line continuation
Problem: Vim9: tests contain superfluous line continuation.
Solution: Remove line continuation no longer needed. Skip empty lines.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 12 Apr 2020 23:00:03 +0200 |
parents | d4fa9db88d16 |
children | 8fb1cf4c44d5 |
comparison
equal
deleted
inserted
replaced
20018:33b501a289fc | 20019:e9af5a09a55b |
---|---|
29 assert_fails('disass [', 'E475:') | 29 assert_fails('disass [', 'E475:') |
30 assert_fails('disass 234', 'E475:') | 30 assert_fails('disass 234', 'E475:') |
31 assert_fails('disass <XX>foo', 'E475:') | 31 assert_fails('disass <XX>foo', 'E475:') |
32 | 32 |
33 let res = execute('disass s:ScriptFuncLoad') | 33 let res = execute('disass s:ScriptFuncLoad') |
34 assert_match('<SNR>\d*_ScriptFuncLoad.*' | 34 assert_match('<SNR>\d*_ScriptFuncLoad.*' .. |
35 \ .. 'buffers.*' | 35 'buffers.*' .. |
36 \ .. ' EXEC \+buffers.*' | 36 ' EXEC \+buffers.*' .. |
37 \ .. ' LOAD arg\[-1\].*' | 37 ' LOAD arg\[-1\].*' .. |
38 \ .. ' LOAD $0.*' | 38 ' LOAD $0.*' .. |
39 \ .. ' LOADV v:version.*' | 39 ' LOADV v:version.*' .. |
40 \ .. ' LOADS s:scriptvar from .*test_vim9_disassemble.vim.*' | 40 ' LOADS s:scriptvar from .*test_vim9_disassemble.vim.*' .. |
41 \ .. ' LOADG g:globalvar.*' | 41 ' LOADG g:globalvar.*' .. |
42 \ .. ' LOADENV $ENVVAR.*' | 42 ' LOADENV $ENVVAR.*' .. |
43 \ .. ' LOADREG @z.*' | 43 ' LOADREG @z.*', |
44 \, res) | 44 res) |
45 enddef | 45 enddef |
46 | 46 |
47 def s:ScriptFuncPush() | 47 def s:ScriptFuncPush() |
48 let localbool = true | 48 let localbool = true |
49 let localspec = v:none | 49 let localspec = v:none |
53 endif | 53 endif |
54 enddef | 54 enddef |
55 | 55 |
56 def Test_disassemble_push() | 56 def Test_disassemble_push() |
57 let res = execute('disass s:ScriptFuncPush') | 57 let res = execute('disass s:ScriptFuncPush') |
58 assert_match('<SNR>\d*_ScriptFuncPush.*' | 58 assert_match('<SNR>\d*_ScriptFuncPush.*' .. |
59 \ .. 'localbool = true.*' | 59 'localbool = true.*' .. |
60 \ .. ' PUSH v:true.*' | 60 ' PUSH v:true.*' .. |
61 \ .. 'localspec = v:none.*' | 61 'localspec = v:none.*' .. |
62 \ .. ' PUSH v:none.*' | 62 ' PUSH v:none.*' .. |
63 \ .. 'localblob = 0z1234.*' | 63 'localblob = 0z1234.*' .. |
64 \ .. ' PUSHBLOB 0z1234.*' | 64 ' PUSHBLOB 0z1234.*', |
65 \, res) | 65 res) |
66 if has('float') | 66 if has('float') |
67 assert_match('<SNR>\d*_ScriptFuncPush.*' | 67 assert_match('<SNR>\d*_ScriptFuncPush.*' .. |
68 \ .. 'localfloat = 1.234.*' | 68 'localfloat = 1.234.*' .. |
69 \ .. ' PUSHF 1.234.*' | 69 ' PUSHF 1.234.*', |
70 \, res) | 70 res) |
71 endif | 71 endif |
72 enddef | 72 enddef |
73 | 73 |
74 def s:ScriptFuncStore() | 74 def s:ScriptFuncStore() |
75 let localnr = 1 | 75 let localnr = 1 |
84 @z = 'rv' | 84 @z = 'rv' |
85 enddef | 85 enddef |
86 | 86 |
87 def Test_disassemble_store() | 87 def Test_disassemble_store() |
88 let res = execute('disass s:ScriptFuncStore') | 88 let res = execute('disass s:ScriptFuncStore') |
89 assert_match('<SNR>\d*_ScriptFuncStore.*' | 89 assert_match('<SNR>\d*_ScriptFuncStore.*' .. |
90 \ .. 'let localnr = 1.*' | 90 'let localnr = 1.*' .. |
91 \ .. 'localnr = 2.*' | 91 'localnr = 2.*' .. |
92 \ .. ' STORE 2 in $0.*' | 92 ' STORE 2 in $0.*' .. |
93 \ .. 'let localstr = ''abc''.*' | 93 'let localstr = ''abc''.*' .. |
94 \ .. 'localstr = ''xyz''.*' | 94 'localstr = ''xyz''.*' .. |
95 \ .. ' STORE $1.*' | 95 ' STORE $1.*' .. |
96 \ .. 'v:char = ''abc''.*' | 96 'v:char = ''abc''.*' .. |
97 \ .. 'STOREV v:char.*' | 97 'STOREV v:char.*' .. |
98 \ .. 's:scriptvar = ''sv''.*' | 98 's:scriptvar = ''sv''.*' .. |
99 \ .. ' STORES s:scriptvar in .*test_vim9_disassemble.vim.*' | 99 ' STORES s:scriptvar in .*test_vim9_disassemble.vim.*' .. |
100 \ .. 'g:globalvar = ''gv''.*' | 100 'g:globalvar = ''gv''.*' .. |
101 \ .. ' STOREG g:globalvar.*' | 101 ' STOREG g:globalvar.*' .. |
102 \ .. '&tabstop = 8.*' | 102 '&tabstop = 8.*' .. |
103 \ .. ' STOREOPT &tabstop.*' | 103 ' STOREOPT &tabstop.*' .. |
104 \ .. '$ENVVAR = ''ev''.*' | 104 '$ENVVAR = ''ev''.*' .. |
105 \ .. ' STOREENV $ENVVAR.*' | 105 ' STOREENV $ENVVAR.*' .. |
106 \ .. '@z = ''rv''.*' | 106 '@z = ''rv''.*' .. |
107 \ .. ' STOREREG @z.*' | 107 ' STOREREG @z.*', |
108 \, res) | 108 res) |
109 enddef | 109 enddef |
110 | 110 |
111 def s:ScriptFuncTry() | 111 def s:ScriptFuncTry() |
112 try | 112 try |
113 echo 'yes' | 113 echo 'yes' |
118 endtry | 118 endtry |
119 enddef | 119 enddef |
120 | 120 |
121 def Test_disassemble_try() | 121 def Test_disassemble_try() |
122 let res = execute('disass s:ScriptFuncTry') | 122 let res = execute('disass s:ScriptFuncTry') |
123 assert_match('<SNR>\d*_ScriptFuncTry.*' | 123 assert_match('<SNR>\d*_ScriptFuncTry.*' .. |
124 \ .. 'try.*' | 124 'try.*' .. |
125 \ .. 'TRY catch -> \d\+, finally -> \d\+.*' | 125 'TRY catch -> \d\+, finally -> \d\+.*' .. |
126 \ .. 'catch /fail/.*' | 126 'catch /fail/.*' .. |
127 \ .. ' JUMP -> \d\+.*' | 127 ' JUMP -> \d\+.*' .. |
128 \ .. ' PUSH v:exception.*' | 128 ' PUSH v:exception.*' .. |
129 \ .. ' PUSHS "fail".*' | 129 ' PUSHS "fail".*' .. |
130 \ .. ' COMPARESTRING =\~.*' | 130 ' COMPARESTRING =\~.*' .. |
131 \ .. ' JUMP_IF_FALSE -> \d\+.*' | 131 ' JUMP_IF_FALSE -> \d\+.*' .. |
132 \ .. ' CATCH.*' | 132 ' CATCH.*' .. |
133 \ .. 'finally.*' | 133 'finally.*' .. |
134 \ .. ' PUSHS "end".*' | 134 ' PUSHS "end".*' .. |
135 \ .. ' THROW.*' | 135 ' THROW.*' .. |
136 \ .. 'endtry.*' | 136 'endtry.*' .. |
137 \ .. ' ENDTRY.*' | 137 ' ENDTRY.*', |
138 \, res) | 138 res) |
139 enddef | 139 enddef |
140 | 140 |
141 def s:ScriptFuncNew() | 141 def s:ScriptFuncNew() |
142 let ll = [1, "two", 333] | 142 let ll = [1, "two", 333] |
143 let dd = #{one: 1, two: "val"} | 143 let dd = #{one: 1, two: "val"} |
144 enddef | 144 enddef |
145 | 145 |
146 def Test_disassemble_new() | 146 def Test_disassemble_new() |
147 let res = execute('disass s:ScriptFuncNew') | 147 let res = execute('disass s:ScriptFuncNew') |
148 assert_match('<SNR>\d*_ScriptFuncNew.*' | 148 assert_match('<SNR>\d*_ScriptFuncNew.*' .. |
149 \ .. 'let ll = \[1, "two", 333].*' | 149 'let ll = \[1, "two", 333].*' .. |
150 \ .. 'PUSHNR 1.*' | 150 'PUSHNR 1.*' .. |
151 \ .. 'PUSHS "two".*' | 151 'PUSHS "two".*' .. |
152 \ .. 'PUSHNR 333.*' | 152 'PUSHNR 333.*' .. |
153 \ .. 'NEWLIST size 3.*' | 153 'NEWLIST size 3.*' .. |
154 \ .. 'let dd = #{one: 1, two: "val"}.*' | 154 'let dd = #{one: 1, two: "val"}.*' .. |
155 \ .. 'PUSHS "one".*' | 155 'PUSHS "one".*' .. |
156 \ .. 'PUSHNR 1.*' | 156 'PUSHNR 1.*' .. |
157 \ .. 'PUSHS "two".*' | 157 'PUSHS "two".*' .. |
158 \ .. 'PUSHS "val".*' | 158 'PUSHS "val".*' .. |
159 \ .. 'NEWDICT size 2.*' | 159 'NEWDICT size 2.*', |
160 \, res) | 160 res) |
161 enddef | 161 enddef |
162 | 162 |
163 def FuncWithArg(arg) | 163 def FuncWithArg(arg) |
164 echo arg | 164 echo arg |
165 enddef | 165 enddef |
188 return "yes" | 188 return "yes" |
189 enddef | 189 enddef |
190 | 190 |
191 def Test_disassemble_call() | 191 def Test_disassemble_call() |
192 let res = execute('disass s:ScriptFuncCall') | 192 let res = execute('disass s:ScriptFuncCall') |
193 assert_match('<SNR>\d\+_ScriptFuncCall.*' | 193 assert_match('<SNR>\d\+_ScriptFuncCall.*' .. |
194 \ .. 'changenr().*' | 194 'changenr().*' .. |
195 \ .. ' BCALL changenr(argc 0).*' | 195 ' BCALL changenr(argc 0).*' .. |
196 \ .. 'char2nr("abc").*' | 196 'char2nr("abc").*' .. |
197 \ .. ' PUSHS "abc".*' | 197 ' PUSHS "abc".*' .. |
198 \ .. ' BCALL char2nr(argc 1).*' | 198 ' BCALL char2nr(argc 1).*' .. |
199 \ .. 'Test_disassemble_new().*' | 199 'Test_disassemble_new().*' .. |
200 \ .. ' DCALL Test_disassemble_new(argc 0).*' | 200 ' DCALL Test_disassemble_new(argc 0).*' .. |
201 \ .. 'FuncWithArg(343).*' | 201 'FuncWithArg(343).*' .. |
202 \ .. ' PUSHNR 343.*' | 202 ' PUSHNR 343.*' .. |
203 \ .. ' DCALL FuncWithArg(argc 1).*' | 203 ' DCALL FuncWithArg(argc 1).*' .. |
204 \ .. 'ScriptFuncNew().*' | 204 'ScriptFuncNew().*' .. |
205 \ .. ' DCALL <SNR>\d\+_ScriptFuncNew(argc 0).*' | 205 ' DCALL <SNR>\d\+_ScriptFuncNew(argc 0).*' .. |
206 \ .. 's:ScriptFuncNew().*' | 206 's:ScriptFuncNew().*' .. |
207 \ .. ' DCALL <SNR>\d\+_ScriptFuncNew(argc 0).*' | 207 ' DCALL <SNR>\d\+_ScriptFuncNew(argc 0).*' .. |
208 \ .. 'UserFunc().*' | 208 'UserFunc().*' .. |
209 \ .. ' UCALL UserFunc(argc 0).*' | 209 ' UCALL UserFunc(argc 0).*' .. |
210 \ .. 'UserFuncWithArg("foo").*' | 210 'UserFuncWithArg("foo").*' .. |
211 \ .. ' PUSHS "foo".*' | 211 ' PUSHS "foo".*' .. |
212 \ .. ' UCALL UserFuncWithArg(argc 1).*' | 212 ' UCALL UserFuncWithArg(argc 1).*' .. |
213 \ .. 'let FuncRef = function("UserFunc").*' | 213 'let FuncRef = function("UserFunc").*' .. |
214 \ .. 'FuncRef().*' | 214 'FuncRef().*' .. |
215 \ .. ' LOAD $\d.*' | 215 ' LOAD $\d.*' .. |
216 \ .. ' PCALL (argc 0).*' | 216 ' PCALL (argc 0).*' .. |
217 \ .. 'let FuncRefWithArg = function("UserFuncWithArg").*' | 217 'let FuncRefWithArg = function("UserFuncWithArg").*' .. |
218 \ .. 'FuncRefWithArg("bar").*' | 218 'FuncRefWithArg("bar").*' .. |
219 \ .. ' PUSHS "bar".*' | 219 ' PUSHS "bar".*' .. |
220 \ .. ' LOAD $\d.*' | 220 ' LOAD $\d.*' .. |
221 \ .. ' PCALL (argc 1).*' | 221 ' PCALL (argc 1).*' .. |
222 \ .. 'return "yes".*' | 222 'return "yes".*' .. |
223 \ .. ' PUSHS "yes".*' | 223 ' PUSHS "yes".*' .. |
224 \ .. ' RETURN.*' | 224 ' RETURN.*', |
225 \, res) | 225 res) |
226 enddef | 226 enddef |
227 | 227 |
228 | 228 |
229 def EchoArg(arg: string): string | 229 def EchoArg(arg: string): string |
230 return arg | 230 return arg |
236 RefThis()("text") | 236 RefThis()("text") |
237 enddef | 237 enddef |
238 | 238 |
239 def Test_disassemble_pcall() | 239 def Test_disassemble_pcall() |
240 let res = execute('disass s:ScriptPCall') | 240 let res = execute('disass s:ScriptPCall') |
241 assert_match('<SNR>\d\+_ScriptPCall.*' | 241 assert_match('<SNR>\d\+_ScriptPCall.*' .. |
242 \ .. 'RefThis()("text").*' | 242 'RefThis()("text").*' .. |
243 \ .. '\d DCALL RefThis(argc 0).*' | 243 '\d DCALL RefThis(argc 0).*' .. |
244 \ .. '\d PUSHS "text".*' | 244 '\d PUSHS "text".*' .. |
245 \ .. '\d PCALL top (argc 1).*' | 245 '\d PCALL top (argc 1).*' .. |
246 \ .. '\d PCALL end.*' | 246 '\d PCALL end.*' .. |
247 \ .. '\d DROP.*' | 247 '\d DROP.*' .. |
248 \ .. '\d PUSHNR 0.*' | 248 '\d PUSHNR 0.*' .. |
249 \ .. '\d RETURN.*' | 249 '\d RETURN.*', |
250 \, res) | 250 res) |
251 enddef | 251 enddef |
252 | 252 |
253 | 253 |
254 def FuncWithForwardCall(): string | 254 def FuncWithForwardCall(): string |
255 return DefinedLater("yes") | 255 return DefinedLater("yes") |
259 return arg | 259 return arg |
260 enddef | 260 enddef |
261 | 261 |
262 def Test_disassemble_update_instr() | 262 def Test_disassemble_update_instr() |
263 let res = execute('disass FuncWithForwardCall') | 263 let res = execute('disass FuncWithForwardCall') |
264 assert_match('FuncWithForwardCall.*' | 264 assert_match('FuncWithForwardCall.*' .. |
265 \ .. 'return DefinedLater("yes").*' | 265 'return DefinedLater("yes").*' .. |
266 \ .. '\d PUSHS "yes".*' | 266 '\d PUSHS "yes".*' .. |
267 \ .. '\d UCALL DefinedLater(argc 1).*' | 267 '\d UCALL DefinedLater(argc 1).*' .. |
268 \ .. '\d CHECKTYPE string stack\[-1].*' | 268 '\d CHECKTYPE string stack\[-1].*' .. |
269 \ .. '\d RETURN.*' | 269 '\d RETURN.*', |
270 \, res) | 270 res) |
271 | 271 |
272 " Calling the function will change UCALL into the faster DCALL | 272 " Calling the function will change UCALL into the faster DCALL |
273 assert_equal('yes', FuncWithForwardCall()) | 273 assert_equal('yes', FuncWithForwardCall()) |
274 | 274 |
275 res = execute('disass FuncWithForwardCall') | 275 res = execute('disass FuncWithForwardCall') |
276 assert_match('FuncWithForwardCall.*' | 276 assert_match('FuncWithForwardCall.*' .. |
277 \ .. 'return DefinedLater("yes").*' | 277 'return DefinedLater("yes").*' .. |
278 \ .. '\d PUSHS "yes".*' | 278 '\d PUSHS "yes".*' .. |
279 \ .. '\d DCALL DefinedLater(argc 1).*' | 279 '\d DCALL DefinedLater(argc 1).*' .. |
280 \ .. '\d CHECKTYPE string stack\[-1].*' | 280 '\d CHECKTYPE string stack\[-1].*' .. |
281 \ .. '\d RETURN.*' | 281 '\d RETURN.*', |
282 \, res) | 282 res) |
283 enddef | 283 enddef |
284 | 284 |
285 | 285 |
286 def FuncWithDefault(arg: string = 'default'): string | 286 def FuncWithDefault(arg: string = 'default'): string |
287 return arg | 287 return arg |
288 enddef | 288 enddef |
289 | 289 |
290 def Test_disassemble_call_default() | 290 def Test_disassemble_call_default() |
291 let res = execute('disass FuncWithDefault') | 291 let res = execute('disass FuncWithDefault') |
292 assert_match('FuncWithDefault.*' | 292 assert_match('FuncWithDefault.*' .. |
293 \ .. '\d PUSHS "default".*' | 293 '\d PUSHS "default".*' .. |
294 \ .. '\d STORE arg\[-1].*' | 294 '\d STORE arg\[-1].*' .. |
295 \ .. 'return arg.*' | 295 'return arg.*' .. |
296 \ .. '\d LOAD arg\[-1].*' | 296 '\d LOAD arg\[-1].*' .. |
297 \ .. '\d RETURN.*' | 297 '\d RETURN.*', |
298 \, res) | 298 res) |
299 enddef | 299 enddef |
300 | 300 |
301 | 301 |
302 def HasEval() | 302 def HasEval() |
303 if has("eval") | 303 if has("eval") |
328 enddef | 328 enddef |
329 | 329 |
330 def Test_disassemble_const_expr() | 330 def Test_disassemble_const_expr() |
331 assert_equal("\nyes", execute('call HasEval()')) | 331 assert_equal("\nyes", execute('call HasEval()')) |
332 let instr = execute('disassemble HasEval') | 332 let instr = execute('disassemble HasEval') |
333 assert_match('HasEval.*' | 333 assert_match('HasEval.*' .. |
334 \ .. 'if has("eval").*' | 334 'if has("eval").*' .. |
335 \ .. ' PUSHS "yes".*' | 335 ' PUSHS "yes".*', |
336 \, instr) | 336 instr) |
337 assert_notmatch('JUMP', instr) | 337 assert_notmatch('JUMP', instr) |
338 | 338 |
339 assert_equal("\nno", execute('call HasNothing()')) | 339 assert_equal("\nno", execute('call HasNothing()')) |
340 instr = execute('disassemble HasNothing') | 340 instr = execute('disassemble HasNothing') |
341 assert_match('HasNothing.*' | 341 assert_match('HasNothing.*' .. |
342 \ .. 'if has("nothing").*' | 342 'if has("nothing").*' .. |
343 \ .. 'else.*' | 343 'else.*' .. |
344 \ .. ' PUSHS "no".*' | 344 ' PUSHS "no".*', |
345 \, instr) | 345 instr) |
346 assert_notmatch('PUSHS "yes"', instr) | 346 assert_notmatch('PUSHS "yes"', instr) |
347 assert_notmatch('JUMP', instr) | 347 assert_notmatch('JUMP', instr) |
348 | 348 |
349 assert_equal("\neval", execute('call HasSomething()')) | 349 assert_equal("\neval", execute('call HasSomething()')) |
350 instr = execute('disassemble HasSomething') | 350 instr = execute('disassemble HasSomething') |
351 assert_match('HasSomething.*' | 351 assert_match('HasSomething.*' .. |
352 \ .. 'if has("nothing").*' | 352 'if has("nothing").*' .. |
353 \ .. 'elseif has("something").*' | 353 'elseif has("something").*' .. |
354 \ .. 'elseif has("eval").*' | 354 'elseif has("eval").*' .. |
355 \ .. ' PUSHS "eval".*' | 355 ' PUSHS "eval".*' .. |
356 \ .. 'elseif has("less").*' | 356 'elseif has("less").*', |
357 \, instr) | 357 instr) |
358 assert_notmatch('PUSHS "nothing"', instr) | 358 assert_notmatch('PUSHS "nothing"', instr) |
359 assert_notmatch('PUSHS "something"', instr) | 359 assert_notmatch('PUSHS "something"', instr) |
360 assert_notmatch('PUSHS "less"', instr) | 360 assert_notmatch('PUSHS "less"', instr) |
361 assert_notmatch('JUMP', instr) | 361 assert_notmatch('JUMP', instr) |
362 enddef | 362 enddef |
367 let Party2: func = funcref("UserFunc") | 367 let Party2: func = funcref("UserFunc") |
368 enddef | 368 enddef |
369 | 369 |
370 def Test_disassemble_function() | 370 def Test_disassemble_function() |
371 let instr = execute('disassemble WithFunc') | 371 let instr = execute('disassemble WithFunc') |
372 assert_match('WithFunc.*' | 372 assert_match('WithFunc.*' .. |
373 \ .. 'let Funky1: func.*' | 373 'let Funky1: func.*' .. |
374 \ .. '0 PUSHFUNC "\[none]".*' | 374 '0 PUSHFUNC "\[none]".*' .. |
375 \ .. '1 STORE $0.*' | 375 '1 STORE $0.*' .. |
376 \ .. 'let Funky2: func = function("len").*' | 376 'let Funky2: func = function("len").*' .. |
377 \ .. '2 PUSHS "len".*' | 377 '2 PUSHS "len".*' .. |
378 \ .. '3 BCALL function(argc 1).*' | 378 '3 BCALL function(argc 1).*' .. |
379 \ .. '4 STORE $1.*' | 379 '4 STORE $1.*' .. |
380 \ .. 'let Party2: func = funcref("UserFunc").*' | 380 'let Party2: func = funcref("UserFunc").*' .. |
381 \ .. '\d PUSHS "UserFunc".*' | 381 '\d PUSHS "UserFunc".*' .. |
382 \ .. '\d BCALL funcref(argc 1).*' | 382 '\d BCALL funcref(argc 1).*' .. |
383 \ .. '\d STORE $2.*' | 383 '\d STORE $2.*' .. |
384 \ .. '\d PUSHNR 0.*' | 384 '\d PUSHNR 0.*' .. |
385 \ .. '\d RETURN.*' | 385 '\d RETURN.*', |
386 \, instr) | 386 instr) |
387 enddef | 387 enddef |
388 | 388 |
389 if has('channel') | 389 if has('channel') |
390 def WithChannel() | 390 def WithChannel() |
391 let job1: job | 391 let job1: job |
396 | 396 |
397 def Test_disassemble_channel() | 397 def Test_disassemble_channel() |
398 CheckFeature channel | 398 CheckFeature channel |
399 | 399 |
400 let instr = execute('disassemble WithChannel') | 400 let instr = execute('disassemble WithChannel') |
401 assert_match('WithChannel.*' | 401 assert_match('WithChannel.*' .. |
402 \ .. 'let job1: job.*' | 402 'let job1: job.*' .. |
403 \ .. '\d PUSHJOB "no process".*' | 403 '\d PUSHJOB "no process".*' .. |
404 \ .. '\d STORE $0.*' | 404 '\d STORE $0.*' .. |
405 \ .. 'let job2: job = job_start("donothing").*' | 405 'let job2: job = job_start("donothing").*' .. |
406 \ .. '\d PUSHS "donothing".*' | 406 '\d PUSHS "donothing".*' .. |
407 \ .. '\d BCALL job_start(argc 1).*' | 407 '\d BCALL job_start(argc 1).*' .. |
408 \ .. '\d STORE $1.*' | 408 '\d STORE $1.*' .. |
409 \ .. 'let chan1: channel.*' | 409 'let chan1: channel.*' .. |
410 \ .. '\d PUSHCHANNEL 0.*' | 410 '\d PUSHCHANNEL 0.*' .. |
411 \ .. '\d STORE $2.*' | 411 '\d STORE $2.*' .. |
412 \ .. '\d PUSHNR 0.*' | 412 '\d PUSHNR 0.*' .. |
413 \ .. '\d RETURN.*' | 413 '\d RETURN.*', |
414 \, instr) | 414 instr) |
415 enddef | 415 enddef |
416 | 416 |
417 def WithLambda(): string | 417 def WithLambda(): string |
418 let F = {a -> "X" .. a .. "X"} | 418 let F = {a -> "X" .. a .. "X"} |
419 return F("x") | 419 return F("x") |
420 enddef | 420 enddef |
421 | 421 |
422 def Test_disassemble_lambda() | 422 def Test_disassemble_lambda() |
423 assert_equal("XxX", WithLambda()) | 423 assert_equal("XxX", WithLambda()) |
424 let instr = execute('disassemble WithLambda') | 424 let instr = execute('disassemble WithLambda') |
425 assert_match('WithLambda.*' | 425 assert_match('WithLambda.*' .. |
426 \ .. 'let F = {a -> "X" .. a .. "X"}.*' | 426 'let F = {a -> "X" .. a .. "X"}.*' .. |
427 \ .. ' FUNCREF <lambda>\d\+.*' | 427 ' FUNCREF <lambda>\d\+.*' .. |
428 \ .. 'PUSHS "x".*' | 428 'PUSHS "x".*' .. |
429 \ .. ' LOAD $0.*' | 429 ' LOAD $0.*' .. |
430 \ .. ' PCALL (argc 1).*' | 430 ' PCALL (argc 1).*' .. |
431 \ .. ' CHECKTYPE string stack\[-1].*' | 431 ' CHECKTYPE string stack\[-1].*', |
432 \, instr) | 432 instr) |
433 enddef | 433 enddef |
434 | 434 |
435 def AndOr(arg): string | 435 def AndOr(arg): string |
436 if arg == 1 && arg != 2 || arg == 4 | 436 if arg == 1 && arg != 2 || arg == 4 |
437 return 'yes' | 437 return 'yes' |
442 def Test_disassemble_and_or() | 442 def Test_disassemble_and_or() |
443 assert_equal("yes", AndOr(1)) | 443 assert_equal("yes", AndOr(1)) |
444 assert_equal("no", AndOr(2)) | 444 assert_equal("no", AndOr(2)) |
445 assert_equal("yes", AndOr(4)) | 445 assert_equal("yes", AndOr(4)) |
446 let instr = execute('disassemble AndOr') | 446 let instr = execute('disassemble AndOr') |
447 assert_match('AndOr.*' | 447 assert_match('AndOr.*' .. |
448 \ .. 'if arg == 1 && arg != 2 || arg == 4.*' | 448 'if arg == 1 && arg != 2 || arg == 4.*' .. |
449 \ .. '\d LOAD arg\[-1].*' | 449 '\d LOAD arg\[-1].*' .. |
450 \ .. '\d PUSHNR 1.*' | 450 '\d PUSHNR 1.*' .. |
451 \ .. '\d COMPAREANY ==.*' | 451 '\d COMPAREANY ==.*' .. |
452 \ .. '\d JUMP_AND_KEEP_IF_FALSE -> \d\+.*' | 452 '\d JUMP_AND_KEEP_IF_FALSE -> \d\+.*' .. |
453 \ .. '\d LOAD arg\[-1].*' | 453 '\d LOAD arg\[-1].*' .. |
454 \ .. '\d PUSHNR 2.*' | 454 '\d PUSHNR 2.*' .. |
455 \ .. '\d COMPAREANY !=.*' | 455 '\d COMPAREANY !=.*' .. |
456 \ .. '\d JUMP_AND_KEEP_IF_TRUE -> \d\+.*' | 456 '\d JUMP_AND_KEEP_IF_TRUE -> \d\+.*' .. |
457 \ .. '\d LOAD arg\[-1].*' | 457 '\d LOAD arg\[-1].*' .. |
458 \ .. '\d PUSHNR 4.*' | 458 '\d PUSHNR 4.*' .. |
459 \ .. '\d COMPAREANY ==.*' | 459 '\d COMPAREANY ==.*' .. |
460 \ .. '\d JUMP_IF_FALSE -> \d\+.*' | 460 '\d JUMP_IF_FALSE -> \d\+.*', |
461 \, instr) | 461 instr) |
462 enddef | 462 enddef |
463 | 463 |
464 def ForLoop(): list<number> | 464 def ForLoop(): list<number> |
465 let res: list<number> | 465 let res: list<number> |
466 for i in range(3) | 466 for i in range(3) |
470 enddef | 470 enddef |
471 | 471 |
472 def Test_disassemble_for_loop() | 472 def Test_disassemble_for_loop() |
473 assert_equal([0, 1, 2], ForLoop()) | 473 assert_equal([0, 1, 2], ForLoop()) |
474 let instr = execute('disassemble ForLoop') | 474 let instr = execute('disassemble ForLoop') |
475 assert_match('ForLoop.*' | 475 assert_match('ForLoop.*' .. |
476 \ .. 'let res: list<number>.*' | 476 'let res: list<number>.*' .. |
477 \ .. ' NEWLIST size 0.*' | 477 ' NEWLIST size 0.*' .. |
478 \ .. '\d STORE $0.*' | 478 '\d STORE $0.*' .. |
479 \ .. 'for i in range(3).*' | 479 'for i in range(3).*' .. |
480 \ .. '\d STORE -1 in $1.*' | 480 '\d STORE -1 in $1.*' .. |
481 \ .. '\d PUSHNR 3.*' | 481 '\d PUSHNR 3.*' .. |
482 \ .. '\d BCALL range(argc 1).*' | 482 '\d BCALL range(argc 1).*' .. |
483 \ .. '\d FOR $1 -> \d\+.*' | 483 '\d FOR $1 -> \d\+.*' .. |
484 \ .. '\d STORE $2.*' | 484 '\d STORE $2.*' .. |
485 \ .. 'res->add(i).*' | 485 'res->add(i).*' .. |
486 \ .. '\d LOAD $0.*' | 486 '\d LOAD $0.*' .. |
487 \ .. '\d LOAD $2.*' | 487 '\d LOAD $2.*' .. |
488 \ .. '\d BCALL add(argc 2).*' | 488 '\d BCALL add(argc 2).*' .. |
489 \ .. '\d DROP.*' | 489 '\d DROP.*' .. |
490 \ .. 'endfor.*' | 490 'endfor.*' .. |
491 \ .. '\d JUMP -> \d\+.*' | 491 '\d JUMP -> \d\+.*' .. |
492 \ .. '\d DROP.*' | 492 '\d DROP.*', |
493 \, instr) | 493 instr) |
494 enddef | 494 enddef |
495 | 495 |
496 let g:number = 42 | 496 let g:number = 42 |
497 | 497 |
498 def Computing() | 498 def Computing() |
518 endif | 518 endif |
519 enddef | 519 enddef |
520 | 520 |
521 def Test_disassemble_computing() | 521 def Test_disassemble_computing() |
522 let instr = execute('disassemble Computing') | 522 let instr = execute('disassemble Computing') |
523 assert_match('Computing.*' | 523 assert_match('Computing.*' .. |
524 \ .. 'let nr = 3.*' | 524 'let nr = 3.*' .. |
525 \ .. '\d STORE 3 in $0.*' | 525 '\d STORE 3 in $0.*' .. |
526 \ .. 'let nrres = nr + 7.*' | 526 'let nrres = nr + 7.*' .. |
527 \ .. '\d LOAD $0.*' | 527 '\d LOAD $0.*' .. |
528 \ .. '\d PUSHNR 7.*' | 528 '\d PUSHNR 7.*' .. |
529 \ .. '\d OPNR +.*' | 529 '\d OPNR +.*' .. |
530 \ .. '\d STORE $1.*' | 530 '\d STORE $1.*' .. |
531 \ .. 'nrres = nr - 7.*' | 531 'nrres = nr - 7.*' .. |
532 \ .. '\d OPNR -.*' | 532 '\d OPNR -.*' .. |
533 \ .. 'nrres = nr \* 7.*' | 533 'nrres = nr \* 7.*' .. |
534 \ .. '\d OPNR \*.*' | 534 '\d OPNR \*.*' .. |
535 \ .. 'nrres = nr / 7.*' | 535 'nrres = nr / 7.*' .. |
536 \ .. '\d OPNR /.*' | 536 '\d OPNR /.*' .. |
537 \ .. 'nrres = nr % 7.*' | 537 'nrres = nr % 7.*' .. |
538 \ .. '\d OPNR %.*' | 538 '\d OPNR %.*' .. |
539 \ .. 'let anyres = g:number + 7.*' | 539 'let anyres = g:number + 7.*' .. |
540 \ .. '\d LOADG g:number.*' | 540 '\d LOADG g:number.*' .. |
541 \ .. '\d PUSHNR 7.*' | 541 '\d PUSHNR 7.*' .. |
542 \ .. '\d OPANY +.*' | 542 '\d OPANY +.*' .. |
543 \ .. '\d STORE $2.*' | 543 '\d STORE $2.*' .. |
544 \ .. 'anyres = g:number - 7.*' | 544 'anyres = g:number - 7.*' .. |
545 \ .. '\d OPANY -.*' | 545 '\d OPANY -.*' .. |
546 \ .. 'anyres = g:number \* 7.*' | 546 'anyres = g:number \* 7.*' .. |
547 \ .. '\d OPANY \*.*' | 547 '\d OPANY \*.*' .. |
548 \ .. 'anyres = g:number / 7.*' | 548 'anyres = g:number / 7.*' .. |
549 \ .. '\d OPANY /.*' | 549 '\d OPANY /.*' .. |
550 \ .. 'anyres = g:number % 7.*' | 550 'anyres = g:number % 7.*' .. |
551 \ .. '\d OPANY %.*' | 551 '\d OPANY %.*', |
552 \, instr) | 552 instr) |
553 if has('float') | 553 if has('float') |
554 assert_match('Computing.*' | 554 assert_match('Computing.*' .. |
555 \ .. 'let fl = 3.0.*' | 555 'let fl = 3.0.*' .. |
556 \ .. '\d PUSHF 3.0.*' | 556 '\d PUSHF 3.0.*' .. |
557 \ .. '\d STORE $3.*' | 557 '\d STORE $3.*' .. |
558 \ .. 'let flres = fl + 7.0.*' | 558 'let flres = fl + 7.0.*' .. |
559 \ .. '\d LOAD $3.*' | 559 '\d LOAD $3.*' .. |
560 \ .. '\d PUSHF 7.0.*' | 560 '\d PUSHF 7.0.*' .. |
561 \ .. '\d OPFLOAT +.*' | 561 '\d OPFLOAT +.*' .. |
562 \ .. '\d STORE $4.*' | 562 '\d STORE $4.*' .. |
563 \ .. 'flres = fl - 7.0.*' | 563 'flres = fl - 7.0.*' .. |
564 \ .. '\d OPFLOAT -.*' | 564 '\d OPFLOAT -.*' .. |
565 \ .. 'flres = fl \* 7.0.*' | 565 'flres = fl \* 7.0.*' .. |
566 \ .. '\d OPFLOAT \*.*' | 566 '\d OPFLOAT \*.*' .. |
567 \ .. 'flres = fl / 7.0.*' | 567 'flres = fl / 7.0.*' .. |
568 \ .. '\d OPFLOAT /.*' | 568 '\d OPFLOAT /.*', |
569 \, instr) | 569 instr) |
570 endif | 570 endif |
571 enddef | 571 enddef |
572 | 572 |
573 def AddListBlob() | 573 def AddListBlob() |
574 let reslist = [1, 2] + [3, 4] | 574 let reslist = [1, 2] + [3, 4] |
575 let resblob = 0z1122 + 0z3344 | 575 let resblob = 0z1122 + 0z3344 |
576 enddef | 576 enddef |
577 | 577 |
578 def Test_disassemble_add_list_blob() | 578 def Test_disassemble_add_list_blob() |
579 let instr = execute('disassemble AddListBlob') | 579 let instr = execute('disassemble AddListBlob') |
580 assert_match('AddListBlob.*' | 580 assert_match('AddListBlob.*' .. |
581 \ .. 'let reslist = \[1, 2] + \[3, 4].*' | 581 'let reslist = \[1, 2] + \[3, 4].*' .. |
582 \ .. '\d PUSHNR 1.*' | 582 '\d PUSHNR 1.*' .. |
583 \ .. '\d PUSHNR 2.*' | 583 '\d PUSHNR 2.*' .. |
584 \ .. '\d NEWLIST size 2.*' | 584 '\d NEWLIST size 2.*' .. |
585 \ .. '\d PUSHNR 3.*' | 585 '\d PUSHNR 3.*' .. |
586 \ .. '\d PUSHNR 4.*' | 586 '\d PUSHNR 4.*' .. |
587 \ .. '\d NEWLIST size 2.*' | 587 '\d NEWLIST size 2.*' .. |
588 \ .. '\d ADDLIST.*' | 588 '\d ADDLIST.*' .. |
589 \ .. '\d STORE $.*.*' | 589 '\d STORE $.*.*' .. |
590 \ .. 'let resblob = 0z1122 + 0z3344.*' | 590 'let resblob = 0z1122 + 0z3344.*' .. |
591 \ .. '\d PUSHBLOB 0z1122.*' | 591 '\d PUSHBLOB 0z1122.*' .. |
592 \ .. '\d PUSHBLOB 0z3344.*' | 592 '\d PUSHBLOB 0z3344.*' .. |
593 \ .. '\d ADDBLOB.*' | 593 '\d ADDBLOB.*' .. |
594 \ .. '\d STORE $.*' | 594 '\d STORE $.*', |
595 \, instr) | 595 instr) |
596 enddef | 596 enddef |
597 | 597 |
598 let g:aa = 'aa' | 598 let g:aa = 'aa' |
599 def ConcatString(): string | 599 def ConcatString(): string |
600 let res = g:aa .. "bb" | 600 let res = g:aa .. "bb" |
601 return res | 601 return res |
602 enddef | 602 enddef |
603 | 603 |
604 def Test_disassemble_concat() | 604 def Test_disassemble_concat() |
605 let instr = execute('disassemble ConcatString') | 605 let instr = execute('disassemble ConcatString') |
606 assert_match('ConcatString.*' | 606 assert_match('ConcatString.*' .. |
607 \ .. 'let res = g:aa .. "bb".*' | 607 'let res = g:aa .. "bb".*' .. |
608 \ .. '\d LOADG g:aa.*' | 608 '\d LOADG g:aa.*' .. |
609 \ .. '\d PUSHS "bb".*' | 609 '\d PUSHS "bb".*' .. |
610 \ .. '\d 2STRING stack\[-2].*' | 610 '\d 2STRING stack\[-2].*' .. |
611 \ .. '\d CONCAT.*' | 611 '\d CONCAT.*' .. |
612 \ .. '\d STORE $.*' | 612 '\d STORE $.*', |
613 \, instr) | 613 instr) |
614 assert_equal('aabb', ConcatString()) | 614 assert_equal('aabb', ConcatString()) |
615 enddef | 615 enddef |
616 | 616 |
617 def ListIndex(): number | 617 def ListIndex(): number |
618 let l = [1, 2, 3] | 618 let l = [1, 2, 3] |
620 return res | 620 return res |
621 enddef | 621 enddef |
622 | 622 |
623 def Test_disassemble_list_index() | 623 def Test_disassemble_list_index() |
624 let instr = execute('disassemble ListIndex') | 624 let instr = execute('disassemble ListIndex') |
625 assert_match('ListIndex.*' | 625 assert_match('ListIndex.*' .. |
626 \ .. 'let l = \[1, 2, 3].*' | 626 'let l = \[1, 2, 3].*' .. |
627 \ .. '\d PUSHNR 1.*' | 627 '\d PUSHNR 1.*' .. |
628 \ .. '\d PUSHNR 2.*' | 628 '\d PUSHNR 2.*' .. |
629 \ .. '\d PUSHNR 3.*' | 629 '\d PUSHNR 3.*' .. |
630 \ .. '\d NEWLIST size 3.*' | 630 '\d NEWLIST size 3.*' .. |
631 \ .. '\d STORE $0.*' | 631 '\d STORE $0.*' .. |
632 \ .. 'let res = l\[1].*' | 632 'let res = l\[1].*' .. |
633 \ .. '\d LOAD $0.*' | 633 '\d LOAD $0.*' .. |
634 \ .. '\d PUSHNR 1.*' | 634 '\d PUSHNR 1.*' .. |
635 \ .. '\d INDEX.*' | 635 '\d INDEX.*' .. |
636 \ .. '\d STORE $1.*' | 636 '\d STORE $1.*', |
637 \, instr) | 637 instr) |
638 assert_equal(2, ListIndex()) | 638 assert_equal(2, ListIndex()) |
639 enddef | 639 enddef |
640 | 640 |
641 def DictMember(): number | 641 def DictMember(): number |
642 let d = #{item: 1} | 642 let d = #{item: 1} |
644 return res | 644 return res |
645 enddef | 645 enddef |
646 | 646 |
647 def Test_disassemble_dict_member() | 647 def Test_disassemble_dict_member() |
648 let instr = execute('disassemble DictMember') | 648 let instr = execute('disassemble DictMember') |
649 assert_match('DictMember.*' | 649 assert_match('DictMember.*' .. |
650 \ .. 'let d = #{item: 1}.*' | 650 'let d = #{item: 1}.*' .. |
651 \ .. '\d PUSHS "item".*' | 651 '\d PUSHS "item".*' .. |
652 \ .. '\d PUSHNR 1.*' | 652 '\d PUSHNR 1.*' .. |
653 \ .. '\d NEWDICT size 1.*' | 653 '\d NEWDICT size 1.*' .. |
654 \ .. '\d STORE $0.*' | 654 '\d STORE $0.*' .. |
655 \ .. 'let res = d.item.*' | 655 'let res = d.item.*' .. |
656 \ .. '\d LOAD $0.*' | 656 '\d LOAD $0.*' .. |
657 \ .. '\d MEMBER item.*' | 657 '\d MEMBER item.*' .. |
658 \ .. '\d STORE $1.*' | 658 '\d STORE $1.*', |
659 \, instr) | 659 instr) |
660 call assert_equal(1, DictMember()) | 660 call assert_equal(1, DictMember()) |
661 enddef | 661 enddef |
662 | 662 |
663 def NegateNumber(): number | 663 def NegateNumber(): number |
664 let nr = 9 | 664 let nr = 9 |
667 return res | 667 return res |
668 enddef | 668 enddef |
669 | 669 |
670 def Test_disassemble_negate_number() | 670 def Test_disassemble_negate_number() |
671 let instr = execute('disassemble NegateNumber') | 671 let instr = execute('disassemble NegateNumber') |
672 assert_match('NegateNumber.*' | 672 assert_match('NegateNumber.*' .. |
673 \ .. 'let nr = 9.*' | 673 'let nr = 9.*' .. |
674 \ .. '\d STORE 9 in $0.*' | 674 '\d STORE 9 in $0.*' .. |
675 \ .. 'let plus = +nr.*' | 675 'let plus = +nr.*' .. |
676 \ .. '\d LOAD $0.*' | 676 '\d LOAD $0.*' .. |
677 \ .. '\d CHECKNR.*' | 677 '\d CHECKNR.*' .. |
678 \ .. '\d STORE $1.*' | 678 '\d STORE $1.*' .. |
679 \ .. 'let res = -nr.*' | 679 'let res = -nr.*' .. |
680 \ .. '\d LOAD $0.*' | 680 '\d LOAD $0.*' .. |
681 \ .. '\d NEGATENR.*' | 681 '\d NEGATENR.*' .. |
682 \ .. '\d STORE $2.*' | 682 '\d STORE $2.*', |
683 \, instr) | 683 instr) |
684 call assert_equal(-9, NegateNumber()) | 684 call assert_equal(-9, NegateNumber()) |
685 enddef | 685 enddef |
686 | 686 |
687 def InvertBool(): bool | 687 def InvertBool(): bool |
688 let flag = true | 688 let flag = true |
691 return res | 691 return res |
692 enddef | 692 enddef |
693 | 693 |
694 def Test_disassemble_invert_bool() | 694 def Test_disassemble_invert_bool() |
695 let instr = execute('disassemble InvertBool') | 695 let instr = execute('disassemble InvertBool') |
696 assert_match('InvertBool.*' | 696 assert_match('InvertBool.*' .. |
697 \ .. 'let flag = true.*' | 697 'let flag = true.*' .. |
698 \ .. '\d PUSH v:true.*' | 698 '\d PUSH v:true.*' .. |
699 \ .. '\d STORE $0.*' | 699 '\d STORE $0.*' .. |
700 \ .. 'let invert = !flag.*' | 700 'let invert = !flag.*' .. |
701 \ .. '\d LOAD $0.*' | 701 '\d LOAD $0.*' .. |
702 \ .. '\d INVERT (!val).*' | 702 '\d INVERT (!val).*' .. |
703 \ .. '\d STORE $1.*' | 703 '\d STORE $1.*' .. |
704 \ .. 'let res = !!flag.*' | 704 'let res = !!flag.*' .. |
705 \ .. '\d LOAD $0.*' | 705 '\d LOAD $0.*' .. |
706 \ .. '\d 2BOOL (!!val).*' | 706 '\d 2BOOL (!!val).*' .. |
707 \ .. '\d STORE $2.*' | 707 '\d STORE $2.*', |
708 \, instr) | 708 instr) |
709 call assert_equal(true, InvertBool()) | 709 call assert_equal(true, InvertBool()) |
710 enddef | 710 enddef |
711 | 711 |
712 def Test_disassemble_compare() | 712 def Test_disassemble_compare() |
713 " TODO: COMPAREFUNC | 713 " TODO: COMPAREFUNC |
714 let cases = [ | 714 let cases = [ |
715 \ ['true == false', 'COMPAREBOOL =='], | 715 ['true == false', 'COMPAREBOOL =='], |
716 \ ['true != false', 'COMPAREBOOL !='], | 716 ['true != false', 'COMPAREBOOL !='], |
717 \ ['v:none == v:null', 'COMPARESPECIAL =='], | 717 ['v:none == v:null', 'COMPARESPECIAL =='], |
718 \ ['v:none != v:null', 'COMPARESPECIAL !='], | 718 ['v:none != v:null', 'COMPARESPECIAL !='], |
719 \ | 719 |
720 \ ['111 == 222', 'COMPARENR =='], | 720 ['111 == 222', 'COMPARENR =='], |
721 \ ['111 != 222', 'COMPARENR !='], | 721 ['111 != 222', 'COMPARENR !='], |
722 \ ['111 > 222', 'COMPARENR >'], | 722 ['111 > 222', 'COMPARENR >'], |
723 \ ['111 < 222', 'COMPARENR <'], | 723 ['111 < 222', 'COMPARENR <'], |
724 \ ['111 >= 222', 'COMPARENR >='], | 724 ['111 >= 222', 'COMPARENR >='], |
725 \ ['111 <= 222', 'COMPARENR <='], | 725 ['111 <= 222', 'COMPARENR <='], |
726 \ ['111 =~ 222', 'COMPARENR =\~'], | 726 ['111 =~ 222', 'COMPARENR =\~'], |
727 \ ['111 !~ 222', 'COMPARENR !\~'], | 727 ['111 !~ 222', 'COMPARENR !\~'], |
728 \ | 728 |
729 \ ['"xx" != "yy"', 'COMPARESTRING !='], | 729 ['"xx" != "yy"', 'COMPARESTRING !='], |
730 \ ['"xx" > "yy"', 'COMPARESTRING >'], | 730 ['"xx" > "yy"', 'COMPARESTRING >'], |
731 \ ['"xx" < "yy"', 'COMPARESTRING <'], | 731 ['"xx" < "yy"', 'COMPARESTRING <'], |
732 \ ['"xx" >= "yy"', 'COMPARESTRING >='], | 732 ['"xx" >= "yy"', 'COMPARESTRING >='], |
733 \ ['"xx" <= "yy"', 'COMPARESTRING <='], | 733 ['"xx" <= "yy"', 'COMPARESTRING <='], |
734 \ ['"xx" =~ "yy"', 'COMPARESTRING =\~'], | 734 ['"xx" =~ "yy"', 'COMPARESTRING =\~'], |
735 \ ['"xx" !~ "yy"', 'COMPARESTRING !\~'], | 735 ['"xx" !~ "yy"', 'COMPARESTRING !\~'], |
736 \ ['"xx" is "yy"', 'COMPARESTRING is'], | 736 ['"xx" is "yy"', 'COMPARESTRING is'], |
737 \ ['"xx" isnot "yy"', 'COMPARESTRING isnot'], | 737 ['"xx" isnot "yy"', 'COMPARESTRING isnot'], |
738 \ | 738 |
739 \ ['0z11 == 0z22', 'COMPAREBLOB =='], | 739 ['0z11 == 0z22', 'COMPAREBLOB =='], |
740 \ ['0z11 != 0z22', 'COMPAREBLOB !='], | 740 ['0z11 != 0z22', 'COMPAREBLOB !='], |
741 \ ['0z11 is 0z22', 'COMPAREBLOB is'], | 741 ['0z11 is 0z22', 'COMPAREBLOB is'], |
742 \ ['0z11 isnot 0z22', 'COMPAREBLOB isnot'], | 742 ['0z11 isnot 0z22', 'COMPAREBLOB isnot'], |
743 \ | 743 |
744 \ ['[1,2] == [3,4]', 'COMPARELIST =='], | 744 ['[1,2] == [3,4]', 'COMPARELIST =='], |
745 \ ['[1,2] != [3,4]', 'COMPARELIST !='], | 745 ['[1,2] != [3,4]', 'COMPARELIST !='], |
746 \ ['[1,2] is [3,4]', 'COMPARELIST is'], | 746 ['[1,2] is [3,4]', 'COMPARELIST is'], |
747 \ ['[1,2] isnot [3,4]', 'COMPARELIST isnot'], | 747 ['[1,2] isnot [3,4]', 'COMPARELIST isnot'], |
748 \ | 748 |
749 \ ['#{a:1} == #{x:2}', 'COMPAREDICT =='], | 749 ['#{a:1} == #{x:2}', 'COMPAREDICT =='], |
750 \ ['#{a:1} != #{x:2}', 'COMPAREDICT !='], | 750 ['#{a:1} != #{x:2}', 'COMPAREDICT !='], |
751 \ ['#{a:1} is #{x:2}', 'COMPAREDICT is'], | 751 ['#{a:1} is #{x:2}', 'COMPAREDICT is'], |
752 \ ['#{a:1} isnot #{x:2}', 'COMPAREDICT isnot'], | 752 ['#{a:1} isnot #{x:2}', 'COMPAREDICT isnot'], |
753 \ | 753 |
754 \ ['{->33} == {->44}', 'COMPAREFUNC =='], | 754 ['{->33} == {->44}', 'COMPAREFUNC =='], |
755 \ ['{->33} != {->44}', 'COMPAREFUNC !='], | 755 ['{->33} != {->44}', 'COMPAREFUNC !='], |
756 \ ['{->33} is {->44}', 'COMPAREFUNC is'], | 756 ['{->33} is {->44}', 'COMPAREFUNC is'], |
757 \ ['{->33} isnot {->44}', 'COMPAREFUNC isnot'], | 757 ['{->33} isnot {->44}', 'COMPAREFUNC isnot'], |
758 \ | 758 |
759 \ ['77 == g:xx', 'COMPAREANY =='], | 759 ['77 == g:xx', 'COMPAREANY =='], |
760 \ ['77 != g:xx', 'COMPAREANY !='], | 760 ['77 != g:xx', 'COMPAREANY !='], |
761 \ ['77 > g:xx', 'COMPAREANY >'], | 761 ['77 > g:xx', 'COMPAREANY >'], |
762 \ ['77 < g:xx', 'COMPAREANY <'], | 762 ['77 < g:xx', 'COMPAREANY <'], |
763 \ ['77 >= g:xx', 'COMPAREANY >='], | 763 ['77 >= g:xx', 'COMPAREANY >='], |
764 \ ['77 <= g:xx', 'COMPAREANY <='], | 764 ['77 <= g:xx', 'COMPAREANY <='], |
765 \ ['77 =~ g:xx', 'COMPAREANY =\~'], | 765 ['77 =~ g:xx', 'COMPAREANY =\~'], |
766 \ ['77 !~ g:xx', 'COMPAREANY !\~'], | 766 ['77 !~ g:xx', 'COMPAREANY !\~'], |
767 \ ['77 is g:xx', 'COMPAREANY is'], | 767 ['77 is g:xx', 'COMPAREANY is'], |
768 \ ['77 isnot g:xx', 'COMPAREANY isnot'], | 768 ['77 isnot g:xx', 'COMPAREANY isnot'], |
769 \ ] | 769 ] |
770 if has('float') | 770 if has('float') |
771 cases->extend([ | 771 cases->extend([ |
772 \ ['1.1 == 2.2', 'COMPAREFLOAT =='], | 772 ['1.1 == 2.2', 'COMPAREFLOAT =='], |
773 \ ['1.1 != 2.2', 'COMPAREFLOAT !='], | 773 ['1.1 != 2.2', 'COMPAREFLOAT !='], |
774 \ ['1.1 > 2.2', 'COMPAREFLOAT >'], | 774 ['1.1 > 2.2', 'COMPAREFLOAT >'], |
775 \ ['1.1 < 2.2', 'COMPAREFLOAT <'], | 775 ['1.1 < 2.2', 'COMPAREFLOAT <'], |
776 \ ['1.1 >= 2.2', 'COMPAREFLOAT >='], | 776 ['1.1 >= 2.2', 'COMPAREFLOAT >='], |
777 \ ['1.1 <= 2.2', 'COMPAREFLOAT <='], | 777 ['1.1 <= 2.2', 'COMPAREFLOAT <='], |
778 \ ['1.1 =~ 2.2', 'COMPAREFLOAT =\~'], | 778 ['1.1 =~ 2.2', 'COMPAREFLOAT =\~'], |
779 \ ['1.1 !~ 2.2', 'COMPAREFLOAT !\~'], | 779 ['1.1 !~ 2.2', 'COMPAREFLOAT !\~'], |
780 \ ]) | 780 ]) |
781 endif | 781 endif |
782 | 782 |
783 let nr = 1 | 783 let nr = 1 |
784 for case in cases | 784 for case in cases |
785 writefile(['def TestCase' .. nr .. '()', | 785 writefile(['def TestCase' .. nr .. '()', |
786 \ ' if ' .. case[0], | 786 ' if ' .. case[0], |
787 \ ' echo 42' | 787 ' echo 42' |
788 \ ' endif', | 788 ' endif', |
789 \ 'enddef'], 'Xdisassemble') | 789 'enddef'], 'Xdisassemble') |
790 source Xdisassemble | 790 source Xdisassemble |
791 let instr = execute('disassemble TestCase' .. nr) | 791 let instr = execute('disassemble TestCase' .. nr) |
792 assert_match('TestCase' .. nr .. '.*' | 792 assert_match('TestCase' .. nr .. '.*' .. |
793 \ .. 'if ' .. substitute(case[0], '[[~]', '\\\0', 'g') .. '.*' | 793 'if ' .. substitute(case[0], '[[~]', '\\\0', 'g') .. '.*' .. |
794 \ .. '\d \(PUSH\|FUNCREF\).*' | 794 '\d \(PUSH\|FUNCREF\).*' .. |
795 \ .. '\d \(PUSH\|FUNCREF\|LOADG\).*' | 795 '\d \(PUSH\|FUNCREF\|LOADG\).*' .. |
796 \ .. '\d ' .. case[1] .. '.*' | 796 '\d ' .. case[1] .. '.*' .. |
797 \ .. '\d JUMP_IF_FALSE -> \d\+.*' | 797 '\d JUMP_IF_FALSE -> \d\+.*', |
798 \, instr) | 798 instr) |
799 | 799 |
800 nr += 1 | 800 nr += 1 |
801 endfor | 801 endfor |
802 | 802 |
803 delete('Xdisassemble') | 803 delete('Xdisassemble') |
804 enddef | 804 enddef |
805 | 805 |
806 def Test_disassemble_compare_const() | 806 def Test_disassemble_compare_const() |
807 let cases = [ | 807 let cases = [ |
808 \ ['"xx" == "yy"', false], | 808 ['"xx" == "yy"', false], |
809 \ ['"aa" == "aa"', true], | 809 ['"aa" == "aa"', true], |
810 \ ['has("eval") ? true : false', true], | 810 ['has("eval") ? true : false', true], |
811 \ ['has("asdf") ? true : false', false], | 811 ['has("asdf") ? true : false', false], |
812 \ ] | 812 ] |
813 | 813 |
814 let nr = 1 | 814 let nr = 1 |
815 for case in cases | 815 for case in cases |
816 writefile(['def TestCase' .. nr .. '()', | 816 writefile(['def TestCase' .. nr .. '()', |
817 \ ' if ' .. case[0], | 817 ' if ' .. case[0], |
818 \ ' echo 42' | 818 ' echo 42' |
819 \ ' endif', | 819 ' endif', |
820 \ 'enddef'], 'Xdisassemble') | 820 'enddef'], 'Xdisassemble') |
821 source Xdisassemble | 821 source Xdisassemble |
822 let instr = execute('disassemble TestCase' .. nr) | 822 let instr = execute('disassemble TestCase' .. nr) |
823 if case[1] | 823 if case[1] |
824 " condition true, "echo 42" executed | 824 " condition true, "echo 42" executed |
825 assert_match('TestCase' .. nr .. '.*' | 825 assert_match('TestCase' .. nr .. '.*' .. |
826 \ .. 'if ' .. substitute(case[0], '[[~]', '\\\0', 'g') .. '.*' | 826 'if ' .. substitute(case[0], '[[~]', '\\\0', 'g') .. '.*' .. |
827 \ .. '\d PUSHNR 42.*' | 827 '\d PUSHNR 42.*' .. |
828 \ .. '\d ECHO 1.*' | 828 '\d ECHO 1.*' .. |
829 \ .. '\d PUSHNR 0.*' | 829 '\d PUSHNR 0.*' .. |
830 \ .. '\d RETURN.*' | 830 '\d RETURN.*', |
831 \, instr) | 831 instr) |
832 else | 832 else |
833 " condition false, function just returns | 833 " condition false, function just returns |
834 assert_match('TestCase' .. nr .. '.*' | 834 assert_match('TestCase' .. nr .. '.*' .. |
835 \ .. 'if ' .. substitute(case[0], '[[~]', '\\\0', 'g') .. '[ \n]*' | 835 'if ' .. substitute(case[0], '[[~]', '\\\0', 'g') .. '[ \n]*' .. |
836 \ .. 'echo 42[ \n]*' | 836 'echo 42[ \n]*' .. |
837 \ .. 'endif[ \n]*' | 837 'endif[ \n]*' .. |
838 \ .. '\s*\d PUSHNR 0.*' | 838 '\s*\d PUSHNR 0.*' .. |
839 \ .. '\d RETURN.*' | 839 '\d RETURN.*', |
840 \, instr) | 840 instr) |
841 endif | 841 endif |
842 | 842 |
843 nr += 1 | 843 nr += 1 |
844 endfor | 844 endfor |
845 | 845 |
854 execute 'help ' .. tag | 854 execute 'help ' .. tag |
855 enddef | 855 enddef |
856 | 856 |
857 def Test_disassemble_execute() | 857 def Test_disassemble_execute() |
858 let res = execute('disass s:Execute') | 858 let res = execute('disass s:Execute') |
859 assert_match('\<SNR>\d*_Execute.*' | 859 assert_match('\<SNR>\d*_Execute.*' .. |
860 \ .. "execute 'help vim9.txt'.*" | 860 "execute 'help vim9.txt'.*" .. |
861 \ .. '\d PUSHS "help vim9.txt".*' | 861 '\d PUSHS "help vim9.txt".*' .. |
862 \ .. '\d EXECUTE 1.*' | 862 '\d EXECUTE 1.*' .. |
863 \ .. "let cmd = 'help vim9.txt'.*" | 863 "let cmd = 'help vim9.txt'.*" .. |
864 \ .. '\d PUSHS "help vim9.txt".*' | 864 '\d PUSHS "help vim9.txt".*' .. |
865 \ .. '\d STORE $0.*' | 865 '\d STORE $0.*' .. |
866 \ .. 'execute cmd.*' | 866 'execute cmd.*' .. |
867 \ .. '\d LOAD $0.*' | 867 '\d LOAD $0.*' .. |
868 \ .. '\d EXECUTE 1.*' | 868 '\d EXECUTE 1.*' .. |
869 \ .. "let tag = 'vim9.txt'.*" | 869 "let tag = 'vim9.txt'.*" .. |
870 \ .. '\d PUSHS "vim9.txt".*' | 870 '\d PUSHS "vim9.txt".*' .. |
871 \ .. '\d STORE $1.*' | 871 '\d STORE $1.*' .. |
872 \ .. "execute 'help ' .. tag.*" | 872 "execute 'help ' .. tag.*" .. |
873 \ .. '\d PUSHS "help ".*' | 873 '\d PUSHS "help ".*' .. |
874 \ .. '\d LOAD $1.*' | 874 '\d LOAD $1.*' .. |
875 \ .. '\d CONCAT.*' | 875 '\d CONCAT.*' .. |
876 \ .. '\d EXECUTE 1.*' | 876 '\d EXECUTE 1.*' .. |
877 \ .. '\d PUSHNR 0.*' | 877 '\d PUSHNR 0.*' .. |
878 \ .. '\d RETURN' | 878 '\d RETURN', |
879 \, res) | 879 res) |
880 enddef | 880 enddef |
881 | 881 |
882 def SomeStringArg(arg: string) | 882 def SomeStringArg(arg: string) |
883 echo arg | 883 echo arg |
884 enddef | 884 enddef |
891 return arg | 891 return arg |
892 enddef | 892 enddef |
893 | 893 |
894 def Test_display_func() | 894 def Test_display_func() |
895 let res1 = execute('function SomeStringArg') | 895 let res1 = execute('function SomeStringArg') |
896 assert_match('.* def SomeStringArg(arg: string).*' | 896 assert_match('.* def SomeStringArg(arg: string).*' .. |
897 \ .. ' echo arg.*' | 897 ' echo arg.*' .. |
898 \ .. ' enddef' | 898 ' enddef', |
899 \, res1) | 899 res1) |
900 | 900 |
901 let res2 = execute('function SomeAnyArg') | 901 let res2 = execute('function SomeAnyArg') |
902 assert_match('.* def SomeAnyArg(arg: any).*' | 902 assert_match('.* def SomeAnyArg(arg: any).*' .. |
903 \ .. ' echo arg.*' | 903 ' echo arg.*' .. |
904 \ .. ' enddef' | 904 ' enddef', |
905 \, res2) | 905 res2) |
906 | 906 |
907 let res3 = execute('function SomeStringArgAndReturn') | 907 let res3 = execute('function SomeStringArgAndReturn') |
908 assert_match('.* def SomeStringArgAndReturn(arg: string): string.*' | 908 assert_match('.* def SomeStringArgAndReturn(arg: string): string.*' .. |
909 \ .. ' return arg.*' | 909 ' return arg.*' .. |
910 \ .. ' enddef' | 910 ' enddef', |
911 \, res3) | 911 res3) |
912 enddef | 912 enddef |
913 | 913 |
914 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker | 914 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker |