comparison src/testdir/test_vim9_disassemble.vim @ 19439:b347a6c61090 v8.2.0277

patch 8.2.0277: Vim9: not all instructions covered by tests Commit: https://github.com/vim/vim/commit/ee2e52aa0655e02f900c74fb3a770bc55956d63d Author: Bram Moolenaar <Bram@vim.org> Date: Wed Feb 19 14:17:18 2020 +0100 patch 8.2.0277: Vim9: not all instructions covered by tests Problem: Vim9: not all instructions covered by tests. Solution: Add more test cases.
author Bram Moolenaar <Bram@vim.org>
date Wed, 19 Feb 2020 14:30:03 +0100
parents e4b326c9424a
children 0d3dcb4476ba
comparison
equal deleted inserted replaced
19438:c68854c20106 19439:b347a6c61090
435 \ .. '\d OPFLOAT \*.*' 435 \ .. '\d OPFLOAT \*.*'
436 \ .. 'flres = fl / 7.0.*' 436 \ .. 'flres = fl / 7.0.*'
437 \ .. '\d OPFLOAT /.*' 437 \ .. '\d OPFLOAT /.*'
438 \, instr) 438 \, instr)
439 endif 439 endif
440 enddef
441
442 def AddListBlob()
443 let reslist = [1, 2] + [3, 4]
444 let resblob = 0z1122 + 0z3344
445 enddef
446
447 def Test_disassemble_add_list_blob()
448 let instr = execute('disassemble AddListBlob')
449 assert_match('AddListBlob.*'
450 \ .. 'let reslist = \[1, 2] + \[3, 4].*'
451 \ .. '\d PUSHNR 1.*'
452 \ .. '\d PUSHNR 2.*'
453 \ .. '\d NEWLIST size 2.*'
454 \ .. '\d PUSHNR 3.*'
455 \ .. '\d PUSHNR 4.*'
456 \ .. '\d NEWLIST size 2.*'
457 \ .. '\d ADDLIST.*'
458 \ .. '\d STORE $.*.*'
459 \ .. 'let resblob = 0z1122 + 0z3344.*'
460 \ .. '\d PUSHBLOB 0z1122.*'
461 \ .. '\d PUSHBLOB 0z3344.*'
462 \ .. '\d ADDBLOB.*'
463 \ .. '\d STORE $.*'
464 \, instr)
465 enddef
466
467 let g:aa = 'aa'
468 def ConcatString(): string
469 let res = g:aa .. "bb"
470 return res
471 enddef
472
473 def Test_disassemble_concat()
474 let instr = execute('disassemble ConcatString')
475 assert_match('ConcatString.*'
476 \ .. 'let res = g:aa .. "bb".*'
477 \ .. '\d LOADG g:aa.*'
478 \ .. '\d PUSHS "bb".*'
479 \ .. '\d 2STRING stack\[-2].*'
480 \ .. '\d CONCAT.*'
481 \ .. '\d STORE $.*'
482 \, instr)
483 assert_equal('aabb', ConcatString())
484 enddef
485
486 def ListIndex(): number
487 let l = [1, 2, 3]
488 let res = l[1]
489 return res
490 enddef
491
492 def Test_disassemble_list_index()
493 let instr = execute('disassemble ListIndex')
494 assert_match('ListIndex.*'
495 \ .. 'let l = \[1, 2, 3].*'
496 \ .. '\d PUSHNR 1.*'
497 \ .. '\d PUSHNR 2.*'
498 \ .. '\d PUSHNR 3.*'
499 \ .. '\d NEWLIST size 3.*'
500 \ .. '\d STORE $0.*'
501 \ .. 'let res = l\[1].*'
502 \ .. '\d LOAD $0.*'
503 \ .. '\d PUSHNR 1.*'
504 \ .. '\d INDEX.*'
505 \ .. '\d STORE $1.*'
506 \, instr)
507 assert_equal(2, ListIndex())
508 enddef
509
510 def DictMember(): number
511 let d = #{item: 1}
512 let res = d.item
513 return res
514 enddef
515
516 def Test_disassemble_dict_member()
517 let instr = execute('disassemble DictMember')
518 assert_match('DictMember.*'
519 \ .. 'let d = #{item: 1}.*'
520 \ .. '\d PUSHS "item".*'
521 \ .. '\d PUSHNR 1.*'
522 \ .. '\d NEWDICT size 1.*'
523 \ .. '\d STORE $0.*'
524 \ .. 'let res = d.item.*'
525 \ .. '\d LOAD $0.*'
526 \ .. '\d MEMBER item.*'
527 \ .. '\d STORE $1.*'
528 \, instr)
529 call assert_equal(1, DictMember())
530 enddef
531
532 def NegateNumber(): number
533 let nr = 9
534 let plus = +nr
535 let res = -nr
536 return res
537 enddef
538
539 def Test_disassemble_negate_number()
540 let instr = execute('disassemble NegateNumber')
541 assert_match('NegateNumber.*'
542 \ .. 'let nr = 9.*'
543 \ .. '\d STORE 9 in $0.*'
544 \ .. 'let plus = +nr.*'
545 \ .. '\d LOAD $0.*'
546 \ .. '\d CHECKNR.*'
547 \ .. '\d STORE $1.*'
548 \ .. 'let res = -nr.*'
549 \ .. '\d LOAD $0.*'
550 \ .. '\d NEGATENR.*'
551 \ .. '\d STORE $2.*'
552 \, instr)
553 call assert_equal(-9, NegateNumber())
554 enddef
555
556 def InvertBool(): bool
557 let flag = true
558 let invert = !flag
559 let res = !!flag
560 return res
561 enddef
562
563 def Test_disassemble_invert_bool()
564 let instr = execute('disassemble InvertBool')
565 assert_match('InvertBool.*'
566 \ .. 'let flag = true.*'
567 \ .. '\d PUSH v:true.*'
568 \ .. '\d STORE $0.*'
569 \ .. 'let invert = !flag.*'
570 \ .. '\d LOAD $0.*'
571 \ .. '\d INVERT (!val).*'
572 \ .. '\d STORE $1.*'
573 \ .. 'let res = !!flag.*'
574 \ .. '\d LOAD $0.*'
575 \ .. '\d 2BOOL (!!val).*'
576 \ .. '\d STORE $2.*'
577 \, instr)
578 call assert_equal(true, InvertBool())
440 enddef 579 enddef
441 580
442 def Test_disassemble_compare() 581 def Test_disassemble_compare()
443 " TODO: COMPAREFUNC 582 " TODO: COMPAREFUNC
444 let cases = [ 583 let cases = [