comparison src/testdir/test_vim9_script.vim @ 19320:6e199d1d11d0 v8.2.0218

patch 8.2.0218: several Vim9 instructions are not tested Commit: https://github.com/vim/vim/commit/0de50864a78d8811aa9adef3318027c9bab40a90 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Feb 5 22:55:48 2020 +0100 patch 8.2.0218: several Vim9 instructions are not tested Problem: Several Vim9 instructions are not tested. Solution: Add more tests.
author Bram Moolenaar <Bram@vim.org>
date Wed, 05 Feb 2020 23:00:04 +0100
parents 17dc6282f370
children d1810b726592
comparison
equal deleted inserted replaced
19319:c5f04bfc7bf6 19320:6e199d1d11d0
472 echo &tabstop 472 echo &tabstop
473 echo $ENVVAR 473 echo $ENVVAR
474 echo @z 474 echo @z
475 enddef 475 enddef
476 476
477 def s:ScriptFuncPush() 477 def Test_disassembleLoad()
478 let localbool = true
479 let localspec = v:none
480 let localblob = 0z1234
481 if has('float')
482 let localfloat = 1.234
483 endif
484 enddef
485
486 def s:ScriptFuncStore()
487 let localnr = 1
488 localnr = 2
489 let localstr = 'abc'
490 localstr = 'xyz'
491 v:char = 'abc'
492 s:scriptvar = 'sv'
493 g:globalvar = 'gv'
494 &tabstop = 8
495 $ENVVAR = 'ev'
496 @z = 'rv'
497 enddef
498
499 def s:ScriptFuncTry()
500 try
501 echo 'yes'
502 catch /fail/
503 echo 'no'
504 finally
505 echo 'end'
506 endtry
507 enddef
508
509 def Test_disassemble()
510 assert_fails('disass NoFunc', 'E1061:') 478 assert_fails('disass NoFunc', 'E1061:')
511 assert_fails('disass NotCompiled', 'E1062:') 479 assert_fails('disass NotCompiled', 'E1062:')
512 480
513 let res = execute('disass s:ScriptFuncLoad') 481 let res = execute('disass s:ScriptFuncLoad')
514 assert_match('<SNR>\d*_ScriptFuncLoad.*' 482 assert_match('<SNR>\d*_ScriptFuncLoad.*'
520 \ .. ' LOADS s:scriptvar from .*test_vim9_script.vim.*' 488 \ .. ' LOADS s:scriptvar from .*test_vim9_script.vim.*'
521 \ .. ' LOADG g:globalvar.*' 489 \ .. ' LOADG g:globalvar.*'
522 \ .. ' LOADENV $ENVVAR.*' 490 \ .. ' LOADENV $ENVVAR.*'
523 \ .. ' LOADREG @z.*' 491 \ .. ' LOADREG @z.*'
524 \, res) 492 \, res)
525 493 enddef
526 res = execute('disass s:ScriptFuncPush') 494
495 def s:ScriptFuncPush()
496 let localbool = true
497 let localspec = v:none
498 let localblob = 0z1234
499 if has('float')
500 let localfloat = 1.234
501 endif
502 enddef
503
504 def Test_disassemblePush()
505 let res = execute('disass s:ScriptFuncPush')
527 assert_match('<SNR>\d*_ScriptFuncPush.*' 506 assert_match('<SNR>\d*_ScriptFuncPush.*'
528 \ .. 'localbool = true.*' 507 \ .. 'localbool = true.*'
529 \ .. ' PUSH v:true.*' 508 \ .. ' PUSH v:true.*'
530 \ .. 'localspec = v:none.*' 509 \ .. 'localspec = v:none.*'
531 \ .. ' PUSH v:none.*' 510 \ .. ' PUSH v:none.*'
536 assert_match('<SNR>\d*_ScriptFuncPush.*' 515 assert_match('<SNR>\d*_ScriptFuncPush.*'
537 \ .. 'localfloat = 1.234.*' 516 \ .. 'localfloat = 1.234.*'
538 \ .. ' PUSHF 1.234.*' 517 \ .. ' PUSHF 1.234.*'
539 \, res) 518 \, res)
540 endif 519 endif
541 520 enddef
542 res = execute('disass s:ScriptFuncStore') 521
522 def s:ScriptFuncStore()
523 let localnr = 1
524 localnr = 2
525 let localstr = 'abc'
526 localstr = 'xyz'
527 v:char = 'abc'
528 s:scriptvar = 'sv'
529 g:globalvar = 'gv'
530 &tabstop = 8
531 $ENVVAR = 'ev'
532 @z = 'rv'
533 enddef
534
535 def Test_disassembleStore()
536 let res = execute('disass s:ScriptFuncStore')
543 assert_match('<SNR>\d*_ScriptFuncStore.*' 537 assert_match('<SNR>\d*_ScriptFuncStore.*'
544 \ .. 'localnr = 2.*' 538 \ .. 'localnr = 2.*'
545 \ .. ' STORE 2 in $0.*' 539 \ .. ' STORE 2 in $0.*'
546 \ .. 'localstr = ''xyz''.*' 540 \ .. 'localstr = ''xyz''.*'
547 \ .. ' STORE $1.*' 541 \ .. ' STORE $1.*'
556 \ .. '$ENVVAR = ''ev''.*' 550 \ .. '$ENVVAR = ''ev''.*'
557 \ .. ' STOREENV $ENVVAR.*' 551 \ .. ' STOREENV $ENVVAR.*'
558 \ .. '@z = ''rv''.*' 552 \ .. '@z = ''rv''.*'
559 \ .. ' STOREREG @z.*' 553 \ .. ' STOREREG @z.*'
560 \, res) 554 \, res)
561 555 enddef
562 res = execute('disass s:ScriptFuncTry') 556
557 def s:ScriptFuncTry()
558 try
559 echo 'yes'
560 catch /fail/
561 echo 'no'
562 finally
563 echo 'end'
564 endtry
565 enddef
566
567 def Test_disassembleTry()
568 let res = execute('disass s:ScriptFuncTry')
563 assert_match('<SNR>\d*_ScriptFuncTry.*' 569 assert_match('<SNR>\d*_ScriptFuncTry.*'
564 \ .. 'try.*' 570 \ .. 'try.*'
565 \ .. 'TRY catch -> \d\+, finally -> \d\+.*' 571 \ .. 'TRY catch -> \d\+, finally -> \d\+.*'
566 \ .. 'catch /fail/.*' 572 \ .. 'catch /fail/.*'
567 \ .. ' JUMP -> \d\+.*' 573 \ .. ' JUMP -> \d\+.*'
575 \ .. 'endtry.*' 581 \ .. 'endtry.*'
576 \ .. ' ENDTRY.*' 582 \ .. ' ENDTRY.*'
577 \, res) 583 \, res)
578 enddef 584 enddef
579 585
586 def s:ScriptFuncNew()
587 let ll = [1, "two", 333]
588 let dd = #{one: 1, two: "val"}
589 enddef
590
591 def Test_disassembleNew()
592 let res = execute('disass s:ScriptFuncNew')
593 assert_match('<SNR>\d*_ScriptFuncNew.*'
594 \ .. 'let ll = \[1, "two", 333].*'
595 \ .. 'PUSHNR 1.*'
596 \ .. 'PUSHS "two".*'
597 \ .. 'PUSHNR 333.*'
598 \ .. 'NEWLIST size 3.*'
599 \ .. 'let dd = #{one: 1, two: "val"}.*'
600 \ .. 'PUSHS "one".*'
601 \ .. 'PUSHNR 1.*'
602 \ .. 'PUSHS "two".*'
603 \ .. 'PUSHS "val".*'
604 \ .. 'NEWDICT size 2.*'
605 \, res)
606 enddef
607
608 def FuncWithArg(arg)
609 echo arg
610 enddef
611
612 func UserFunc()
613 echo 'nothing'
614 endfunc
615
616 func UserFuncWithArg(arg)
617 echo a:arg
618 endfunc
619
620 def s:ScriptFuncCall(): string
621 changenr()
622 char2nr("abc")
623 Test_disassembleNew()
624 FuncWithArg(343)
625 UserFunc()
626 UserFuncWithArg("foo")
627 let FuncRef = function("UserFunc")
628 FuncRef()
629 let FuncRefWithArg = function("UserFuncWithArg")
630 FuncRefWithArg("bar")
631 return "yes"
632 enddef
633
634 def Test_disassembleCall()
635 let res = execute('disass s:ScriptFuncCall')
636 assert_match('<SNR>\d*_ScriptFuncCall.*'
637 \ .. 'changenr().*'
638 \ .. ' BCALL changenr(argc 0).*'
639 \ .. 'char2nr("abc").*'
640 \ .. ' PUSHS "abc".*'
641 \ .. ' BCALL char2nr(argc 1).*'
642 \ .. 'Test_disassembleNew().*'
643 \ .. ' DCALL Test_disassembleNew(argc 0).*'
644 \ .. 'FuncWithArg(343).*'
645 \ .. ' PUSHNR 343.*'
646 \ .. ' DCALL FuncWithArg(argc 1).*'
647 \ .. 'UserFunc().*'
648 \ .. ' UCALL UserFunc(argc 0).*'
649 \ .. 'UserFuncWithArg("foo").*'
650 \ .. ' PUSHS "foo".*'
651 \ .. ' UCALL UserFuncWithArg(argc 1).*'
652 \ .. 'let FuncRef = function("UserFunc").*'
653 \ .. 'FuncRef().*'
654 \ .. ' LOAD $\d.*'
655 \ .. ' PCALL (argc 0).*'
656 \ .. 'let FuncRefWithArg = function("UserFuncWithArg").*'
657 \ .. 'FuncRefWithArg("bar").*'
658 \ .. ' PUSHS "bar".*'
659 \ .. ' LOAD $\d.*'
660 \ .. ' PCALL (argc 1).*'
661 \ .. 'return "yes".*'
662 \ .. ' PUSHS "yes".*'
663 \ .. ' RETURN.*'
664 \, res)
665 enddef
666
580 667
581 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker 668 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker