Mercurial > vim
comparison src/testdir/test_vim9_script.vim @ 19330:9c8b803fe598 v8.2.0223
patch 8.2.0223: some instructions not yet tested
Commit: https://github.com/vim/vim/commit/5cab73f8cca46d831fb9337b176493da2a55ed5d
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Feb 6 19:25:19 2020 +0100
patch 8.2.0223: some instructions not yet tested
Problem: Some instructions not yet tested.
Solution: Disassemble more instructions. Move tests to a new file. Compile
call to s:function().
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 06 Feb 2020 19:30:08 +0100 |
parents | e99e6d794597 |
children | d6e8a9e80be4 |
comparison
equal
deleted
inserted
replaced
19329:f49020e6bf12 | 19330:9c8b803fe598 |
---|---|
487 assert_notmatch('PUSHS "yes"', instr) | 487 assert_notmatch('PUSHS "yes"', instr) |
488 assert_match('PUSHS "no"', instr) | 488 assert_match('PUSHS "no"', instr) |
489 assert_notmatch('JUMP', instr) | 489 assert_notmatch('JUMP', instr) |
490 enddef | 490 enddef |
491 | 491 |
492 func NotCompiled() | |
493 echo "not" | |
494 endfunc | |
495 | |
496 let s:scriptvar = 4 | |
497 let g:globalvar = 'g' | |
498 | |
499 def s:ScriptFuncLoad(arg: string) | |
500 let local = 1 | |
501 buffers | |
502 echo arg | |
503 echo local | |
504 echo v:version | |
505 echo s:scriptvar | |
506 echo g:globalvar | |
507 echo &tabstop | |
508 echo $ENVVAR | |
509 echo @z | |
510 enddef | |
511 | |
512 def Test_disassembleLoad() | |
513 assert_fails('disass NoFunc', 'E1061:') | |
514 assert_fails('disass NotCompiled', 'E1062:') | |
515 | |
516 let res = execute('disass s:ScriptFuncLoad') | |
517 assert_match('<SNR>\d*_ScriptFuncLoad.*' | |
518 \ .. 'buffers.*' | |
519 \ .. ' EXEC \+buffers.*' | |
520 \ .. ' LOAD arg\[-1\].*' | |
521 \ .. ' LOAD $0.*' | |
522 \ .. ' LOADV v:version.*' | |
523 \ .. ' LOADS s:scriptvar from .*test_vim9_script.vim.*' | |
524 \ .. ' LOADG g:globalvar.*' | |
525 \ .. ' LOADENV $ENVVAR.*' | |
526 \ .. ' LOADREG @z.*' | |
527 \, res) | |
528 enddef | |
529 | |
530 def s:ScriptFuncPush() | |
531 let localbool = true | |
532 let localspec = v:none | |
533 let localblob = 0z1234 | |
534 if has('float') | |
535 let localfloat = 1.234 | |
536 endif | |
537 enddef | |
538 | |
539 def Test_disassemblePush() | |
540 let res = execute('disass s:ScriptFuncPush') | |
541 assert_match('<SNR>\d*_ScriptFuncPush.*' | |
542 \ .. 'localbool = true.*' | |
543 \ .. ' PUSH v:true.*' | |
544 \ .. 'localspec = v:none.*' | |
545 \ .. ' PUSH v:none.*' | |
546 \ .. 'localblob = 0z1234.*' | |
547 \ .. ' PUSHBLOB 0z1234.*' | |
548 \, res) | |
549 if has('float') | |
550 assert_match('<SNR>\d*_ScriptFuncPush.*' | |
551 \ .. 'localfloat = 1.234.*' | |
552 \ .. ' PUSHF 1.234.*' | |
553 \, res) | |
554 endif | |
555 enddef | |
556 | |
557 def s:ScriptFuncStore() | |
558 let localnr = 1 | |
559 localnr = 2 | |
560 let localstr = 'abc' | |
561 localstr = 'xyz' | |
562 v:char = 'abc' | |
563 s:scriptvar = 'sv' | |
564 g:globalvar = 'gv' | |
565 &tabstop = 8 | |
566 $ENVVAR = 'ev' | |
567 @z = 'rv' | |
568 enddef | |
569 | |
570 def Test_disassembleStore() | |
571 let res = execute('disass s:ScriptFuncStore') | |
572 assert_match('<SNR>\d*_ScriptFuncStore.*' | |
573 \ .. 'localnr = 2.*' | |
574 \ .. ' STORE 2 in $0.*' | |
575 \ .. 'localstr = ''xyz''.*' | |
576 \ .. ' STORE $1.*' | |
577 \ .. 'v:char = ''abc''.*' | |
578 \ .. 'STOREV v:char.*' | |
579 \ .. 's:scriptvar = ''sv''.*' | |
580 \ .. ' STORES s:scriptvar in .*test_vim9_script.vim.*' | |
581 \ .. 'g:globalvar = ''gv''.*' | |
582 \ .. ' STOREG g:globalvar.*' | |
583 \ .. '&tabstop = 8.*' | |
584 \ .. ' STOREOPT &tabstop.*' | |
585 \ .. '$ENVVAR = ''ev''.*' | |
586 \ .. ' STOREENV $ENVVAR.*' | |
587 \ .. '@z = ''rv''.*' | |
588 \ .. ' STOREREG @z.*' | |
589 \, res) | |
590 enddef | |
591 | |
592 def s:ScriptFuncTry() | |
593 try | |
594 echo 'yes' | |
595 catch /fail/ | |
596 echo 'no' | |
597 finally | |
598 echo 'end' | |
599 endtry | |
600 enddef | |
601 | |
602 def Test_disassembleTry() | |
603 let res = execute('disass s:ScriptFuncTry') | |
604 assert_match('<SNR>\d*_ScriptFuncTry.*' | |
605 \ .. 'try.*' | |
606 \ .. 'TRY catch -> \d\+, finally -> \d\+.*' | |
607 \ .. 'catch /fail/.*' | |
608 \ .. ' JUMP -> \d\+.*' | |
609 \ .. ' PUSH v:exception.*' | |
610 \ .. ' PUSHS "fail".*' | |
611 \ .. ' COMPARESTRING =\~.*' | |
612 \ .. ' JUMP_IF_FALSE -> \d\+.*' | |
613 \ .. ' CATCH.*' | |
614 \ .. 'finally.*' | |
615 \ .. ' PUSHS "end".*' | |
616 \ .. 'endtry.*' | |
617 \ .. ' ENDTRY.*' | |
618 \, res) | |
619 enddef | |
620 | |
621 def s:ScriptFuncNew() | |
622 let ll = [1, "two", 333] | |
623 let dd = #{one: 1, two: "val"} | |
624 enddef | |
625 | |
626 def Test_disassembleNew() | |
627 let res = execute('disass s:ScriptFuncNew') | |
628 assert_match('<SNR>\d*_ScriptFuncNew.*' | |
629 \ .. 'let ll = \[1, "two", 333].*' | |
630 \ .. 'PUSHNR 1.*' | |
631 \ .. 'PUSHS "two".*' | |
632 \ .. 'PUSHNR 333.*' | |
633 \ .. 'NEWLIST size 3.*' | |
634 \ .. 'let dd = #{one: 1, two: "val"}.*' | |
635 \ .. 'PUSHS "one".*' | |
636 \ .. 'PUSHNR 1.*' | |
637 \ .. 'PUSHS "two".*' | |
638 \ .. 'PUSHS "val".*' | |
639 \ .. 'NEWDICT size 2.*' | |
640 \, res) | |
641 enddef | |
642 | |
643 def FuncWithArg(arg) | |
644 echo arg | |
645 enddef | |
646 | |
647 func UserFunc() | |
648 echo 'nothing' | |
649 endfunc | |
650 | |
651 func UserFuncWithArg(arg) | |
652 echo a:arg | |
653 endfunc | |
654 | |
655 def s:ScriptFuncCall(): string | |
656 changenr() | |
657 char2nr("abc") | |
658 Test_disassembleNew() | |
659 FuncWithArg(343) | |
660 UserFunc() | |
661 UserFuncWithArg("foo") | |
662 let FuncRef = function("UserFunc") | |
663 FuncRef() | |
664 let FuncRefWithArg = function("UserFuncWithArg") | |
665 FuncRefWithArg("bar") | |
666 return "yes" | |
667 enddef | |
668 | |
669 def Test_disassembleCall() | |
670 let res = execute('disass s:ScriptFuncCall') | |
671 assert_match('<SNR>\d*_ScriptFuncCall.*' | |
672 \ .. 'changenr().*' | |
673 \ .. ' BCALL changenr(argc 0).*' | |
674 \ .. 'char2nr("abc").*' | |
675 \ .. ' PUSHS "abc".*' | |
676 \ .. ' BCALL char2nr(argc 1).*' | |
677 \ .. 'Test_disassembleNew().*' | |
678 \ .. ' DCALL Test_disassembleNew(argc 0).*' | |
679 \ .. 'FuncWithArg(343).*' | |
680 \ .. ' PUSHNR 343.*' | |
681 \ .. ' DCALL FuncWithArg(argc 1).*' | |
682 \ .. 'UserFunc().*' | |
683 \ .. ' UCALL UserFunc(argc 0).*' | |
684 \ .. 'UserFuncWithArg("foo").*' | |
685 \ .. ' PUSHS "foo".*' | |
686 \ .. ' UCALL UserFuncWithArg(argc 1).*' | |
687 \ .. 'let FuncRef = function("UserFunc").*' | |
688 \ .. 'FuncRef().*' | |
689 \ .. ' LOAD $\d.*' | |
690 \ .. ' PCALL (argc 0).*' | |
691 \ .. 'let FuncRefWithArg = function("UserFuncWithArg").*' | |
692 \ .. 'FuncRefWithArg("bar").*' | |
693 \ .. ' PUSHS "bar".*' | |
694 \ .. ' LOAD $\d.*' | |
695 \ .. ' PCALL (argc 1).*' | |
696 \ .. 'return "yes".*' | |
697 \ .. ' PUSHS "yes".*' | |
698 \ .. ' RETURN.*' | |
699 \, res) | |
700 enddef | |
701 | |
702 | 492 |
703 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker | 493 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker |