Mercurial > vim
comparison src/testdir/test49.vim @ 7391:4761fed349ed v7.4.1000
commit https://github.com/vim/vim/commit/c06624661a3aa6642304c06db9cebe553a4cab17
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Dec 30 15:49:05 2015 +0100
patch 7.4.1000
Problem: Test 49 is slow and doesn't work on MS-Windows.
Solution: Start moving parts of test 49 to test_viml.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Wed, 30 Dec 2015 16:00:05 +0100 |
parents | d1e35ca56c73 |
children | 4ff843da79fd |
comparison
equal
deleted
inserted
replaced
7390:c6215e9d4b30 | 7391:4761fed349ed |
---|---|
1 " Vim script language tests | 1 " Vim script language tests |
2 " Author: Servatius Brandt <Servatius.Brandt@fujitsu-siemens.com> | 2 " Author: Servatius Brandt <Servatius.Brandt@fujitsu-siemens.com> |
3 " Last Change: 2015 Sep 25 | 3 " Last Change: 2015 Dec 30 |
4 | 4 |
5 "------------------------------------------------------------------------------- | 5 "------------------------------------------------------------------------------- |
6 " Test environment {{{1 | 6 " Test environment {{{1 |
7 "------------------------------------------------------------------------------- | 7 "------------------------------------------------------------------------------- |
8 | 8 |
606 | 606 |
607 | 607 |
608 " END_OF_TEST_ENVIRONMENT - do not change or remove this line. | 608 " END_OF_TEST_ENVIRONMENT - do not change or remove this line. |
609 | 609 |
610 | 610 |
611 "------------------------------------------------------------------------------- | 611 " Tests 1 to 6 were moved to test_viml.vim |
612 " Test 1: :endwhile in function {{{1 | 612 let Xtest = 7 |
613 " | |
614 " Detect if a broken loop is (incorrectly) reactivated by the | |
615 " :endwhile. Use a :return to prevent an endless loop, and make | |
616 " this test first to get a meaningful result on an error before other | |
617 " tests will hang. | |
618 "------------------------------------------------------------------------------- | |
619 | |
620 XpathINIT | |
621 | |
622 function! F() | |
623 Xpath 1 " X: 1 | |
624 let first = 1 | |
625 XloopINIT 2 8 | |
626 while 1 | |
627 Xloop 1 " X: 2 + 0 * 16 | |
628 if first | |
629 Xloop 2 " X: 4 + 0 * 32 | |
630 let first = 0 | |
631 XloopNEXT | |
632 break | |
633 else | |
634 Xloop 4 " X: 0 + 0 * 64 | |
635 return | |
636 endif | |
637 endwhile | |
638 endfunction | |
639 | |
640 call F() | |
641 Xpath 128 " X: 128 | |
642 | |
643 function! G() | |
644 Xpath 256 " X: 256 + 0 * 2048 | |
645 let first = 1 | |
646 XloopINIT 512 8 | |
647 while 1 | |
648 Xloop 1 " X: 512 + 0 * 4096 | |
649 if first | |
650 Xloop 2 " X: 1024 + 0 * 8192 | |
651 let first = 0 | |
652 XloopNEXT | |
653 break | |
654 else | |
655 Xloop 4 " X: 0 + 0 * 16384 | |
656 return | |
657 endif | |
658 if 1 " unmatched :if | |
659 endwhile | |
660 endfunction | |
661 | |
662 call G() | |
663 Xpath 32768 " X: 32768 | |
664 | |
665 Xcheck 34695 | |
666 | |
667 " Leave F and G for execution as scripts in the next test. | |
668 | |
669 | |
670 "------------------------------------------------------------------------------- | |
671 " Test 2: :endwhile in script {{{1 | |
672 " | |
673 " Detect if a broken loop is (incorrectly) reactivated by the | |
674 " :endwhile. Use a :finish to prevent an endless loop, and place | |
675 " this test before others that might hang to get a meaningful result | |
676 " on an error. | |
677 " | |
678 " This test executes the bodies of the functions F and G from the | |
679 " previous test as script files (:return replaced by :finish). | |
680 "------------------------------------------------------------------------------- | |
681 | |
682 XpathINIT | |
683 | |
684 ExecAsScript F " X: 1 + 2 + 4 | |
685 Xpath 128 " X: 128 | |
686 | |
687 ExecAsScript G " X: 256 + 512 + 1024 | |
688 Xpath 32768 " X: 32768 | |
689 | |
690 unlet first | |
691 delfunction F | |
692 delfunction G | |
693 | |
694 Xcheck 34695 | |
695 | |
696 | |
697 "------------------------------------------------------------------------------- | |
698 " Test 3: :if, :elseif, :while, :continue, :break {{{1 | |
699 "------------------------------------------------------------------------------- | |
700 | |
701 XpathINIT | |
702 if 1 | |
703 Xpath 1 " X: 1 | |
704 let loops = 3 | |
705 XloopINIT 2 512 | |
706 while loops > -1 " main loop: loops == 3, 2, 1 (which breaks) | |
707 if loops <= 0 | |
708 let break_err = 1 | |
709 let loops = -1 | |
710 else " 3: 2: 1: | |
711 Xloop 1 " X: 2 + 2*512 + 2*512*512 | |
712 endif | |
713 if (loops == 2) | |
714 while loops == 2 " dummy loop | |
715 Xloop 2 " X: 4*512 | |
716 let loops = loops - 1 | |
717 continue " stop dummy loop | |
718 Xloop 4 " X: 0 | |
719 endwhile | |
720 XloopNEXT | |
721 continue " continue main loop | |
722 Xloop 8 " X: 0 | |
723 elseif (loops == 1) | |
724 let p = 1 | |
725 while p " dummy loop | |
726 Xloop 16 " X: 32*512*512 | |
727 let p = 0 | |
728 break " break dummy loop | |
729 Xloop 32 " X: 0 | |
730 endwhile | |
731 Xloop 64 " X: 128*512*512 | |
732 unlet p | |
733 break " break main loop | |
734 Xloop 128 " X: 0 | |
735 endif | |
736 if (loops > 0) | |
737 Xloop 256 " X: 512 | |
738 endif | |
739 while loops == 3 " dummy loop | |
740 let loops = loops - 1 | |
741 endwhile " end dummy loop | |
742 XloopNEXT | |
743 endwhile " end main loop | |
744 Xpath 268435456 " X: 1024*512*512 | |
745 else | |
746 Xpath 536870912 " X: 0 | |
747 endif | |
748 Xpath 1073741824 " X: 4096*512*512 | |
749 if exists("break_err") | |
750 " The Xpath command does not accept 2^31 (negative); add explicitly: | |
751 let Xpath = Xpath + 2147483648 " X: 0 | |
752 unlet break_err | |
753 endif | |
754 | |
755 unlet loops | |
756 | |
757 Xcheck 1384648195 | |
758 | |
759 | |
760 "------------------------------------------------------------------------------- | |
761 " Test 4: :return {{{1 | |
762 "------------------------------------------------------------------------------- | |
763 | |
764 XpathINIT | |
765 | |
766 function! F() | |
767 if 1 | |
768 Xpath 1 " X: 1 | |
769 let loops = 3 | |
770 XloopINIT 2 16 | |
771 while loops > 0 " 3: 2: 1: | |
772 Xloop 1 " X: 2 + 2*16 + 0*16*16 | |
773 if (loops == 2) | |
774 Xloop 2 " X: 4*16 | |
775 return | |
776 Xloop 4 " X: 0 | |
777 endif | |
778 Xloop 8 " X: 16 | |
779 let loops = loops - 1 | |
780 XloopNEXT | |
781 endwhile | |
782 Xpath 8192 " X: 0 | |
783 else | |
784 Xpath 16384 " X: 0 | |
785 endif | |
786 endfunction | |
787 | |
788 call F() | |
789 Xpath 32768 " X: 8*16*16*16 | |
790 | |
791 Xcheck 32883 | |
792 | |
793 " Leave F for execution as a script in the next test. | |
794 | |
795 | |
796 "------------------------------------------------------------------------------- | |
797 " Test 5: :finish {{{1 | |
798 " | |
799 " This test executes the body of the function F from the previous test | |
800 " as a script file (:return replaced by :finish). | |
801 "------------------------------------------------------------------------------- | |
802 | |
803 XpathINIT | |
804 | |
805 ExecAsScript F " X: 1 + 2 + 2*16 + 4*16 + 16 | |
806 Xpath 32768 " X: 32768 | |
807 | |
808 unlet loops | |
809 delfunction F | |
810 | |
811 Xcheck 32883 | |
812 | |
813 | |
814 "------------------------------------------------------------------------------- | |
815 " Test 6: Defining functions in :while loops {{{1 | |
816 " | |
817 " Functions can be defined inside other functions. An inner function | |
818 " gets defined when the outer function is executed. Functions may | |
819 " also be defined inside while loops. Expressions in braces for | |
820 " defining the function name are allowed. | |
821 "------------------------------------------------------------------------------- | |
822 | |
823 XpathINIT | |
824 | |
825 if ExtraVim() | |
826 | |
827 " The command CALL collects the argument of all its invocations in "calls" | |
828 " when used from a function (that is, when the global variable "calls" needs | |
829 " the "g:" prefix). This is to check that the function code is skipped when | |
830 " the function is defined. For inner functions, do so only if the outer | |
831 " function is not being executed. | |
832 " | |
833 let calls = "" | |
834 com! -nargs=1 CALL | |
835 \ if !exists("calls") && !exists("outer") | | |
836 \ let g:calls = g:calls . <args> | | |
837 \ endif | |
838 | |
839 | |
840 XloopINIT! 1 16 | |
841 | |
842 let i = 0 | |
843 while i < 3 | |
844 | |
845 XloopNEXT | |
846 let i = i + 1 | |
847 | |
848 if i == 1 | |
849 Xloop 1 " X: 1 | |
850 function! F1(arg) | |
851 CALL a:arg | |
852 let outer = 1 | |
853 | |
854 XloopINIT! 4096 4 | |
855 let j = 0 | |
856 while j < 1 | |
857 XloopNEXT | |
858 Xloop 1 " X: 4096 | |
859 let j = j + 1 | |
860 function! G1(arg) | |
861 CALL a:arg | |
862 endfunction | |
863 Xloop 2 " X: 8192 | |
864 endwhile | |
865 endfunction | |
866 Xloop 2 " X: 2 | |
867 | |
868 continue | |
869 endif | |
870 | |
871 Xloop 4 " X: 4 * (16 + 256) | |
872 function! F{i}(i, arg) | |
873 CALL a:arg | |
874 let outer = 1 | |
875 | |
876 XloopINIT! 16384 4 | |
877 if a:i == 3 | |
878 XloopNEXT | |
879 XloopNEXT | |
880 XloopNEXT | |
881 endif | |
882 let k = 0 | |
883 while k < 3 | |
884 XloopNEXT | |
885 Xloop 1 " X: 16384*(1+4+16+64+256+1024) | |
886 let k = k + 1 | |
887 function! G{a:i}{k}(arg) | |
888 CALL a:arg | |
889 endfunction | |
890 Xloop 2 " X: 32768*(1+4+16+64+256+1024) | |
891 endwhile | |
892 endfunction | |
893 Xloop 8 " X: 8 * (16 + 256) | |
894 | |
895 endwhile | |
896 | |
897 if exists("*G1") | |
898 Xpath 67108864 " X: 0 | |
899 endif | |
900 if exists("*F1") | |
901 call F1("F1") | |
902 if exists("*G1") | |
903 call G1("G1") | |
904 endif | |
905 endif | |
906 | |
907 if exists("G21") || exists("G21") || exists("G21") | |
908 Xpath 134217728 " X: 0 | |
909 endif | |
910 if exists("*F2") | |
911 call F2(2, "F2") | |
912 if exists("*G21") | |
913 call G21("G21") | |
914 endif | |
915 if exists("*G22") | |
916 call G22("G22") | |
917 endif | |
918 if exists("*G23") | |
919 call G23("G23") | |
920 endif | |
921 endif | |
922 | |
923 if exists("G31") || exists("G31") || exists("G31") | |
924 Xpath 268435456 " X: 0 | |
925 endif | |
926 if exists("*F3") | |
927 call F3(3, "F3") | |
928 if exists("*G31") | |
929 call G31("G31") | |
930 endif | |
931 if exists("*G32") | |
932 call G32("G32") | |
933 endif | |
934 if exists("*G33") | |
935 call G33("G33") | |
936 endif | |
937 endif | |
938 | |
939 Xpath 536870912 " X: 536870912 | |
940 | |
941 if calls != "F1G1F2G21G22G23F3G31G32G33" | |
942 Xpath 1073741824 " X: 0 | |
943 Xout "calls is" calls | |
944 endif | |
945 | |
946 delfunction F1 | |
947 delfunction G1 | |
948 delfunction F2 | |
949 delfunction G21 | |
950 delfunction G22 | |
951 delfunction G23 | |
952 delfunction G31 | |
953 delfunction G32 | |
954 delfunction G33 | |
955 | |
956 endif | |
957 | |
958 Xcheck 603978947 | |
959 | |
960 | 613 |
961 "------------------------------------------------------------------------------- | 614 "------------------------------------------------------------------------------- |
962 " Test 7: Continuing on errors outside functions {{{1 | 615 " Test 7: Continuing on errors outside functions {{{1 |
963 " | 616 " |
964 " On an error outside a function, the script processing continues | 617 " On an error outside a function, the script processing continues |