comparison src/testdir/test49.vim @ 21632:792398a9fe39 v8.2.1366

patch 8.2.1366: test 49 is old style Commit: https://github.com/vim/vim/commit/a6296200bd5191bab7efcdcc16c9e79eb498e8e0 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Aug 5 11:23:13 2020 +0200 patch 8.2.1366: test 49 is old style Problem: Test 49 is old style. Solution: Convert several tests to new style. (Yegappan Lakshmanan, closes #6629)
author Bram Moolenaar <Bram@vim.org>
date Wed, 05 Aug 2020 11:30:03 +0200
parents eff8d8f72a82
children 97b887aecd4a
comparison
equal deleted inserted replaced
21631:e55aba8c2146 21632:792398a9fe39
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: 2019 Nov 03 3 " Last Change: 2020 Jun 07
4 4
5 "------------------------------------------------------------------------------- 5 "-------------------------------------------------------------------------------
6 " Test environment {{{1 6 " Test environment {{{1
7 "------------------------------------------------------------------------------- 7 "-------------------------------------------------------------------------------
8 8
605 " EXTRA_VIM_STOP - do not change or remove this line. 605 " EXTRA_VIM_STOP - do not change or remove this line.
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 " Tests 1 to 50, 87 were moved to test_vimscript.vim
611 " Tests 1 to 17 were moved to test_vimscript.vim 611 " Tests 25, 26, 32, 33, 41-48, 51, 69-75 were moved to test_trycatch.vim
612 let Xtest = 18
613
614 "-------------------------------------------------------------------------------
615 " Test 18: Interrupt (Ctrl-C pressed) {{{1
616 "
617 " On an interrupt, the script processing is terminated immediately.
618 "-------------------------------------------------------------------------------
619
620 XpathINIT
621
622 if ExtraVim()
623 if 1
624 Xpath 1 " X: 1
625 while 1
626 Xpath 2 " X: 2
627 if 1
628 Xpath 4 " X: 4
629 "INTERRUPT
630 Xpath 8 " X: 0
631 break
632 finish
633 endif | Xpath 16 " X: 0
634 Xpath 32 " X: 0
635 endwhile | Xpath 64 " X: 0
636 Xpath 128 " X: 0
637 endif | Xpath 256 " X: 0
638 Xpath 512 " X: 0
639 endif
640
641 if ExtraVim()
642 try
643 Xpath 1024 " X: 1024
644 "INTERRUPT
645 Xpath 2048 " X: 0
646 endtry | Xpath 4096 " X: 0
647 Xpath 8192 " X: 0
648 endif
649
650 if ExtraVim()
651 function! F()
652 if 1
653 Xpath 16384 " X: 16384
654 while 1
655 Xpath 32768 " X: 32768
656 if 1
657 Xpath 65536 " X: 65536
658 "INTERRUPT
659 Xpath 131072 " X: 0
660 break
661 return
662 endif | Xpath 262144 " X: 0
663 Xpath Xpath 524288 " X: 0
664 endwhile | Xpath 1048576 " X: 0
665 Xpath Xpath 2097152 " X: 0
666 endif | Xpath Xpath 4194304 " X: 0
667 Xpath Xpath 8388608 " X: 0
668 endfunction
669
670 call F() | Xpath 16777216 " X: 0
671 Xpath 33554432 " X: 0
672 endif
673
674 if ExtraVim()
675 function! G()
676 try
677 Xpath 67108864 " X: 67108864
678 "INTERRUPT
679 Xpath 134217728 " X: 0
680 endtry | Xpath 268435456 " X: 0
681 Xpath 536870912 " X: 0
682 endfunction
683
684 call G() | Xpath 1073741824 " X: 0
685 " The Xpath command does not accept 2^31 (negative); display explicitly:
686 exec "!echo 2147483648 >>" . g:ExtraVimResult
687 " X: 0
688 endif
689
690 Xcheck 67224583
691
692
693 "-------------------------------------------------------------------------------
694 " Test 19: Aborting on errors inside :try/:endtry {{{1
695 "
696 " An error in a command dynamically enclosed in a :try/:endtry region
697 " aborts script processing immediately. It does not matter whether
698 " the failing command is outside or inside a function and whether a
699 " function has an "abort" attribute.
700 "-------------------------------------------------------------------------------
701
702 XpathINIT
703
704 if ExtraVim()
705 function! F() abort
706 Xpath 1 " X: 1
707 asdf
708 Xpath 2 " X: 0
709 endfunction
710
711 try
712 Xpath 4 " X: 4
713 call F()
714 Xpath 8 " X: 0
715 endtry | Xpath 16 " X: 0
716 Xpath 32 " X: 0
717 endif
718
719 if ExtraVim()
720 function! G()
721 Xpath 64 " X: 64
722 asdf
723 Xpath 128 " X: 0
724 endfunction
725
726 try
727 Xpath 256 " X: 256
728 call G()
729 Xpath 512 " X: 0
730 endtry | Xpath 1024 " X: 0
731 Xpath 2048 " X: 0
732 endif
733
734 if ExtraVim()
735 try
736 Xpath 4096 " X: 4096
737 asdf
738 Xpath 8192 " X: 0
739 endtry | Xpath 16384 " X: 0
740 Xpath 32768 " X: 0
741 endif
742
743 if ExtraVim()
744 if 1
745 try
746 Xpath 65536 " X: 65536
747 asdf
748 Xpath 131072 " X: 0
749 endtry | Xpath 262144 " X: 0
750 endif | Xpath 524288 " X: 0
751 Xpath 1048576 " X: 0
752 endif
753
754 if ExtraVim()
755 let p = 1
756 while p
757 let p = 0
758 try
759 Xpath 2097152 " X: 2097152
760 asdf
761 Xpath 4194304 " X: 0
762 endtry | Xpath 8388608 " X: 0
763 endwhile | Xpath 16777216 " X: 0
764 Xpath 33554432 " X: 0
765 endif
766
767 if ExtraVim()
768 let p = 1
769 while p
770 let p = 0
771 " try
772 Xpath 67108864 " X: 67108864
773 endwhile | Xpath 134217728 " X: 0
774 Xpath 268435456 " X: 0
775 endif
776
777 Xcheck 69275973
778 "-------------------------------------------------------------------------------
779 " Test 20: Aborting on errors after :try/:endtry {{{1
780 "
781 " When an error occurs after the last active :try/:endtry region has
782 " been left, termination behavior is as if no :try/:endtry has been
783 " seen.
784 "-------------------------------------------------------------------------------
785
786 XpathINIT
787
788 if ExtraVim()
789 let p = 1
790 while p
791 let p = 0
792 try
793 Xpath 1 " X: 1
794 endtry
795 asdf
796 endwhile | Xpath 2 " X: 0
797 Xpath 4 " X: 4
798 endif
799
800 if ExtraVim()
801 while 1
802 try
803 Xpath 8 " X: 8
804 break
805 Xpath 16 " X: 0
806 endtry
807 endwhile
808 Xpath 32 " X: 32
809 asdf
810 Xpath 64 " X: 64
811 endif
812
813 if ExtraVim()
814 while 1
815 try
816 Xpath 128 " X: 128
817 break
818 Xpath 256 " X: 0
819 finally
820 Xpath 512 " X: 512
821 endtry
822 endwhile
823 Xpath 1024 " X: 1024
824 asdf
825 Xpath 2048 " X: 2048
826 endif
827
828 if ExtraVim()
829 while 1
830 try
831 Xpath 4096 " X: 4096
832 finally
833 Xpath 8192 " X: 8192
834 break
835 Xpath 16384 " X: 0
836 endtry
837 endwhile
838 Xpath 32768 " X: 32768
839 asdf
840 Xpath 65536 " X: 65536
841 endif
842
843 if ExtraVim()
844 let p = 1
845 while p
846 let p = 0
847 try
848 Xpath 131072 " X: 131072
849 continue
850 Xpath 262144 " X: 0
851 endtry
852 endwhile
853 Xpath 524288 " X: 524288
854 asdf
855 Xpath 1048576 " X: 1048576
856 endif
857
858 if ExtraVim()
859 let p = 1
860 while p
861 let p = 0
862 try
863 Xpath 2097152 " X: 2097152
864 continue
865 Xpath 4194304 " X: 0
866 finally
867 Xpath 8388608 " X: 8388608
868 endtry
869 endwhile
870 Xpath 16777216 " X: 16777216
871 asdf
872 Xpath 33554432 " X: 33554432
873 endif
874
875 if ExtraVim()
876 let p = 1
877 while p
878 let p = 0
879 try
880 Xpath 67108864 " X: 67108864
881 finally
882 Xpath 134217728 " X: 134217728
883 continue
884 Xpath 268435456 " X: 0
885 endtry
886 endwhile
887 Xpath 536870912 " X: 536870912
888 asdf
889 Xpath 1073741824 " X: 1073741824
890 endif
891
892 Xcheck 1874575085
893
894
895 "-------------------------------------------------------------------------------
896 " Test 21: :finally for :try after :continue/:break/:return/:finish {{{1
897 "
898 " If a :try conditional stays inactive due to a preceding :continue,
899 " :break, :return, or :finish, its :finally clause should not be
900 " executed.
901 "-------------------------------------------------------------------------------
902
903 XpathINIT
904
905 if ExtraVim()
906 function F()
907 let loops = 2
908 XloopINIT! 1 256
909 while loops > 0
910 XloopNEXT
911 let loops = loops - 1
912 try
913 if loops == 1
914 Xloop 1 " X: 1
915 continue
916 Xloop 2 " X: 0
917 elseif loops == 0
918 Xloop 4 " X: 4*256
919 break
920 Xloop 8 " X: 0
921 endif
922
923 try " inactive
924 Xloop 16 " X: 0
925 finally
926 Xloop 32 " X: 0
927 endtry
928 finally
929 Xloop 64 " X: 64 + 64*256
930 endtry
931 Xloop 128 " X: 0
932 endwhile
933
934 try
935 Xpath 65536 " X: 65536
936 return
937 Xpath 131072 " X: 0
938 try " inactive
939 Xpath 262144 " X: 0
940 finally
941 Xpath 524288 " X: 0
942 endtry
943 finally
944 Xpath 1048576 " X: 1048576
945 endtry
946 Xpath 2097152 " X: 0
947 endfunction
948
949 try
950 Xpath 4194304 " X: 4194304
951 call F()
952 Xpath 8388608 " X: 8388608
953 finish
954 Xpath 16777216 " X: 0
955 try " inactive
956 Xpath 33554432 " X: 0
957 finally
958 Xpath 67108864 " X: 0
959 endtry
960 finally
961 Xpath 134217728 " X: 134217728
962 endtry
963 Xpath 268435456 " X: 0
964 endif
965
966 Xcheck 147932225
967
968
969 "-------------------------------------------------------------------------------
970 " Test 22: :finally for a :try after an error/interrupt/:throw {{{1
971 "
972 " If a :try conditional stays inactive due to a preceding error or
973 " interrupt or :throw, its :finally clause should not be executed.
974 "-------------------------------------------------------------------------------
975
976 XpathINIT
977
978 if ExtraVim()
979 function! Error()
980 try
981 asdf " aborting error, triggering error exception
982 endtry
983 endfunction
984
985 Xpath 1 " X: 1
986 call Error()
987 Xpath 2 " X: 0
988
989 if 1 " not active due to error
990 try " not active since :if inactive
991 Xpath 4 " X: 0
992 finally
993 Xpath 8 " X: 0
994 endtry
995 endif
996
997 try " not active due to error
998 Xpath 16 " X: 0
999 finally
1000 Xpath 32 " X: 0
1001 endtry
1002 endif
1003
1004 if ExtraVim()
1005 function! Interrupt()
1006 try
1007 "INTERRUPT " triggering interrupt exception
1008 endtry
1009 endfunction
1010
1011 Xpath 64 " X: 64
1012 call Interrupt()
1013 Xpath 128 " X: 0
1014
1015 if 1 " not active due to interrupt
1016 try " not active since :if inactive
1017 Xpath 256 " X: 0
1018 finally
1019 Xpath 512 " X: 0
1020 endtry
1021 endif
1022
1023 try " not active due to interrupt
1024 Xpath 1024 " X: 0
1025 finally
1026 Xpath 2048 " X: 0
1027 endtry
1028 endif
1029
1030 if ExtraVim()
1031 function! Throw()
1032 throw "xyz"
1033 endfunction
1034
1035 Xpath 4096 " X: 4096
1036 call Throw()
1037 Xpath 8192 " X: 0
1038
1039 if 1 " not active due to :throw
1040 try " not active since :if inactive
1041 Xpath 16384 " X: 0
1042 finally
1043 Xpath 32768 " X: 0
1044 endtry
1045 endif
1046
1047 try " not active due to :throw
1048 Xpath 65536 " X: 0
1049 finally
1050 Xpath 131072 " X: 0
1051 endtry
1052 endif
1053
1054 Xcheck 4161
1055
1056
1057 "-------------------------------------------------------------------------------
1058 " Test 23: :catch clauses for a :try after a :throw {{{1
1059 "
1060 " If a :try conditional stays inactive due to a preceding :throw,
1061 " none of its :catch clauses should be executed.
1062 "-------------------------------------------------------------------------------
1063
1064 XpathINIT
1065
1066 if ExtraVim()
1067 try
1068 Xpath 1 " X: 1
1069 throw "xyz"
1070 Xpath 2 " X: 0
1071
1072 if 1 " not active due to :throw
1073 try " not active since :if inactive
1074 Xpath 4 " X: 0
1075 catch /xyz/
1076 Xpath 8 " X: 0
1077 endtry
1078 endif
1079 catch /xyz/
1080 Xpath 16 " X: 16
1081 endtry
1082
1083 Xpath 32 " X: 32
1084 throw "abc"
1085 Xpath 64 " X: 0
1086
1087 try " not active due to :throw
1088 Xpath 128 " X: 0
1089 catch /abc/
1090 Xpath 256 " X: 0
1091 endtry
1092 endif
1093
1094 Xcheck 49
1095
1096
1097 "-------------------------------------------------------------------------------
1098 " Test 24: :endtry for a :try after a :throw {{{1
1099 "
1100 " If a :try conditional stays inactive due to a preceding :throw,
1101 " its :endtry should not rethrow the exception to the next surrounding
1102 " active :try conditional.
1103 "-------------------------------------------------------------------------------
1104
1105 XpathINIT
1106
1107 if ExtraVim()
1108 try " try 1
1109 try " try 2
1110 Xpath 1 " X: 1
1111 throw "xyz" " makes try 2 inactive
1112 Xpath 2 " X: 0
1113
1114 try " try 3
1115 Xpath 4 " X: 0
1116 endtry " no rethrow to try 1
1117 catch /xyz/ " should catch although try 2 inactive
1118 Xpath 8 " X: 8
1119 endtry
1120 catch /xyz/ " try 1 active, but exception already caught
1121 Xpath 16 " X: 0
1122 endtry
1123 Xpath 32 " X: 32
1124 endif
1125
1126 Xcheck 41
1127
1128 " Tests 25 and 26 were moved to test_trycatch.vim
1129 let Xtest = 27
1130
1131
1132 "-------------------------------------------------------------------------------
1133 " Test 27: Executing :finally clauses after :return {{{1
1134 "
1135 " For a :return command dynamically enclosed in a :try/:endtry region,
1136 " :finally clauses are executed and the called function is ended.
1137 "-------------------------------------------------------------------------------
1138
1139 XpathINIT
1140
1141 function! F()
1142 try
1143 Xpath 1 " X: 1
1144 try
1145 Xpath 2 " X: 2
1146 return
1147 Xpath 4 " X: 0
1148 finally
1149 Xpath 8 " X: 8
1150 endtry
1151 Xpath 16 " X: 0
1152 finally
1153 Xpath 32 " X: 32
1154 endtry
1155 Xpath 64 " X: 0
1156 endfunction
1157
1158 function! G()
1159 try
1160 Xpath 128 " X: 128
1161 return
1162 Xpath 256 " X: 0
1163 finally
1164 Xpath 512 " X: 512
1165 call F()
1166 Xpath 1024 " X: 1024
1167 endtry
1168 Xpath 2048 " X: 0
1169 endfunction
1170
1171 function! H()
1172 try
1173 Xpath 4096 " X: 4096
1174 call G()
1175 Xpath 8192 " X: 8192
1176 finally
1177 Xpath 16384 " X: 16384
1178 return
1179 Xpath 32768 " X: 0
1180 endtry
1181 Xpath 65536 " X: 0
1182 endfunction
1183
1184 try
1185 Xpath 131072 " X: 131072
1186 call H()
1187 Xpath 262144 " X: 262144
1188 finally
1189 Xpath 524288 " X: 524288
1190 endtry
1191 Xpath 1048576 " X: 1048576
1192
1193 Xcheck 1996459
1194
1195 " Leave F, G, and H for execution as scripts in the next test.
1196
1197
1198 "-------------------------------------------------------------------------------
1199 " Test 28: Executing :finally clauses after :finish {{{1
1200 "
1201 " For a :finish command dynamically enclosed in a :try/:endtry region,
1202 " :finally clauses are executed and the sourced file is finished.
1203 "
1204 " This test executes the bodies of the functions F, G, and H from the
1205 " previous test as script files (:return replaced by :finish).
1206 "-------------------------------------------------------------------------------
1207
1208 XpathINIT
1209
1210 let scriptF = MakeScript("F") " X: 1 + 2 + 8 + 32
1211 let scriptG = MakeScript("G", scriptF) " X: 128 + 512 + 1024
1212 let scriptH = MakeScript("H", scriptG) " X: 4096 + 8192 + 16384
1213
1214 try
1215 Xpath 131072 " X: 131072
1216 exec "source" scriptH
1217 Xpath 262144 " X: 262144
1218 finally
1219 Xpath 524288 " X: 524288
1220 endtry
1221 Xpath 1048576 " X: 1048576
1222
1223 call delete(scriptF)
1224 call delete(scriptG)
1225 call delete(scriptH)
1226 unlet scriptF scriptG scriptH
1227 delfunction F
1228 delfunction G
1229 delfunction H
1230
1231 Xcheck 1996459
1232
1233
1234 "-------------------------------------------------------------------------------
1235 " Test 29: Executing :finally clauses on errors {{{1
1236 "
1237 " After an error in a command dynamically enclosed in a :try/:endtry
1238 " region, :finally clauses are executed and the script processing is
1239 " terminated.
1240 "-------------------------------------------------------------------------------
1241
1242 XpathINIT
1243
1244 if ExtraVim()
1245 function! F()
1246 while 1
1247 try
1248 Xpath 1 " X: 1
1249 while 1
1250 try
1251 Xpath 2 " X: 2
1252 asdf " error
1253 Xpath 4 " X: 0
1254 finally
1255 Xpath 8 " X: 8
1256 endtry | Xpath 16 " X: 0
1257 Xpath 32 " X: 0
1258 break
1259 endwhile
1260 Xpath 64 " X: 0
1261 finally
1262 Xpath 128 " X: 128
1263 endtry | Xpath 256 " X: 0
1264 Xpath 512 " X: 0
1265 break
1266 endwhile
1267 Xpath 1024 " X: 0
1268 endfunction
1269
1270 while 1
1271 try
1272 Xpath 2048 " X: 2048
1273 while 1
1274 call F()
1275 Xpath 4096 " X: 0
1276 break
1277 endwhile | Xpath 8192 " X: 0
1278 Xpath 16384 " X: 0
1279 finally
1280 Xpath 32768 " X: 32768
1281 endtry | Xpath 65536 " X: 0
1282 endwhile | Xpath 131072 " X: 0
1283 Xpath 262144 " X: 0
1284 endif
1285
1286 if ExtraVim()
1287 function! G() abort
1288 if 1
1289 try
1290 Xpath 524288 " X: 524288
1291 asdf " error
1292 Xpath 1048576 " X: 0
1293 finally
1294 Xpath 2097152 " X: 2097152
1295 endtry | Xpath 4194304 " X: 0
1296 endif | Xpath 8388608 " X: 0
1297 Xpath 16777216 " X: 0
1298 endfunction
1299
1300 if 1
1301 try
1302 Xpath 33554432 " X: 33554432
1303 call G()
1304 Xpath 67108864 " X: 0
1305 finally
1306 Xpath 134217728 " X: 134217728
1307 endtry | Xpath 268435456 " X: 0
1308 endif | Xpath 536870912 " X: 0
1309 Xpath 1073741824 " X: 0
1310 endif
1311
1312 Xcheck 170428555
1313
1314
1315 "-------------------------------------------------------------------------------
1316 " Test 30: Executing :finally clauses on interrupt {{{1
1317 "
1318 " After an interrupt in a command dynamically enclosed in
1319 " a :try/:endtry region, :finally clauses are executed and the
1320 " script processing is terminated.
1321 "-------------------------------------------------------------------------------
1322
1323 XpathINIT
1324
1325 if ExtraVim()
1326 XloopINIT 1 16
1327
1328 function! F()
1329 try
1330 Xloop 1 " X: 1 + 1*16
1331 "INTERRUPT
1332 Xloop 2 " X: 0
1333 finally
1334 Xloop 4 " X: 4 + 4*16
1335 endtry
1336 Xloop 8 " X: 0
1337 endfunction
1338
1339 try
1340 Xpath 256 " X: 256
1341 try
1342 Xpath 512 " X: 512
1343 "INTERRUPT
1344 Xpath 1024 " X: 0
1345 finally
1346 Xpath 2048 " X: 2048
1347 try
1348 Xpath 4096 " X: 4096
1349 try
1350 Xpath 8192 " X: 8192
1351 finally
1352 Xpath 16384 " X: 16384
1353 try
1354 Xpath 32768 " X: 32768
1355 "INTERRUPT
1356 Xpath 65536 " X: 0
1357 endtry
1358 Xpath 131072 " X: 0
1359 endtry
1360 Xpath 262144 " X: 0
1361 endtry
1362 Xpath 524288 " X: 0
1363 endtry
1364 Xpath 1048576 " X: 0
1365 finally
1366 Xpath 2097152 " X: 2097152
1367 try
1368 Xpath 4194304 " X: 4194304
1369 call F()
1370 Xpath 8388608 " X: 0
1371 finally
1372 Xpath 16777216 " X: 16777216
1373 try
1374 Xpath 33554432 " X: 33554432
1375 XloopNEXT
1376 ExecAsScript F
1377 Xpath 67108864 " X: 0
1378 finally
1379 Xpath 134217728 " X: 134217728
1380 endtry
1381 Xpath 268435456 " X: 0
1382 endtry
1383 Xpath 536870912 " X: 0
1384 endtry
1385 Xpath 1073741824 " X: 0
1386 endif
1387
1388 Xcheck 190905173
1389
1390
1391 "-------------------------------------------------------------------------------
1392 " Test 31: Executing :finally clauses after :throw {{{1
1393 "
1394 " After a :throw dynamically enclosed in a :try/:endtry region,
1395 " :finally clauses are executed and the script processing is
1396 " terminated.
1397 "-------------------------------------------------------------------------------
1398
1399 XpathINIT
1400
1401 if ExtraVim()
1402 XloopINIT 1 16
1403
1404 function! F()
1405 try
1406 Xloop 1 " X: 1 + 1*16
1407 throw "exception"
1408 Xloop 2 " X: 0
1409 finally
1410 Xloop 4 " X: 4 + 4*16
1411 endtry
1412 Xloop 8 " X: 0
1413 endfunction
1414
1415 try
1416 Xpath 256 " X: 256
1417 try
1418 Xpath 512 " X: 512
1419 throw "exception"
1420 Xpath 1024 " X: 0
1421 finally
1422 Xpath 2048 " X: 2048
1423 try
1424 Xpath 4096 " X: 4096
1425 try
1426 Xpath 8192 " X: 8192
1427 finally
1428 Xpath 16384 " X: 16384
1429 try
1430 Xpath 32768 " X: 32768
1431 throw "exception"
1432 Xpath 65536 " X: 0
1433 endtry
1434 Xpath 131072 " X: 0
1435 endtry
1436 Xpath 262144 " X: 0
1437 endtry
1438 Xpath 524288 " X: 0
1439 endtry
1440 Xpath 1048576 " X: 0
1441 finally
1442 Xpath 2097152 " X: 2097152
1443 try
1444 Xpath 4194304 " X: 4194304
1445 call F()
1446 Xpath 8388608 " X: 0
1447 finally
1448 Xpath 16777216 " X: 16777216
1449 try
1450 Xpath 33554432 " X: 33554432
1451 XloopNEXT
1452 ExecAsScript F
1453 Xpath 67108864 " X: 0
1454 finally
1455 Xpath 134217728 " X: 134217728
1456 endtry
1457 Xpath 268435456 " X: 0
1458 endtry
1459 Xpath 536870912 " X: 0
1460 endtry
1461 Xpath 1073741824 " X: 0
1462 endif
1463
1464 Xcheck 190905173
1465
1466 " Tests 32 and 33 were moved to test_trycatch.vim
1467 let Xtest = 34
1468
1469
1470 "-------------------------------------------------------------------------------
1471 " Test 34: :finally reason discarded by :continue {{{1
1472 "
1473 " When a :finally clause is executed due to a :continue, :break,
1474 " :return, :finish, error, interrupt or :throw, the jump reason is
1475 " discarded by a :continue in the finally clause.
1476 "-------------------------------------------------------------------------------
1477
1478 XpathINIT
1479
1480 if ExtraVim()
1481
1482 XloopINIT! 1 8
1483
1484 function! C(jump)
1485 XloopNEXT
1486 let loop = 0
1487 while loop < 2
1488 let loop = loop + 1
1489 if loop == 1
1490 try
1491 if a:jump == "continue"
1492 continue
1493 elseif a:jump == "break"
1494 break
1495 elseif a:jump == "return" || a:jump == "finish"
1496 return
1497 elseif a:jump == "error"
1498 asdf
1499 elseif a:jump == "interrupt"
1500 "INTERRUPT
1501 let dummy = 0
1502 elseif a:jump == "throw"
1503 throw "abc"
1504 endif
1505 finally
1506 continue " discards jump that caused the :finally
1507 Xloop 1 " X: 0
1508 endtry
1509 Xloop 2 " X: 0
1510 elseif loop == 2
1511 Xloop 4 " X: 4*(1+8+64+512+4096+32768+262144)
1512 endif
1513 endwhile
1514 endfunction
1515
1516 call C("continue")
1517 Xpath 2097152 " X: 2097152
1518 call C("break")
1519 Xpath 4194304 " X: 4194304
1520 call C("return")
1521 Xpath 8388608 " X: 8388608
1522 let g:jump = "finish"
1523 ExecAsScript C
1524 unlet g:jump
1525 Xpath 16777216 " X: 16777216
1526 try
1527 call C("error")
1528 Xpath 33554432 " X: 33554432
1529 finally
1530 Xpath 67108864 " X: 67108864
1531 try
1532 call C("interrupt")
1533 Xpath 134217728 " X: 134217728
1534 finally
1535 Xpath 268435456 " X: 268435456
1536 call C("throw")
1537 Xpath 536870912 " X: 536870912
1538 endtry
1539 endtry
1540 Xpath 1073741824 " X: 1073741824
1541
1542 delfunction C
1543
1544 endif
1545
1546 Xcheck 2146584868
1547
1548
1549 "-------------------------------------------------------------------------------
1550 " Test 35: :finally reason discarded by :break {{{1
1551 "
1552 " When a :finally clause is executed due to a :continue, :break,
1553 " :return, :finish, error, interrupt or :throw, the jump reason is
1554 " discarded by a :break in the finally clause.
1555 "-------------------------------------------------------------------------------
1556
1557 XpathINIT
1558
1559 if ExtraVim()
1560
1561 XloopINIT! 1 8
1562
1563 function! B(jump)
1564 XloopNEXT
1565 let loop = 0
1566 while loop < 2
1567 let loop = loop + 1
1568 if loop == 1
1569 try
1570 if a:jump == "continue"
1571 continue
1572 elseif a:jump == "break"
1573 break
1574 elseif a:jump == "return" || a:jump == "finish"
1575 return
1576 elseif a:jump == "error"
1577 asdf
1578 elseif a:jump == "interrupt"
1579 "INTERRUPT
1580 let dummy = 0
1581 elseif a:jump == "throw"
1582 throw "abc"
1583 endif
1584 finally
1585 break " discards jump that caused the :finally
1586 Xloop 1 " X: 0
1587 endtry
1588 elseif loop == 2
1589 Xloop 2 " X: 0
1590 endif
1591 endwhile
1592 Xloop 4 " X: 4*(1+8+64+512+4096+32768+262144)
1593 endfunction
1594
1595 call B("continue")
1596 Xpath 2097152 " X: 2097152
1597 call B("break")
1598 Xpath 4194304 " X: 4194304
1599 call B("return")
1600 Xpath 8388608 " X: 8388608
1601 let g:jump = "finish"
1602 ExecAsScript B
1603 unlet g:jump
1604 Xpath 16777216 " X: 16777216
1605 try
1606 call B("error")
1607 Xpath 33554432 " X: 33554432
1608 finally
1609 Xpath 67108864 " X: 67108864
1610 try
1611 call B("interrupt")
1612 Xpath 134217728 " X: 134217728
1613 finally
1614 Xpath 268435456 " X: 268435456
1615 call B("throw")
1616 Xpath 536870912 " X: 536870912
1617 endtry
1618 endtry
1619 Xpath 1073741824 " X: 1073741824
1620
1621 delfunction B
1622
1623 endif
1624
1625 Xcheck 2146584868
1626
1627
1628 "-------------------------------------------------------------------------------
1629 " Test 36: :finally reason discarded by :return {{{1
1630 "
1631 " When a :finally clause is executed due to a :continue, :break,
1632 " :return, :finish, error, interrupt or :throw, the jump reason is
1633 " discarded by a :return in the finally clause.
1634 "-------------------------------------------------------------------------------
1635
1636 XpathINIT
1637
1638 if ExtraVim()
1639
1640 XloopINIT! 1 8
1641
1642 function! R(jump, retval) abort
1643 XloopNEXT
1644 let loop = 0
1645 while loop < 2
1646 let loop = loop + 1
1647 if loop == 1
1648 try
1649 if a:jump == "continue"
1650 continue
1651 elseif a:jump == "break"
1652 break
1653 elseif a:jump == "return"
1654 return
1655 elseif a:jump == "error"
1656 asdf
1657 elseif a:jump == "interrupt"
1658 "INTERRUPT
1659 let dummy = 0
1660 elseif a:jump == "throw"
1661 throw "abc"
1662 endif
1663 finally
1664 return a:retval " discards jump that caused the :finally
1665 Xloop 1 " X: 0
1666 endtry
1667 elseif loop == 2
1668 Xloop 2 " X: 0
1669 endif
1670 endwhile
1671 Xloop 4 " X: 0
1672 endfunction
1673
1674 let sum = -R("continue", -8)
1675 Xpath 2097152 " X: 2097152
1676 let sum = sum - R("break", -16)
1677 Xpath 4194304 " X: 4194304
1678 let sum = sum - R("return", -32)
1679 Xpath 8388608 " X: 8388608
1680 try
1681 let sum = sum - R("error", -64)
1682 Xpath 16777216 " X: 16777216
1683 finally
1684 Xpath 33554432 " X: 33554432
1685 try
1686 let sum = sum - R("interrupt", -128)
1687 Xpath 67108864 " X: 67108864
1688 finally
1689 Xpath 134217728 " X: 134217728
1690 let sum = sum - R("throw", -256)
1691 Xpath 268435456 " X: 268435456
1692 endtry
1693 endtry
1694 Xpath 536870912 " X: 536870912
1695
1696 let expected = 8 + 16 + 32 + 64 + 128 + 256
1697 if sum != expected
1698 Xpath 1073741824 " X: 0
1699 Xout "sum =" . sum . ", expected: " . expected
1700 endif
1701
1702 unlet sum expected
1703 delfunction R
1704
1705 endif
1706
1707 Xcheck 1071644672
1708
1709
1710 "-------------------------------------------------------------------------------
1711 " Test 37: :finally reason discarded by :finish {{{1
1712 "
1713 " When a :finally clause is executed due to a :continue, :break,
1714 " :return, :finish, error, interrupt or :throw, the jump reason is
1715 " discarded by a :finish in the finally clause.
1716 "-------------------------------------------------------------------------------
1717
1718 XpathINIT
1719
1720 if ExtraVim()
1721
1722 XloopINIT! 1 8
1723
1724 function! F(jump) " not executed as function, transformed to a script
1725 XloopNEXT
1726 let loop = 0
1727 while loop < 2
1728 let loop = loop + 1
1729 if loop == 1
1730 try
1731 if a:jump == "continue"
1732 continue
1733 elseif a:jump == "break"
1734 break
1735 elseif a:jump == "finish"
1736 finish
1737 elseif a:jump == "error"
1738 asdf
1739 elseif a:jump == "interrupt"
1740 "INTERRUPT
1741 let dummy = 0
1742 elseif a:jump == "throw"
1743 throw "abc"
1744 endif
1745 finally
1746 finish " discards jump that caused the :finally
1747 Xloop 1 " X: 0
1748 endtry
1749 elseif loop == 2
1750 Xloop 2 " X: 0
1751 endif
1752 endwhile
1753 Xloop 4 " X: 0
1754 endfunction
1755
1756 let scriptF = MakeScript("F")
1757 delfunction F
1758
1759 let g:jump = "continue"
1760 exec "source" scriptF
1761 Xpath 2097152 " X: 2097152
1762 let g:jump = "break"
1763 exec "source" scriptF
1764 Xpath 4194304 " X: 4194304
1765 let g:jump = "finish"
1766 exec "source" scriptF
1767 Xpath 8388608 " X: 8388608
1768 try
1769 let g:jump = "error"
1770 exec "source" scriptF
1771 Xpath 16777216 " X: 16777216
1772 finally
1773 Xpath 33554432 " X: 33554432
1774 try
1775 let g:jump = "interrupt"
1776 exec "source" scriptF
1777 Xpath 67108864 " X: 67108864
1778 finally
1779 Xpath 134217728 " X: 134217728
1780 try
1781 let g:jump = "throw"
1782 exec "source" scriptF
1783 Xpath 268435456 " X: 268435456
1784 finally
1785 Xpath 536870912 " X: 536870912
1786 endtry
1787 endtry
1788 endtry
1789 unlet g:jump
1790
1791 call delete(scriptF)
1792 unlet scriptF
1793
1794 endif
1795
1796 Xcheck 1071644672
1797
1798
1799 "-------------------------------------------------------------------------------
1800 " Test 38: :finally reason discarded by an error {{{1
1801 "
1802 " When a :finally clause is executed due to a :continue, :break,
1803 " :return, :finish, error, interrupt or :throw, the jump reason is
1804 " discarded by an error in the finally clause.
1805 "-------------------------------------------------------------------------------
1806
1807 XpathINIT
1808
1809 if ExtraVim()
1810
1811 XloopINIT! 1 4
1812
1813 function! E(jump)
1814 XloopNEXT
1815 let loop = 0
1816 while loop < 2
1817 let loop = loop + 1
1818 if loop == 1
1819 try
1820 if a:jump == "continue"
1821 continue
1822 elseif a:jump == "break"
1823 break
1824 elseif a:jump == "return" || a:jump == "finish"
1825 return
1826 elseif a:jump == "error"
1827 asdf
1828 elseif a:jump == "interrupt"
1829 "INTERRUPT
1830 let dummy = 0
1831 elseif a:jump == "throw"
1832 throw "abc"
1833 endif
1834 finally
1835 asdf " error; discards jump that caused the :finally
1836 endtry
1837 elseif loop == 2
1838 Xloop 1 " X: 0
1839 endif
1840 endwhile
1841 Xloop 2 " X: 0
1842 endfunction
1843
1844 try
1845 Xpath 16384 " X: 16384
1846 call E("continue")
1847 Xpath 32768 " X: 0
1848 finally
1849 try
1850 Xpath 65536 " X: 65536
1851 call E("break")
1852 Xpath 131072 " X: 0
1853 finally
1854 try
1855 Xpath 262144 " X: 262144
1856 call E("return")
1857 Xpath 524288 " X: 0
1858 finally
1859 try
1860 Xpath 1048576 " X: 1048576
1861 let g:jump = "finish"
1862 ExecAsScript E
1863 Xpath 2097152 " X: 0
1864 finally
1865 unlet g:jump
1866 try
1867 Xpath 4194304 " X: 4194304
1868 call E("error")
1869 Xpath 8388608 " X: 0
1870 finally
1871 try
1872 Xpath 16777216 " X: 16777216
1873 call E("interrupt")
1874 Xpath 33554432 " X: 0
1875 finally
1876 try
1877 Xpath 67108864 " X: 67108864
1878 call E("throw")
1879 Xpath 134217728 " X: 0
1880 finally
1881 Xpath 268435456 " X: 268435456
1882 delfunction E
1883 endtry
1884 endtry
1885 endtry
1886 endtry
1887 endtry
1888 endtry
1889 endtry
1890 Xpath 536870912 " X: 0
1891
1892 endif
1893
1894 Xcheck 357908480
1895
1896
1897 "-------------------------------------------------------------------------------
1898 " Test 39: :finally reason discarded by an interrupt {{{1
1899 "
1900 " When a :finally clause is executed due to a :continue, :break,
1901 " :return, :finish, error, interrupt or :throw, the jump reason is
1902 " discarded by an interrupt in the finally clause.
1903 "-------------------------------------------------------------------------------
1904
1905 XpathINIT
1906
1907 if ExtraVim()
1908
1909 XloopINIT! 1 4
1910
1911 function! I(jump)
1912 XloopNEXT
1913 let loop = 0
1914 while loop < 2
1915 let loop = loop + 1
1916 if loop == 1
1917 try
1918 if a:jump == "continue"
1919 continue
1920 elseif a:jump == "break"
1921 break
1922 elseif a:jump == "return" || a:jump == "finish"
1923 return
1924 elseif a:jump == "error"
1925 asdf
1926 elseif a:jump == "interrupt"
1927 "INTERRUPT
1928 let dummy = 0
1929 elseif a:jump == "throw"
1930 throw "abc"
1931 endif
1932 finally
1933 "INTERRUPT - discards jump that caused the :finally
1934 let dummy = 0
1935 endtry
1936 elseif loop == 2
1937 Xloop 1 " X: 0
1938 endif
1939 endwhile
1940 Xloop 2 " X: 0
1941 endfunction
1942
1943 try
1944 Xpath 16384 " X: 16384
1945 call I("continue")
1946 Xpath 32768 " X: 0
1947 finally
1948 try
1949 Xpath 65536 " X: 65536
1950 call I("break")
1951 Xpath 131072 " X: 0
1952 finally
1953 try
1954 Xpath 262144 " X: 262144
1955 call I("return")
1956 Xpath 524288 " X: 0
1957 finally
1958 try
1959 Xpath 1048576 " X: 1048576
1960 let g:jump = "finish"
1961 ExecAsScript I
1962 Xpath 2097152 " X: 0
1963 finally
1964 unlet g:jump
1965 try
1966 Xpath 4194304 " X: 4194304
1967 call I("error")
1968 Xpath 8388608 " X: 0
1969 finally
1970 try
1971 Xpath 16777216 " X: 16777216
1972 call I("interrupt")
1973 Xpath 33554432 " X: 0
1974 finally
1975 try
1976 Xpath 67108864 " X: 67108864
1977 call I("throw")
1978 Xpath 134217728 " X: 0
1979 finally
1980 Xpath 268435456 " X: 268435456
1981 delfunction I
1982 endtry
1983 endtry
1984 endtry
1985 endtry
1986 endtry
1987 endtry
1988 endtry
1989 Xpath 536870912 " X: 0
1990
1991 endif
1992
1993 Xcheck 357908480
1994
1995
1996 "-------------------------------------------------------------------------------
1997 " Test 40: :finally reason discarded by :throw {{{1
1998 "
1999 " When a :finally clause is executed due to a :continue, :break,
2000 " :return, :finish, error, interrupt or :throw, the jump reason is
2001 " discarded by a :throw in the finally clause.
2002 "-------------------------------------------------------------------------------
2003
2004 XpathINIT
2005
2006 if ExtraVim()
2007
2008 XloopINIT! 1 4
2009
2010 function! T(jump)
2011 XloopNEXT
2012 let loop = 0
2013 while loop < 2
2014 let loop = loop + 1
2015 if loop == 1
2016 try
2017 if a:jump == "continue"
2018 continue
2019 elseif a:jump == "break"
2020 break
2021 elseif a:jump == "return" || a:jump == "finish"
2022 return
2023 elseif a:jump == "error"
2024 asdf
2025 elseif a:jump == "interrupt"
2026 "INTERRUPT
2027 let dummy = 0
2028 elseif a:jump == "throw"
2029 throw "abc"
2030 endif
2031 finally
2032 throw "xyz" " discards jump that caused the :finally
2033 endtry
2034 elseif loop == 2
2035 Xloop 1 " X: 0
2036 endif
2037 endwhile
2038 Xloop 2 " X: 0
2039 endfunction
2040
2041 try
2042 Xpath 16384 " X: 16384
2043 call T("continue")
2044 Xpath 32768 " X: 0
2045 finally
2046 try
2047 Xpath 65536 " X: 65536
2048 call T("break")
2049 Xpath 131072 " X: 0
2050 finally
2051 try
2052 Xpath 262144 " X: 262144
2053 call T("return")
2054 Xpath 524288 " X: 0
2055 finally
2056 try
2057 Xpath 1048576 " X: 1048576
2058 let g:jump = "finish"
2059 ExecAsScript T
2060 Xpath 2097152 " X: 0
2061 finally
2062 unlet g:jump
2063 try
2064 Xpath 4194304 " X: 4194304
2065 call T("error")
2066 Xpath 8388608 " X: 0
2067 finally
2068 try
2069 Xpath 16777216 " X: 16777216
2070 call T("interrupt")
2071 Xpath 33554432 " X: 0
2072 finally
2073 try
2074 Xpath 67108864 " X: 67108864
2075 call T("throw")
2076 Xpath 134217728 " X: 0
2077 finally
2078 Xpath 268435456 " X: 268435456
2079 delfunction T
2080 endtry
2081 endtry
2082 endtry
2083 endtry
2084 endtry
2085 endtry
2086 endtry
2087 Xpath 536870912 " X: 0
2088
2089 endif
2090
2091 Xcheck 357908480
2092
2093 " Tests 41 to 48 were moved to test_trycatch.vim
2094 let Xtest = 49
2095
2096
2097 "-------------------------------------------------------------------------------
2098 " Test 49: Throwing exceptions across functions {{{1
2099 "
2100 " When an exception is thrown but not caught inside a function, the
2101 " caller is checked for a matching :catch clause.
2102 "-------------------------------------------------------------------------------
2103
2104 XpathINIT
2105
2106 function! C()
2107 try
2108 Xpath 1 " X: 1
2109 throw "arrgh"
2110 Xpath 2 " X: 0
2111 catch /arrgh/
2112 Xpath 4 " X: 4
2113 endtry
2114 Xpath 8 " X: 8
2115 endfunction
2116
2117 XloopINIT! 16 16
2118
2119 function! T1()
2120 XloopNEXT
2121 try
2122 Xloop 1 " X: 16 + 16*16
2123 throw "arrgh"
2124 Xloop 2 " X: 0
2125 finally
2126 Xloop 4 " X: 64 + 64*16
2127 endtry
2128 Xloop 8 " X: 0
2129 endfunction
2130
2131 function! T2()
2132 try
2133 Xpath 4096 " X: 4096
2134 call T1()
2135 Xpath 8192 " X: 0
2136 finally
2137 Xpath 16384 " X: 16384
2138 endtry
2139 Xpath 32768 " X: 0
2140 endfunction
2141
2142 try
2143 Xpath 65536 " X: 65536
2144 call C() " throw and catch
2145 Xpath 131072 " X: 131072
2146 catch /.*/
2147 Xpath 262144 " X: 0
2148 Xout v:exception "in" v:throwpoint
2149 endtry
2150
2151 try
2152 Xpath 524288 " X: 524288
2153 call T1() " throw, one level
2154 Xpath 1048576 " X: 0
2155 catch /arrgh/
2156 Xpath 2097152 " X: 2097152
2157 catch /.*/
2158 Xpath 4194304 " X: 0
2159 Xout v:exception "in" v:throwpoint
2160 endtry
2161
2162 try
2163 Xpath 8388608 " X: 8388608
2164 call T2() " throw, two levels
2165 Xpath 16777216 " X: 0
2166 catch /arrgh/
2167 Xpath 33554432 " X: 33554432
2168 catch /.*/
2169 Xpath 67108864 " X: 0
2170 Xout v:exception "in" v:throwpoint
2171 endtry
2172 Xpath 134217728 " X: 134217728
2173
2174 Xcheck 179000669
2175
2176 " Leave C, T1, and T2 for execution as scripts in the next test.
2177
2178
2179 "-------------------------------------------------------------------------------
2180 " Test 50: Throwing exceptions across script files {{{1
2181 "
2182 " When an exception is thrown but not caught inside a script file,
2183 " the sourcing script or function is checked for a matching :catch
2184 " clause.
2185 "
2186 " This test executes the bodies of the functions C, T1, and T2 from
2187 " the previous test as script files (:return replaced by :finish).
2188 "-------------------------------------------------------------------------------
2189
2190 XpathINIT
2191
2192 let scriptC = MakeScript("C") " X: 1 + 4 + 8
2193 delfunction C
2194
2195 XloopINIT! 16 16
2196
2197 let scriptT1 = MakeScript("T1") " X: 16 + 64 + 16*16 + 64*16
2198 delfunction T1
2199
2200 let scriptT2 = MakeScript("T2", scriptT1) " X: 4096 + 16384
2201 delfunction T2
2202
2203 function! F()
2204 try
2205 Xpath 65536 " X: 65536
2206 exec "source" g:scriptC
2207 Xpath 131072 " X: 131072
2208 catch /.*/
2209 Xpath 262144 " X: 0
2210 Xout v:exception "in" v:throwpoint
2211 endtry
2212
2213 try
2214 Xpath 524288 " X: 524288
2215 exec "source" g:scriptT1
2216 Xpath 1048576 " X: 0
2217 catch /arrgh/
2218 Xpath 2097152 " X: 2097152
2219 catch /.*/
2220 Xpath 4194304 " X: 0
2221 Xout v:exception "in" v:throwpoint
2222 endtry
2223 endfunction
2224
2225 try
2226 Xpath 8388608 " X: 8388608
2227 call F()
2228 Xpath 16777216 " X: 16777216
2229 exec "source" scriptT2
2230 Xpath 33554432 " X: 0
2231 catch /arrgh/
2232 Xpath 67108864 " X: 67108864
2233 catch /.*/
2234 Xpath 134217728 " X: 0
2235 Xout v:exception "in" v:throwpoint
2236 endtry
2237 Xpath 268435456 " X: 268435456
2238
2239 call delete(scriptC)
2240 call delete(scriptT1)
2241 call delete(scriptT2)
2242 unlet scriptC scriptT1 scriptT2
2243 delfunction F
2244
2245 Xcheck 363550045
2246
2247 " Test 51 was moved to test_trycatch.vim
2248 let Xtest = 52 612 let Xtest = 52
2249
2250 613
2251 "------------------------------------------------------------------------------- 614 "-------------------------------------------------------------------------------
2252 " Test 52: Uncaught exceptions {{{1 615 " Test 52: Uncaught exceptions {{{1
2253 " 616 "
2254 " When an exception is thrown but not caught, an error message is 617 " When an exception is thrown but not caught, an error message is