comparison src/testdir/test_vim9_disassemble.vim @ 19342:8ff84bc1c89b v8.2.0229

patch 8.2.0229: compare instructions not tested Commit: https://github.com/vim/vim/commit/f2460a3aec89e70d4bab8d2369ee3f78cc43f09a Author: Bram Moolenaar <Bram@vim.org> Date: Fri Feb 7 22:09:54 2020 +0100 patch 8.2.0229: compare instructions not tested Problem: Compare instructions not tested. Solution: Add test cases. Fix disassemble with line continuation.
author Bram Moolenaar <Bram@vim.org>
date Fri, 07 Feb 2020 22:15:03 +0100
parents ef432264b88a
children e4b326c9424a
comparison
equal deleted inserted replaced
19341:c8b2ecaca20e 19342:8ff84bc1c89b
18 echo &tabstop 18 echo &tabstop
19 echo $ENVVAR 19 echo $ENVVAR
20 echo @z 20 echo @z
21 enddef 21 enddef
22 22
23 def Test_disassembleLoad() 23 def Test_disassemble_load()
24 assert_fails('disass NoFunc', 'E1061:') 24 assert_fails('disass NoFunc', 'E1061:')
25 assert_fails('disass NotCompiled', 'E1062:') 25 assert_fails('disass NotCompiled', 'E1062:')
26 26
27 let res = execute('disass s:ScriptFuncLoad') 27 let res = execute('disass s:ScriptFuncLoad')
28 assert_match('<SNR>\d*_ScriptFuncLoad.*' 28 assert_match('<SNR>\d*_ScriptFuncLoad.*'
45 if has('float') 45 if has('float')
46 let localfloat = 1.234 46 let localfloat = 1.234
47 endif 47 endif
48 enddef 48 enddef
49 49
50 def Test_disassemblePush() 50 def Test_disassemble_push()
51 let res = execute('disass s:ScriptFuncPush') 51 let res = execute('disass s:ScriptFuncPush')
52 assert_match('<SNR>\d*_ScriptFuncPush.*' 52 assert_match('<SNR>\d*_ScriptFuncPush.*'
53 \ .. 'localbool = true.*' 53 \ .. 'localbool = true.*'
54 \ .. ' PUSH v:true.*' 54 \ .. ' PUSH v:true.*'
55 \ .. 'localspec = v:none.*' 55 \ .. 'localspec = v:none.*'
76 &tabstop = 8 76 &tabstop = 8
77 $ENVVAR = 'ev' 77 $ENVVAR = 'ev'
78 @z = 'rv' 78 @z = 'rv'
79 enddef 79 enddef
80 80
81 def Test_disassembleStore() 81 def Test_disassemble_store()
82 let res = execute('disass s:ScriptFuncStore') 82 let res = execute('disass s:ScriptFuncStore')
83 assert_match('<SNR>\d*_ScriptFuncStore.*' 83 assert_match('<SNR>\d*_ScriptFuncStore.*'
84 \ .. 'localnr = 2.*' 84 \ .. 'localnr = 2.*'
85 \ .. ' STORE 2 in $0.*' 85 \ .. ' STORE 2 in $0.*'
86 \ .. 'localstr = ''xyz''.*' 86 \ .. 'localstr = ''xyz''.*'
108 finally 108 finally
109 throw 'end' 109 throw 'end'
110 endtry 110 endtry
111 enddef 111 enddef
112 112
113 def Test_disassembleTry() 113 def Test_disassemble_try()
114 let res = execute('disass s:ScriptFuncTry') 114 let res = execute('disass s:ScriptFuncTry')
115 assert_match('<SNR>\d*_ScriptFuncTry.*' 115 assert_match('<SNR>\d*_ScriptFuncTry.*'
116 \ .. 'try.*' 116 \ .. 'try.*'
117 \ .. 'TRY catch -> \d\+, finally -> \d\+.*' 117 \ .. 'TRY catch -> \d\+, finally -> \d\+.*'
118 \ .. 'catch /fail/.*' 118 \ .. 'catch /fail/.*'
133 def s:ScriptFuncNew() 133 def s:ScriptFuncNew()
134 let ll = [1, "two", 333] 134 let ll = [1, "two", 333]
135 let dd = #{one: 1, two: "val"} 135 let dd = #{one: 1, two: "val"}
136 enddef 136 enddef
137 137
138 def Test_disassembleNew() 138 def Test_disassemble_new()
139 let res = execute('disass s:ScriptFuncNew') 139 let res = execute('disass s:ScriptFuncNew')
140 assert_match('<SNR>\d*_ScriptFuncNew.*' 140 assert_match('<SNR>\d*_ScriptFuncNew.*'
141 \ .. 'let ll = \[1, "two", 333].*' 141 \ .. 'let ll = \[1, "two", 333].*'
142 \ .. 'PUSHNR 1.*' 142 \ .. 'PUSHNR 1.*'
143 \ .. 'PUSHS "two".*' 143 \ .. 'PUSHS "two".*'
165 endfunc 165 endfunc
166 166
167 def s:ScriptFuncCall(): string 167 def s:ScriptFuncCall(): string
168 changenr() 168 changenr()
169 char2nr("abc") 169 char2nr("abc")
170 Test_disassembleNew() 170 Test_disassemble_new()
171 FuncWithArg(343) 171 FuncWithArg(343)
172 ScriptFuncNew() 172 ScriptFuncNew()
173 s:ScriptFuncNew() 173 s:ScriptFuncNew()
174 UserFunc() 174 UserFunc()
175 UserFuncWithArg("foo") 175 UserFuncWithArg("foo")
178 let FuncRefWithArg = function("UserFuncWithArg") 178 let FuncRefWithArg = function("UserFuncWithArg")
179 FuncRefWithArg("bar") 179 FuncRefWithArg("bar")
180 return "yes" 180 return "yes"
181 enddef 181 enddef
182 182
183 def Test_disassembleCall() 183 def Test_disassemble_call()
184 let res = execute('disass s:ScriptFuncCall') 184 let res = execute('disass s:ScriptFuncCall')
185 assert_match('<SNR>\d\+_ScriptFuncCall.*' 185 assert_match('<SNR>\d\+_ScriptFuncCall.*'
186 \ .. 'changenr().*' 186 \ .. 'changenr().*'
187 \ .. ' BCALL changenr(argc 0).*' 187 \ .. ' BCALL changenr(argc 0).*'
188 \ .. 'char2nr("abc").*' 188 \ .. 'char2nr("abc").*'
189 \ .. ' PUSHS "abc".*' 189 \ .. ' PUSHS "abc".*'
190 \ .. ' BCALL char2nr(argc 1).*' 190 \ .. ' BCALL char2nr(argc 1).*'
191 \ .. 'Test_disassembleNew().*' 191 \ .. 'Test_disassemble_new().*'
192 \ .. ' DCALL Test_disassembleNew(argc 0).*' 192 \ .. ' DCALL Test_disassemble_new(argc 0).*'
193 \ .. 'FuncWithArg(343).*' 193 \ .. 'FuncWithArg(343).*'
194 \ .. ' PUSHNR 343.*' 194 \ .. ' PUSHNR 343.*'
195 \ .. ' DCALL FuncWithArg(argc 1).*' 195 \ .. ' DCALL FuncWithArg(argc 1).*'
196 \ .. 'ScriptFuncNew().*' 196 \ .. 'ScriptFuncNew().*'
197 \ .. ' DCALL <SNR>\d\+_ScriptFuncNew(argc 0).*' 197 \ .. ' DCALL <SNR>\d\+_ScriptFuncNew(argc 0).*'
243 elseif has("less") 243 elseif has("less")
244 echo "less" 244 echo "less"
245 endif 245 endif
246 enddef 246 enddef
247 247
248 def Test_compile_const_expr() 248 def Test_disassemble_const_expr()
249 assert_equal("\nyes", execute('call HasEval()')) 249 assert_equal("\nyes", execute('call HasEval()'))
250 let instr = execute('disassemble HasEval') 250 let instr = execute('disassemble HasEval')
251 assert_match('HasEval.*' 251 assert_match('HasEval.*'
252 \ .. 'if has("eval").*' 252 \ .. 'if has("eval").*'
253 \ .. ' PUSHS "yes".*' 253 \ .. ' PUSHS "yes".*'
282 def WithLambda(): string 282 def WithLambda(): string
283 let F = {a -> "X" .. a .. "X"} 283 let F = {a -> "X" .. a .. "X"}
284 return F("x") 284 return F("x")
285 enddef 285 enddef
286 286
287 def Test_compile_lambda() 287 def Test_disassemble_lambda()
288 assert_equal("XxX", WithLambda()) 288 assert_equal("XxX", WithLambda())
289 let instr = execute('disassemble WithLambda') 289 let instr = execute('disassemble WithLambda')
290 assert_match('WithLambda.*' 290 assert_match('WithLambda.*'
291 \ .. 'let F = {a -> "X" .. a .. "X"}.*' 291 \ .. 'let F = {a -> "X" .. a .. "X"}.*'
292 \ .. ' FUNCREF <lambda>\d\+.*' 292 \ .. ' FUNCREF <lambda>\d\+.*'
302 return 'yes' 302 return 'yes'
303 endif 303 endif
304 return 'no' 304 return 'no'
305 enddef 305 enddef
306 306
307 def Test_compile_and_or() 307 def Test_disassemble_and_or()
308 assert_equal("yes", AndOr(1)) 308 assert_equal("yes", AndOr(1))
309 assert_equal("no", AndOr(2)) 309 assert_equal("no", AndOr(2))
310 assert_equal("yes", AndOr(4)) 310 assert_equal("yes", AndOr(4))
311 let instr = execute('disassemble AndOr') 311 let instr = execute('disassemble AndOr')
312 assert_match('AndOr.*' 312 assert_match('AndOr.*'
332 res->add(i) 332 res->add(i)
333 endfor 333 endfor
334 return res 334 return res
335 enddef 335 enddef
336 336
337 def Test_compile_for_loop() 337 def Test_disassemble_for_loop()
338 assert_equal([0, 1, 2], ForLoop()) 338 assert_equal([0, 1, 2], ForLoop())
339 let instr = execute('disassemble ForLoop') 339 let instr = execute('disassemble ForLoop')
340 assert_match('ForLoop.*' 340 assert_match('ForLoop.*'
341 \ .. 'let res: list<number>.*' 341 \ .. 'let res: list<number>.*'
342 \ .. ' NEWLIST size 0.*' 342 \ .. ' NEWLIST size 0.*'
381 flres = fl * 7.0 381 flres = fl * 7.0
382 flres = fl / 7.0 382 flres = fl / 7.0
383 endif 383 endif
384 enddef 384 enddef
385 385
386 def Test_computing() 386 def Test_disassemble_computing()
387 let instr = execute('disassemble Computing') 387 let instr = execute('disassemble Computing')
388 assert_match('Computing.*' 388 assert_match('Computing.*'
389 \ .. 'let nr = 3.*' 389 \ .. 'let nr = 3.*'
390 \ .. '\d STORE 3 in $0.*' 390 \ .. '\d STORE 3 in $0.*'
391 \ .. 'let nrres = nr + 7.*' 391 \ .. 'let nrres = nr + 7.*'
433 \ .. '\d OPFLOAT /.*' 433 \ .. '\d OPFLOAT /.*'
434 \, instr) 434 \, instr)
435 endif 435 endif
436 enddef 436 enddef
437 437
438 def Test_disassemble_compare()
439 " TODO: COMPAREFUNC
440 let cases = [
441 \ ['true == false', 'COMPAREBOOL =='],
442 \ ['true != false', 'COMPAREBOOL !='],
443 \ ['v:none == v:null', 'COMPARESPECIAL =='],
444 \ ['v:none != v:null', 'COMPARESPECIAL !='],
445 \
446 \ ['111 == 222', 'COMPARENR =='],
447 \ ['111 != 222', 'COMPARENR !='],
448 \ ['111 > 222', 'COMPARENR >'],
449 \ ['111 < 222', 'COMPARENR <'],
450 \ ['111 >= 222', 'COMPARENR >='],
451 \ ['111 <= 222', 'COMPARENR <='],
452 \ ['111 =~ 222', 'COMPARENR =\~'],
453 \ ['111 !~ 222', 'COMPARENR !\~'],
454 \
455 \ ['"xx" == "yy"', 'COMPARESTRING =='],
456 \ ['"xx" != "yy"', 'COMPARESTRING !='],
457 \ ['"xx" > "yy"', 'COMPARESTRING >'],
458 \ ['"xx" < "yy"', 'COMPARESTRING <'],
459 \ ['"xx" >= "yy"', 'COMPARESTRING >='],
460 \ ['"xx" <= "yy"', 'COMPARESTRING <='],
461 \ ['"xx" =~ "yy"', 'COMPARESTRING =\~'],
462 \ ['"xx" !~ "yy"', 'COMPARESTRING !\~'],
463 \ ['"xx" is "yy"', 'COMPARESTRING is'],
464 \ ['"xx" isnot "yy"', 'COMPARESTRING isnot'],
465 \
466 \ ['0z11 == 0z22', 'COMPAREBLOB =='],
467 \ ['0z11 != 0z22', 'COMPAREBLOB !='],
468 \ ['0z11 is 0z22', 'COMPAREBLOB is'],
469 \ ['0z11 isnot 0z22', 'COMPAREBLOB isnot'],
470 \
471 \ ['[1,2] == [3,4]', 'COMPARELIST =='],
472 \ ['[1,2] != [3,4]', 'COMPARELIST !='],
473 \ ['[1,2] is [3,4]', 'COMPARELIST is'],
474 \ ['[1,2] isnot [3,4]', 'COMPARELIST isnot'],
475 \
476 \ ['#{a:1} == #{x:2}', 'COMPAREDICT =='],
477 \ ['#{a:1} != #{x:2}', 'COMPAREDICT !='],
478 \ ['#{a:1} is #{x:2}', 'COMPAREDICT is'],
479 \ ['#{a:1} isnot #{x:2}', 'COMPAREDICT isnot'],
480 \
481 \ ['{->33} == {->44}', 'COMPAREPARTIAL =='],
482 \ ['{->33} != {->44}', 'COMPAREPARTIAL !='],
483 \ ['{->33} is {->44}', 'COMPAREPARTIAL is'],
484 \ ['{->33} isnot {->44}', 'COMPAREPARTIAL isnot'],
485 \
486 \ ['77 == g:xx', 'COMPAREANY =='],
487 \ ['77 != g:xx', 'COMPAREANY !='],
488 \ ['77 > g:xx', 'COMPAREANY >'],
489 \ ['77 < g:xx', 'COMPAREANY <'],
490 \ ['77 >= g:xx', 'COMPAREANY >='],
491 \ ['77 <= g:xx', 'COMPAREANY <='],
492 \ ['77 =~ g:xx', 'COMPAREANY =\~'],
493 \ ['77 !~ g:xx', 'COMPAREANY !\~'],
494 \ ['77 is g:xx', 'COMPAREANY is'],
495 \ ['77 isnot g:xx', 'COMPAREANY isnot'],
496 \ ]
497 if has('float')
498 cases->extend([
499 \ ['1.1 == 2.2', 'COMPAREFLOAT =='],
500 \ ['1.1 != 2.2', 'COMPAREFLOAT !='],
501 \ ['1.1 > 2.2', 'COMPAREFLOAT >'],
502 \ ['1.1 < 2.2', 'COMPAREFLOAT <'],
503 \ ['1.1 >= 2.2', 'COMPAREFLOAT >='],
504 \ ['1.1 <= 2.2', 'COMPAREFLOAT <='],
505 \ ['1.1 =~ 2.2', 'COMPAREFLOAT =\~'],
506 \ ['1.1 !~ 2.2', 'COMPAREFLOAT !\~'],
507 \ ])
508 endif
509
510 let nr = 1
511 for case in cases
512 writefile(['def TestCase' .. nr .. '()',
513 \ ' if ' .. case[0],
514 \ ' echo 42'
515 \ ' endif',
516 \ 'enddef'], 'Xdisassemble')
517 source Xdisassemble
518 let instr = execute('disassemble TestCase' .. nr)
519 assert_match('TestCase' .. nr .. '.*'
520 \ .. 'if ' .. substitute(case[0], '[[~]', '\\\0', 'g') .. '.*'
521 \ .. '\d \(PUSH\|FUNCREF\).*'
522 \ .. '\d \(PUSH\|FUNCREF\|LOADG\).*'
523 \ .. '\d ' .. case[1] .. '.*'
524 \ .. '\d JUMP_IF_FALSE -> \d\+.*'
525 \, instr)
526
527 nr += 1
528 endfor
529
530 " delete('Xdisassemble')
531 enddef
532
438 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker 533 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker