Mercurial > vim
comparison src/testdir/test49.vim @ 18504:ece46bd3c9af v8.1.2246
patch 8.1.2246: some tests are still in old style
Commit: https://github.com/vim/vim/commit/1f068233c101ecf5966e6df14853fe68f08175a7
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Nov 3 16:17:26 2019 +0100
patch 8.1.2246: some tests are still in old style
Problem: Some tests are still in old style.
Solution: Change a few tests to new style. (Yegappan Lakshmanan)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 03 Nov 2019 16:30:03 +0100 |
parents | 57b18521216f |
children | eff8d8f72a82 |
comparison
equal
deleted
inserted
replaced
18503:d946c71f8b4c | 18504:ece46bd3c9af |
---|---|
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 Oct 08 | 3 " Last Change: 2019 Nov 03 |
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 " Tests 1 to 15 were moved to test_vimscript.vim | 611 " Tests 1 to 17 were moved to test_vimscript.vim |
612 let Xtest = 16 | 612 let Xtest = 18 |
613 | |
614 "------------------------------------------------------------------------------- | |
615 " Test 16: Double :else or :elseif after :else {{{1 | |
616 " | |
617 " Multiple :elses or an :elseif after an :else are forbidden. | |
618 "------------------------------------------------------------------------------- | |
619 | |
620 XpathINIT | |
621 | |
622 function! F() abort | |
623 if 0 | |
624 Xpath 1 " X: 0 | |
625 else | |
626 Xpath 2 " X: 2 | |
627 else " aborts function | |
628 Xpath 4 " X: 0 | |
629 endif | |
630 endfunction | |
631 | |
632 function! G() abort | |
633 if 0 | |
634 Xpath 8 " X: 0 | |
635 else | |
636 Xpath 16 " X: 16 | |
637 elseif 1 " aborts function | |
638 Xpath 32 " X: 0 | |
639 else | |
640 Xpath 64 " X: 0 | |
641 endif | |
642 endfunction | |
643 | |
644 function! H() abort | |
645 if 0 | |
646 Xpath 128 " X: 0 | |
647 elseif 0 | |
648 Xpath 256 " X: 0 | |
649 else | |
650 Xpath 512 " X: 512 | |
651 else " aborts function | |
652 Xpath 1024 " X: 0 | |
653 endif | |
654 endfunction | |
655 | |
656 function! I() abort | |
657 if 0 | |
658 Xpath 2048 " X: 0 | |
659 elseif 0 | |
660 Xpath 4096 " X: 0 | |
661 else | |
662 Xpath 8192 " X: 8192 | |
663 elseif 1 " aborts function | |
664 Xpath 16384 " X: 0 | |
665 else | |
666 Xpath 32768 " X: 0 | |
667 endif | |
668 endfunction | |
669 | |
670 call F() | |
671 call G() | |
672 call H() | |
673 call I() | |
674 | |
675 delfunction F | |
676 delfunction G | |
677 delfunction H | |
678 delfunction I | |
679 | |
680 Xcheck 8722 | |
681 | |
682 | |
683 "------------------------------------------------------------------------------- | |
684 " Test 17: Nesting of unmatched :if or :endif inside a :while {{{1 | |
685 " | |
686 " The :while/:endwhile takes precedence in nesting over an unclosed | |
687 " :if or an unopened :endif. | |
688 "------------------------------------------------------------------------------- | |
689 | |
690 XpathINIT | |
691 | |
692 function! MSG(enr, emsg) | |
693 let english = v:lang == "C" || v:lang =~ '^[Ee]n' | |
694 if a:enr == "" | |
695 Xout "TODO: Add message number for:" a:emsg | |
696 let v:errmsg = ":" . v:errmsg | |
697 endif | |
698 let match = 1 | |
699 if v:errmsg !~ '^'.a:enr.':' || (english && v:errmsg !~ a:emsg) | |
700 let match = 0 | |
701 if v:errmsg == "" | |
702 Xout "Message missing." | |
703 else | |
704 let v:errmsg = escape(v:errmsg, '"') | |
705 Xout "Unexpected message:" v:errmsg | |
706 endif | |
707 endif | |
708 return match | |
709 endfunction | |
710 | |
711 let messages = "" | |
712 | |
713 " While loops inside a function are continued on error. | |
714 function! F() | |
715 let v:errmsg = "" | |
716 XloopINIT 1 16 | |
717 let loops = 3 | |
718 while loops > 0 | |
719 let loops = loops - 1 " 2: 1: 0: | |
720 Xloop 1 " X: 1 + 1*16 + 1*16*16 | |
721 if (loops == 1) | |
722 Xloop 2 " X: 2*16 | |
723 XloopNEXT | |
724 continue | |
725 elseif (loops == 0) | |
726 Xloop 4 " X: 4*16*16 | |
727 break | |
728 elseif 1 | |
729 Xloop 8 " X: 8 | |
730 XloopNEXT | |
731 " endif missing! | |
732 endwhile " :endwhile after :if 1 | |
733 Xpath 4096 " X: 16*16*16 | |
734 if MSG('E171', "Missing :endif") | |
735 let g:messages = g:messages . "A" | |
736 endif | |
737 | |
738 let v:errmsg = "" | |
739 XloopINIT! 8192 4 | |
740 let loops = 2 | |
741 while loops > 0 " 2: 1: | |
742 XloopNEXT | |
743 let loops = loops - 1 | |
744 Xloop 1 " X: 8192 + 8192*4 | |
745 if 0 | |
746 Xloop 2 " X: 0 | |
747 " endif missing | |
748 endwhile " :endwhile after :if 0 | |
749 Xpath 131072 " X: 8192*4*4 | |
750 if MSG('E171', "Missing :endif") | |
751 let g:messages = g:messages . "B" | |
752 endif | |
753 | |
754 let v:errmsg = "" | |
755 XloopINIT 262144 4 | |
756 let loops = 2 | |
757 while loops > 0 " 2: 1: | |
758 let loops = loops - 1 | |
759 Xloop 1 " X: 262144 + 262144 * 4 | |
760 " if missing! | |
761 endif " :endif without :if in while | |
762 Xloop 2 " X: 524288 + 524288 * 4 | |
763 XloopNEXT | |
764 endwhile | |
765 Xpath 4194304 " X: 262144*4*4 | |
766 if MSG('E580', ":endif without :if") | |
767 let g:messages = g:messages . "C" | |
768 endif | |
769 endfunction | |
770 | |
771 call F() | |
772 | |
773 " Error continuation outside a function is at the outermost :endwhile or :endif. | |
774 let v:errmsg = "" | |
775 XloopINIT! 8388608 4 | |
776 let loops = 2 | |
777 while loops > 0 " 2: 1: | |
778 XloopNEXT | |
779 let loops = loops - 1 | |
780 Xloop 1 " X: 8388608 + 0 * 4 | |
781 if 0 | |
782 Xloop 2 " X: 0 | |
783 " endif missing! Following :endwhile fails. | |
784 endwhile | Xpath 134217728 " X: 0 | |
785 Xpath 268435456 " X: 2*8388608*4*4 | |
786 if MSG('E171', "Missing :endif") | |
787 let messages = g:messages . "D" | |
788 endif | |
789 | |
790 if messages != "ABCD" | |
791 Xpath 536870912 " X: 0 | |
792 Xout "messages is" messages "instead of ABCD" | |
793 endif | |
794 | |
795 unlet loops messages | |
796 delfunction F | |
797 delfunction MSG | |
798 | |
799 Xcheck 285127993 | |
800 | |
801 | 613 |
802 "------------------------------------------------------------------------------- | 614 "------------------------------------------------------------------------------- |
803 " Test 18: Interrupt (Ctrl-C pressed) {{{1 | 615 " Test 18: Interrupt (Ctrl-C pressed) {{{1 |
804 " | 616 " |
805 " On an interrupt, the script processing is terminated immediately. | 617 " On an interrupt, the script processing is terminated immediately. |
1311 Xpath 32 " X: 32 | 1123 Xpath 32 " X: 32 |
1312 endif | 1124 endif |
1313 | 1125 |
1314 Xcheck 41 | 1126 Xcheck 41 |
1315 | 1127 |
1316 | 1128 " Tests 25 and 26 were moved to test_trycatch.vim |
1317 "------------------------------------------------------------------------------- | 1129 let Xtest = 27 |
1318 " Test 25: Executing :finally clauses on normal control flow {{{1 | |
1319 " | |
1320 " Control flow in a :try conditional should always fall through to its | |
1321 " :finally clause. A :finally clause of a :try conditional inside an | |
1322 " inactive conditional should never be executed. | |
1323 "------------------------------------------------------------------------------- | |
1324 | |
1325 XpathINIT | |
1326 | |
1327 function! F() | |
1328 let loops = 3 | |
1329 XloopINIT 1 256 | |
1330 while loops > 0 " 3: 2: 1: | |
1331 Xloop 1 " X: 1 + 1*256 + 1*256*256 | |
1332 if loops >= 2 | |
1333 try | |
1334 Xloop 2 " X: 2 + 2*256 | |
1335 if loops == 2 | |
1336 try | |
1337 Xloop 4 " X: 4*256 | |
1338 finally | |
1339 Xloop 8 " X: 8*256 | |
1340 endtry | |
1341 endif | |
1342 finally | |
1343 Xloop 16 " X: 16 + 16*256 | |
1344 if loops == 2 | |
1345 try | |
1346 Xloop 32 " X: 32*256 | |
1347 finally | |
1348 Xloop 64 " X: 64*256 | |
1349 endtry | |
1350 endif | |
1351 endtry | |
1352 endif | |
1353 Xloop 128 " X: 128 + 128*256 + 128*256*256 | |
1354 let loops = loops - 1 | |
1355 XloopNEXT | |
1356 endwhile | |
1357 Xpath 16777216 " X: 16777216 | |
1358 endfunction | |
1359 | |
1360 if 1 | |
1361 try | |
1362 Xpath 33554432 " X: 33554432 | |
1363 call F() | |
1364 Xpath 67108864 " X: 67108864 | |
1365 finally | |
1366 Xpath 134217728 " X: 134217728 | |
1367 endtry | |
1368 else | |
1369 try | |
1370 Xpath 268435456 " X: 0 | |
1371 finally | |
1372 Xpath 536870912 " X: 0 | |
1373 endtry | |
1374 endif | |
1375 | |
1376 delfunction F | |
1377 | |
1378 Xcheck 260177811 | |
1379 | |
1380 | |
1381 "------------------------------------------------------------------------------- | |
1382 " Test 26: Executing :finally clauses after :continue or :break {{{1 | |
1383 " | |
1384 " For a :continue or :break dynamically enclosed in a :try/:endtry | |
1385 " region inside the next surrounding :while/:endwhile, if the | |
1386 " :continue/:break is before the :finally, the :finally clause is | |
1387 " executed first. If the :continue/:break is after the :finally, the | |
1388 " :finally clause is broken (like an :if/:endif region). | |
1389 "------------------------------------------------------------------------------- | |
1390 | |
1391 XpathINIT | |
1392 | |
1393 try | |
1394 let loops = 3 | |
1395 XloopINIT! 1 32 | |
1396 while loops > 0 | |
1397 XloopNEXT | |
1398 try | |
1399 try | |
1400 if loops == 2 " 3: 2: 1: | |
1401 Xloop 1 " X: 1*32 | |
1402 let loops = loops - 1 | |
1403 continue | |
1404 elseif loops == 1 | |
1405 Xloop 2 " X: 2*32*32 | |
1406 break | |
1407 finish | |
1408 endif | |
1409 Xloop 4 " X: 4 | |
1410 endtry | |
1411 finally | |
1412 Xloop 8 " X: 8 + 8*32 + 8*32*32 | |
1413 endtry | |
1414 Xloop 16 " X: 16 | |
1415 let loops = loops - 1 | |
1416 endwhile | |
1417 Xpath 32768 " X: 32768 | |
1418 finally | |
1419 Xpath 65536 " X: 65536 | |
1420 let loops = 3 | |
1421 XloopINIT 131072 16 | |
1422 while loops > 0 | |
1423 try | |
1424 finally | |
1425 try | |
1426 if loops == 2 | |
1427 Xloop 1 " X: 131072*16 | |
1428 let loops = loops - 1 | |
1429 XloopNEXT | |
1430 continue | |
1431 elseif loops == 1 | |
1432 Xloop 2 " X: 131072*2*16*16 | |
1433 break | |
1434 finish | |
1435 endif | |
1436 endtry | |
1437 Xloop 4 " X: 131072*4 | |
1438 endtry | |
1439 Xloop 8 " X: 131072*8 | |
1440 let loops = loops - 1 | |
1441 XloopNEXT | |
1442 endwhile | |
1443 Xpath 536870912 " X: 536870912 | |
1444 endtry | |
1445 Xpath 1073741824 " X: 1073741824 | |
1446 | |
1447 unlet loops | |
1448 | |
1449 Xcheck 1681500476 | |
1450 | 1130 |
1451 | 1131 |
1452 "------------------------------------------------------------------------------- | 1132 "------------------------------------------------------------------------------- |
1453 " Test 27: Executing :finally clauses after :return {{{1 | 1133 " Test 27: Executing :finally clauses after :return {{{1 |
1454 " | 1134 " |
1781 Xpath 1073741824 " X: 0 | 1461 Xpath 1073741824 " X: 0 |
1782 endif | 1462 endif |
1783 | 1463 |
1784 Xcheck 190905173 | 1464 Xcheck 190905173 |
1785 | 1465 |
1786 | 1466 " Tests 32 and 33 were moved to test_trycatch.vim |
1787 "------------------------------------------------------------------------------- | 1467 let Xtest = 34 |
1788 " Test 32: Remembering the :return value on :finally {{{1 | |
1789 " | |
1790 " If a :finally clause is executed due to a :return specifying | |
1791 " a value, this is the value visible to the caller if not overwritten | |
1792 " by a new :return in the :finally clause. A :return without a value | |
1793 " in the :finally clause overwrites with value 0. | |
1794 "------------------------------------------------------------------------------- | |
1795 | |
1796 XpathINIT | |
1797 | |
1798 function! F() | |
1799 try | |
1800 Xpath 1 " X: 1 | |
1801 try | |
1802 Xpath 2 " X: 2 | |
1803 return "ABCD" | |
1804 Xpath 4 " X: 0 | |
1805 finally | |
1806 Xpath 8 " X: 8 | |
1807 endtry | |
1808 Xpath 16 " X: 0 | |
1809 finally | |
1810 Xpath 32 " X: 32 | |
1811 endtry | |
1812 Xpath 64 " X: 0 | |
1813 endfunction | |
1814 | |
1815 function! G() | |
1816 try | |
1817 Xpath 128 " X: 128 | |
1818 return 8 | |
1819 Xpath 256 " X: 0 | |
1820 finally | |
1821 Xpath 512 " X: 512 | |
1822 return 16 + strlen(F()) | |
1823 Xpath 1024 " X: 0 | |
1824 endtry | |
1825 Xpath 2048 " X: 0 | |
1826 endfunction | |
1827 | |
1828 function! H() | |
1829 try | |
1830 Xpath 4096 " X: 4096 | |
1831 return 32 | |
1832 Xpath 8192 " X: 0 | |
1833 finally | |
1834 Xpath 16384 " X: 16384 | |
1835 return | |
1836 Xpath 32768 " X: 0 | |
1837 endtry | |
1838 Xpath 65536 " X: 0 | |
1839 endfunction | |
1840 | |
1841 function! I() | |
1842 try | |
1843 Xpath 131072 " X: 131072 | |
1844 finally | |
1845 Xpath 262144 " X: 262144 | |
1846 return G() + H() + 64 | |
1847 Xpath 524288 " X: 0 | |
1848 endtry | |
1849 Xpath 1048576 " X: 0 | |
1850 endfunction | |
1851 | |
1852 let retcode = I() | |
1853 Xpath 2097152 " X: 2097152 | |
1854 | |
1855 if retcode < 0 | |
1856 Xpath 4194304 " X: 0 | |
1857 endif | |
1858 if retcode % 4 | |
1859 Xpath 8388608 " X: 0 | |
1860 endif | |
1861 if (retcode/4) % 2 | |
1862 Xpath 16777216 " X: 16777216 | |
1863 endif | |
1864 if (retcode/8) % 2 | |
1865 Xpath 33554432 " X: 0 | |
1866 endif | |
1867 if (retcode/16) % 2 | |
1868 Xpath 67108864 " X: 67108864 | |
1869 endif | |
1870 if (retcode/32) % 2 | |
1871 Xpath 134217728 " X: 0 | |
1872 endif | |
1873 if (retcode/64) % 2 | |
1874 Xpath 268435456 " X: 268435456 | |
1875 endif | |
1876 if retcode/128 | |
1877 Xpath 536870912 " X: 0 | |
1878 endif | |
1879 | |
1880 unlet retcode | |
1881 delfunction F | |
1882 delfunction G | |
1883 delfunction H | |
1884 delfunction I | |
1885 | |
1886 Xcheck 354833067 | |
1887 | |
1888 | |
1889 "------------------------------------------------------------------------------- | |
1890 " Test 33: :return under :execute or user command and :finally {{{1 | |
1891 " | |
1892 " A :return command may be executed under an ":execute" or from | |
1893 " a user command. Executing of :finally clauses and passing through | |
1894 " the return code works also then. | |
1895 "------------------------------------------------------------------------------- | |
1896 XpathINIT | |
1897 | |
1898 command! -nargs=? RETURN | |
1899 \ try | return <args> | finally | return <args> * 2 | endtry | |
1900 | |
1901 function! F() | |
1902 try | |
1903 RETURN 8 | |
1904 Xpath 1 " X: 0 | |
1905 finally | |
1906 Xpath 2 " X: 2 | |
1907 endtry | |
1908 Xpath 4 " X: 0 | |
1909 endfunction | |
1910 | |
1911 function! G() | |
1912 try | |
1913 RETURN 32 | |
1914 Xpath 8 " X: 0 | |
1915 finally | |
1916 Xpath 16 " X: 16 | |
1917 RETURN 128 | |
1918 Xpath 32 " X: 0 | |
1919 endtry | |
1920 Xpath 64 " X: 0 | |
1921 endfunction | |
1922 | |
1923 function! H() | |
1924 try | |
1925 execute "try | return 512 | finally | return 1024 | endtry" | |
1926 Xpath 128 " X: 0 | |
1927 finally | |
1928 Xpath 256 " X: 256 | |
1929 endtry | |
1930 Xpath 512 " X: 0 | |
1931 endfunction | |
1932 | |
1933 function! I() | |
1934 try | |
1935 execute "try | return 2048 | finally | return 4096 | endtry" | |
1936 Xpath 1024 " X: 0 | |
1937 finally | |
1938 Xpath 2048 " X: 2048 | |
1939 execute "try | return 8192 | finally | return 16384 | endtry" | |
1940 Xpath 4096 " X: 0 | |
1941 endtry | |
1942 Xpath 8192 " X: 0 | |
1943 endfunction | |
1944 | |
1945 function! J() | |
1946 try | |
1947 RETURN 32768 | |
1948 Xpath 16384 " X: 0 | |
1949 finally | |
1950 Xpath 32768 " X: 32768 | |
1951 return | |
1952 Xpath 65536 " X: 0 | |
1953 endtry | |
1954 Xpath 131072 " X: 0 | |
1955 endfunction | |
1956 | |
1957 function! K() | |
1958 try | |
1959 execute "try | return 131072 | finally | return 262144 | endtry" | |
1960 Xpath 262144 " X: 0 | |
1961 finally | |
1962 Xpath 524288 " X: 524288 | |
1963 execute "try | return 524288 | finally | return | endtry" | |
1964 Xpath 1048576 " X: 0 | |
1965 endtry | |
1966 Xpath 2097152 " X: 0 | |
1967 endfunction | |
1968 | |
1969 function! L() | |
1970 try | |
1971 return | |
1972 Xpath 4194304 " X: 0 | |
1973 finally | |
1974 Xpath 8388608 " X: 8388608 | |
1975 RETURN 1048576 | |
1976 Xpath 16777216 " X: 0 | |
1977 endtry | |
1978 Xpath 33554432 " X: 0 | |
1979 endfunction | |
1980 | |
1981 function! M() | |
1982 try | |
1983 return | |
1984 Xpath 67108864 " X: 0 | |
1985 finally | |
1986 Xpath 134217728 " X: 134217728 | |
1987 execute "try | return 4194304 | finally | return 8388608 | endtry" | |
1988 Xpath 268435456 " X: 0 | |
1989 endtry | |
1990 Xpath 536870912 " X: 0 | |
1991 endfunction | |
1992 | |
1993 function! N() | |
1994 RETURN 16777216 | |
1995 endfunction | |
1996 | |
1997 function! O() | |
1998 execute "try | return 67108864 | finally | return 134217728 | endtry" | |
1999 endfunction | |
2000 | |
2001 let sum = F() + G() + H() + I() + J() + K() + L() + M() | |
2002 let expected = 16 + 256 + 1024 + 16384 + 0 + 0 + 2097152 + 8388608 | |
2003 let sum = sum + N() + O() | |
2004 let expected = expected + 33554432 + 134217728 | |
2005 | |
2006 if sum == expected | |
2007 Xout "sum = " . sum . " (ok)" | |
2008 else | |
2009 Xout "sum = " . sum . ", expected: " . expected | |
2010 endif | |
2011 | |
2012 Xpath 1073741824 " X: 1073741824 | |
2013 | |
2014 if sum != expected | |
2015 " The Xpath command does not accept 2^31 (negative); add explicitly: | |
2016 let Xpath = Xpath + 2147483648 " X: 0 | |
2017 endif | |
2018 | |
2019 unlet sum expected | |
2020 delfunction F | |
2021 delfunction G | |
2022 delfunction H | |
2023 delfunction I | |
2024 delfunction J | |
2025 delfunction K | |
2026 delfunction L | |
2027 delfunction M | |
2028 delfunction N | |
2029 delfunction O | |
2030 | |
2031 Xcheck 1216907538 | |
2032 | 1468 |
2033 | 1469 |
2034 "------------------------------------------------------------------------------- | 1470 "------------------------------------------------------------------------------- |
2035 " Test 34: :finally reason discarded by :continue {{{1 | 1471 " Test 34: :finally reason discarded by :continue {{{1 |
2036 " | 1472 " |
2652 | 2088 |
2653 endif | 2089 endif |
2654 | 2090 |
2655 Xcheck 357908480 | 2091 Xcheck 357908480 |
2656 | 2092 |
2657 | 2093 " Tests 41 to 48 were moved to test_trycatch.vim |
2658 "------------------------------------------------------------------------------- | 2094 let Xtest = 49 |
2659 " Test 41: Skipped :throw finding next command {{{1 | |
2660 " | |
2661 " A :throw in an inactive conditional must not hide a following | |
2662 " command. | |
2663 "------------------------------------------------------------------------------- | |
2664 | |
2665 XpathINIT | |
2666 | |
2667 function! F() | |
2668 Xpath 1 " X: 1 | |
2669 if 0 | throw "never" | endif | Xpath 2 " X: 2 | |
2670 Xpath 4 " X: 4 | |
2671 endfunction | |
2672 | |
2673 function! G() | |
2674 Xpath 8 " X: 8 | |
2675 while 0 | throw "never" | endwhile | Xpath 16 " X: 16 | |
2676 Xpath 32 " X: 32 | |
2677 endfunction | |
2678 | |
2679 function H() | |
2680 Xpath 64 " X: 64 | |
2681 if 0 | try | throw "never" | endtry | endif | Xpath 128 " X: 128 | |
2682 Xpath 256 " X: 256 | |
2683 endfunction | |
2684 | |
2685 Xpath 512 " X: 512 | |
2686 | |
2687 try | |
2688 Xpath 1024 " X: 1024 | |
2689 call F() | |
2690 Xpath 2048 " X: 2048 | |
2691 catch /.*/ | |
2692 Xpath 4096 " X: 0 | |
2693 Xout v:exception "in" v:throwpoint | |
2694 endtry | |
2695 | |
2696 Xpath 8192 " X: 8192 | |
2697 | |
2698 try | |
2699 Xpath 16384 " X: 16384 | |
2700 call G() | |
2701 Xpath 32768 " X: 32768 | |
2702 catch /.*/ | |
2703 Xpath 65536 " X: 0 | |
2704 Xout v:exception "in" v:throwpoint | |
2705 endtry | |
2706 | |
2707 Xpath 131072 " X: 131072 | |
2708 | |
2709 try | |
2710 Xpath 262144 " X: 262144 | |
2711 call H() | |
2712 Xpath 524288 " X: 524288 | |
2713 catch /.*/ | |
2714 Xpath 1048576 " X: 0 | |
2715 Xout v:exception "in" v:throwpoint | |
2716 endtry | |
2717 | |
2718 Xpath 2097152 " X: 2097152 | |
2719 | |
2720 delfunction F | |
2721 delfunction G | |
2722 delfunction H | |
2723 | |
2724 Xcheck 3076095 | |
2725 | |
2726 | |
2727 "------------------------------------------------------------------------------- | |
2728 " Test 42: Catching number and string exceptions {{{1 | |
2729 " | |
2730 " When a number is thrown, it is converted to a string exception. | |
2731 " Numbers and strings may be caught by specifying a regular exception | |
2732 " as argument to the :catch command. | |
2733 "------------------------------------------------------------------------------- | |
2734 | |
2735 XpathINIT | |
2736 | |
2737 try | |
2738 | |
2739 try | |
2740 Xpath 1 " X: 1 | |
2741 throw 4711 | |
2742 Xpath 2 " X: 0 | |
2743 catch /4711/ | |
2744 Xpath 4 " X: 4 | |
2745 endtry | |
2746 | |
2747 try | |
2748 Xpath 8 " X: 8 | |
2749 throw 4711 | |
2750 Xpath 16 " X: 0 | |
2751 catch /^4711$/ | |
2752 Xpath 32 " X: 32 | |
2753 endtry | |
2754 | |
2755 try | |
2756 Xpath 64 " X: 64 | |
2757 throw 4711 | |
2758 Xpath 128 " X: 0 | |
2759 catch /\d/ | |
2760 Xpath 256 " X: 256 | |
2761 endtry | |
2762 | |
2763 try | |
2764 Xpath 512 " X: 512 | |
2765 throw 4711 | |
2766 Xpath 1024 " X: 0 | |
2767 catch /^\d\+$/ | |
2768 Xpath 2048 " X: 2048 | |
2769 endtry | |
2770 | |
2771 try | |
2772 Xpath 4096 " X: 4096 | |
2773 throw "arrgh" | |
2774 Xpath 8192 " X: 0 | |
2775 catch /arrgh/ | |
2776 Xpath 16384 " X: 16384 | |
2777 endtry | |
2778 | |
2779 try | |
2780 Xpath 32768 " X: 32768 | |
2781 throw "arrgh" | |
2782 Xpath 65536 " X: 0 | |
2783 catch /^arrgh$/ | |
2784 Xpath 131072 " X: 131072 | |
2785 endtry | |
2786 | |
2787 try | |
2788 Xpath 262144 " X: 262144 | |
2789 throw "arrgh" | |
2790 Xpath 524288 " X: 0 | |
2791 catch /\l/ | |
2792 Xpath 1048576 " X: 1048576 | |
2793 endtry | |
2794 | |
2795 try | |
2796 Xpath 2097152 " X: 2097152 | |
2797 throw "arrgh" | |
2798 Xpath 4194304 " X: 0 | |
2799 catch /^\l\+$/ | |
2800 Xpath 8388608 " X: 8388608 | |
2801 endtry | |
2802 | |
2803 try | |
2804 try | |
2805 Xpath 16777216 " X: 16777216 | |
2806 throw "ARRGH" | |
2807 Xpath 33554432 " X: 0 | |
2808 catch /^arrgh$/ | |
2809 Xpath 67108864 " X: 0 | |
2810 endtry | |
2811 catch /^\carrgh$/ | |
2812 Xpath 134217728 " X: 134217728 | |
2813 endtry | |
2814 | |
2815 try | |
2816 Xpath 268435456 " X: 268435456 | |
2817 throw "" | |
2818 Xpath 536870912 " X: 0 | |
2819 catch /^$/ | |
2820 Xpath 1073741824 " X: 1073741824 | |
2821 endtry | |
2822 | |
2823 catch /.*/ | |
2824 " The Xpath command does not accept 2^31 (negative); add explicitly: | |
2825 let Xpath = Xpath + 2147483648 " X: 0 | |
2826 Xout v:exception "in" v:throwpoint | |
2827 endtry | |
2828 | |
2829 Xcheck 1505155949 | |
2830 | |
2831 | |
2832 "------------------------------------------------------------------------------- | |
2833 " Test 43: Selecting the correct :catch clause {{{1 | |
2834 " | |
2835 " When an exception is thrown and there are multiple :catch clauses, | |
2836 " the first matching one is taken. | |
2837 "------------------------------------------------------------------------------- | |
2838 | |
2839 XpathINIT | |
2840 | |
2841 XloopINIT 1 1024 | |
2842 let loops = 3 | |
2843 while loops > 0 | |
2844 try | |
2845 if loops == 3 | |
2846 Xloop 1 " X: 1 | |
2847 throw "a" | |
2848 Xloop 2 " X: 0 | |
2849 elseif loops == 2 | |
2850 Xloop 4 " X: 4*1024 | |
2851 throw "ab" | |
2852 Xloop 8 " X: 0 | |
2853 elseif loops == 1 | |
2854 Xloop 16 " X: 16*1024*1024 | |
2855 throw "abc" | |
2856 Xloop 32 " X: 0 | |
2857 endif | |
2858 catch /abc/ | |
2859 Xloop 64 " X: 64*1024*1024 | |
2860 catch /ab/ | |
2861 Xloop 128 " X: 128*1024 | |
2862 catch /.*/ | |
2863 Xloop 256 " X: 256 | |
2864 catch /a/ | |
2865 Xloop 512 " X: 0 | |
2866 endtry | |
2867 | |
2868 let loops = loops - 1 | |
2869 XloopNEXT | |
2870 endwhile | |
2871 Xpath 1073741824 " X: 1073741824 | |
2872 | |
2873 unlet loops | |
2874 | |
2875 Xcheck 1157763329 | |
2876 | |
2877 | |
2878 "------------------------------------------------------------------------------- | |
2879 " Test 44: Missing or empty :catch patterns {{{1 | |
2880 " | |
2881 " A missing or empty :catch pattern means the same as /.*/, that is, | |
2882 " catches everything. To catch only empty exceptions, /^$/ must be | |
2883 " used. A :catch with missing, empty, or /.*/ argument also works | |
2884 " when followed by another command separated by a bar on the same | |
2885 " line. :catch patterns cannot be specified between ||. But other | |
2886 " pattern separators can be used instead of //. | |
2887 "------------------------------------------------------------------------------- | |
2888 | |
2889 XpathINIT | |
2890 | |
2891 try | |
2892 try | |
2893 Xpath 1 " X: 1 | |
2894 throw "" | |
2895 catch /^$/ | |
2896 Xpath 2 " X: 2 | |
2897 endtry | |
2898 | |
2899 try | |
2900 Xpath 4 " X: 4 | |
2901 throw "" | |
2902 catch /.*/ | |
2903 Xpath 8 " X: 8 | |
2904 endtry | |
2905 | |
2906 try | |
2907 Xpath 16 " X: 16 | |
2908 throw "" | |
2909 catch // | |
2910 Xpath 32 " X: 32 | |
2911 endtry | |
2912 | |
2913 try | |
2914 Xpath 64 " X: 64 | |
2915 throw "" | |
2916 catch | |
2917 Xpath 128 " X: 128 | |
2918 endtry | |
2919 | |
2920 try | |
2921 Xpath 256 " X: 256 | |
2922 throw "oops" | |
2923 catch /^$/ | |
2924 Xpath 512 " X: 0 | |
2925 catch /.*/ | |
2926 Xpath 1024 " X: 1024 | |
2927 endtry | |
2928 | |
2929 try | |
2930 Xpath 2048 " X: 2048 | |
2931 throw "arrgh" | |
2932 catch /^$/ | |
2933 Xpath 4096 " X: 0 | |
2934 catch // | |
2935 Xpath 8192 " X: 8192 | |
2936 endtry | |
2937 | |
2938 try | |
2939 Xpath 16384 " X: 16384 | |
2940 throw "brrr" | |
2941 catch /^$/ | |
2942 Xpath 32768 " X: 0 | |
2943 catch | |
2944 Xpath 65536 " X: 65536 | |
2945 endtry | |
2946 | |
2947 try | Xpath 131072 | throw "x" | catch /.*/ | Xpath 262144 | endtry | |
2948 " X: 131072 + 262144 | |
2949 | |
2950 try | Xpath 524288 | throw "y" | catch // | Xpath 1048576 | endtry | |
2951 " X: 524288 + 1048576 | |
2952 | |
2953 while 1 | |
2954 try | |
2955 let caught = 0 | |
2956 let v:errmsg = "" | |
2957 " Extra try level: if ":catch" without arguments below raises | |
2958 " a syntax error because it misinterprets the "Xpath" as a pattern, | |
2959 " let it be caught by the ":catch /.*/" below. | |
2960 try | |
2961 try | Xpath 2097152 | throw "z" | catch | Xpath 4194304 | : | |
2962 endtry " X: 2097152 + 4194304 | |
2963 endtry | |
2964 catch /.*/ | |
2965 let caught = 1 | |
2966 Xout v:exception "in" v:throwpoint | |
2967 finally | |
2968 if $VIMNOERRTHROW && v:errmsg != "" | |
2969 Xout v:errmsg | |
2970 endif | |
2971 if caught || $VIMNOERRTHROW && v:errmsg != "" | |
2972 Xpath 8388608 " X: 0 | |
2973 endif | |
2974 break " discard error for $VIMNOERRTHROW | |
2975 endtry | |
2976 endwhile | |
2977 | |
2978 let cologne = 4711 | |
2979 try | |
2980 try | |
2981 Xpath 16777216 " X: 16777216 | |
2982 throw "throw cologne" | |
2983 " Next lines catches all and throws 4711: | |
2984 catch |throw cologne| | |
2985 Xpath 33554432 " X: 0 | |
2986 endtry | |
2987 catch /4711/ | |
2988 Xpath 67108864 " X: 67108864 | |
2989 endtry | |
2990 | |
2991 try | |
2992 Xpath 134217728 " X: 134217728 | |
2993 throw "plus" | |
2994 catch +plus+ | |
2995 Xpath 268435456 " X: 268435456 | |
2996 endtry | |
2997 | |
2998 Xpath 536870912 " X: 536870912 | |
2999 catch /.*/ | |
3000 Xpath 1073741824 " X: 0 | |
3001 Xout v:exception "in" v:throwpoint | |
3002 endtry | |
3003 | |
3004 unlet! caught cologne | |
3005 | |
3006 Xcheck 1031761407 | |
3007 | |
3008 | |
3009 "------------------------------------------------------------------------------- | |
3010 " Test 45: Catching exceptions from nested :try blocks {{{1 | |
3011 " | |
3012 " When :try blocks are nested, an exception is caught by the innermost | |
3013 " try conditional that has a matching :catch clause. | |
3014 "------------------------------------------------------------------------------- | |
3015 | |
3016 XpathINIT | |
3017 | |
3018 XloopINIT 1 1024 | |
3019 let loops = 3 | |
3020 while loops > 0 | |
3021 try | |
3022 try | |
3023 try | |
3024 try | |
3025 if loops == 3 | |
3026 Xloop 1 " X: 1 | |
3027 throw "a" | |
3028 Xloop 2 " X: 0 | |
3029 elseif loops == 2 | |
3030 Xloop 4 " X: 4*1024 | |
3031 throw "ab" | |
3032 Xloop 8 " X: 0 | |
3033 elseif loops == 1 | |
3034 Xloop 16 " X: 16*1024*1024 | |
3035 throw "abc" | |
3036 Xloop 32 " X: 0 | |
3037 endif | |
3038 catch /abc/ | |
3039 Xloop 64 " X: 64*1024*1024 | |
3040 endtry | |
3041 catch /ab/ | |
3042 Xloop 128 " X: 128*1024 | |
3043 endtry | |
3044 catch /.*/ | |
3045 Xloop 256 " X: 256 | |
3046 endtry | |
3047 catch /a/ | |
3048 Xloop 512 " X: 0 | |
3049 endtry | |
3050 | |
3051 let loops = loops - 1 | |
3052 XloopNEXT | |
3053 endwhile | |
3054 Xpath 1073741824 " X: 1073741824 | |
3055 | |
3056 unlet loops | |
3057 | |
3058 Xcheck 1157763329 | |
3059 | |
3060 | |
3061 "------------------------------------------------------------------------------- | |
3062 " Test 46: Executing :finally after a :throw in nested :try {{{1 | |
3063 " | |
3064 " When an exception is thrown from within nested :try blocks, the | |
3065 " :finally clauses of the non-catching try conditionals should be | |
3066 " executed before the matching :catch of the next surrounding :try | |
3067 " gets the control. If this also has a :finally clause, it is | |
3068 " executed afterwards. | |
3069 "------------------------------------------------------------------------------- | |
3070 | |
3071 XpathINIT | |
3072 | |
3073 let sum = 0 | |
3074 | |
3075 try | |
3076 Xpath 1 " X: 1 | |
3077 try | |
3078 Xpath 2 " X: 2 | |
3079 try | |
3080 Xpath 4 " X: 4 | |
3081 try | |
3082 Xpath 8 " X: 8 | |
3083 throw "ABC" | |
3084 Xpath 16 " X: 0 | |
3085 catch /xyz/ | |
3086 Xpath 32 " X: 0 | |
3087 finally | |
3088 Xpath 64 " X: 64 | |
3089 if sum != 0 | |
3090 Xpath 128 " X: 0 | |
3091 endif | |
3092 let sum = sum + 1 | |
3093 endtry | |
3094 Xpath 256 " X: 0 | |
3095 catch /123/ | |
3096 Xpath 512 " X: 0 | |
3097 catch /321/ | |
3098 Xpath 1024 " X: 0 | |
3099 finally | |
3100 Xpath 2048 " X: 2048 | |
3101 if sum != 1 | |
3102 Xpath 4096 " X: 0 | |
3103 endif | |
3104 let sum = sum + 2 | |
3105 endtry | |
3106 Xpath 8192 " X: 0 | |
3107 finally | |
3108 Xpath 16384 " X: 16384 | |
3109 if sum != 3 | |
3110 Xpath 32768 " X: 0 | |
3111 endif | |
3112 let sum = sum + 4 | |
3113 endtry | |
3114 Xpath 65536 " X: 0 | |
3115 catch /ABC/ | |
3116 Xpath 131072 " X: 131072 | |
3117 if sum != 7 | |
3118 Xpath 262144 " X: 0 | |
3119 endif | |
3120 let sum = sum + 8 | |
3121 finally | |
3122 Xpath 524288 " X: 524288 | |
3123 if sum != 15 | |
3124 Xpath 1048576 " X: 0 | |
3125 endif | |
3126 let sum = sum + 16 | |
3127 endtry | |
3128 Xpath 65536 " X: 65536 | |
3129 if sum != 31 | |
3130 Xpath 131072 " X: 0 | |
3131 endif | |
3132 | |
3133 unlet sum | |
3134 | |
3135 Xcheck 739407 | |
3136 | |
3137 | |
3138 "------------------------------------------------------------------------------- | |
3139 " Test 47: Throwing exceptions from a :catch clause {{{1 | |
3140 " | |
3141 " When an exception is thrown from a :catch clause, it should not be | |
3142 " caught by a :catch of the same :try conditional. After executing | |
3143 " the :finally clause (if present), surrounding try conditionals | |
3144 " should be checked for a matching :catch. | |
3145 "------------------------------------------------------------------------------- | |
3146 | |
3147 XpathINIT | |
3148 | |
3149 Xpath 1 " X: 1 | |
3150 try | |
3151 Xpath 2 " X: 2 | |
3152 try | |
3153 Xpath 4 " X: 4 | |
3154 try | |
3155 Xpath 8 " X: 8 | |
3156 throw "x1" | |
3157 Xpath 16 " X: 0 | |
3158 catch /x1/ | |
3159 Xpath 32 " X: 32 | |
3160 try | |
3161 Xpath 64 " X: 64 | |
3162 throw "x2" | |
3163 Xpath 128 " X: 0 | |
3164 catch /x1/ | |
3165 Xpath 256 " X: 0 | |
3166 catch /x2/ | |
3167 Xpath 512 " X: 512 | |
3168 try | |
3169 Xpath 1024 " X: 1024 | |
3170 throw "x3" | |
3171 Xpath 2048 " X: 0 | |
3172 catch /x1/ | |
3173 Xpath 4096 " X: 0 | |
3174 catch /x2/ | |
3175 Xpath 8192 " X: 0 | |
3176 finally | |
3177 Xpath 16384 " X: 16384 | |
3178 endtry | |
3179 Xpath 32768 " X: 0 | |
3180 catch /x3/ | |
3181 Xpath 65536 " X: 0 | |
3182 endtry | |
3183 Xpath 131072 " X: 0 | |
3184 catch /x1/ | |
3185 Xpath 262144 " X: 0 | |
3186 catch /x2/ | |
3187 Xpath 524288 " X: 0 | |
3188 catch /x3/ | |
3189 Xpath 1048576 " X: 0 | |
3190 finally | |
3191 Xpath 2097152 " X: 2097152 | |
3192 endtry | |
3193 Xpath 4194304 " X: 0 | |
3194 catch /x1/ | |
3195 Xpath 8388608 " X: 0 | |
3196 catch /x2/ | |
3197 Xpath 16777216 " X: 0 | |
3198 catch /x3/ | |
3199 Xpath 33554432 " X: 33554432 | |
3200 endtry | |
3201 Xpath 67108864 " X: 67108864 | |
3202 catch /.*/ | |
3203 Xpath 134217728 " X: 0 | |
3204 Xout v:exception "in" v:throwpoint | |
3205 endtry | |
3206 Xpath 268435456 " X: 268435456 | |
3207 | |
3208 Xcheck 371213935 | |
3209 | |
3210 | |
3211 "------------------------------------------------------------------------------- | |
3212 " Test 48: Throwing exceptions from a :finally clause {{{1 | |
3213 " | |
3214 " When an exception is thrown from a :finally clause, it should not be | |
3215 " caught by a :catch of the same :try conditional. Surrounding try | |
3216 " conditionals should be checked for a matching :catch. A previously | |
3217 " thrown exception is discarded. | |
3218 "------------------------------------------------------------------------------- | |
3219 | |
3220 XpathINIT | |
3221 | |
3222 try | |
3223 | |
3224 try | |
3225 try | |
3226 Xpath 1 " X: 1 | |
3227 catch /x1/ | |
3228 Xpath 2 " X: 0 | |
3229 finally | |
3230 Xpath 4 " X: 4 | |
3231 throw "x1" | |
3232 Xpath 8 " X: 0 | |
3233 endtry | |
3234 Xpath 16 " X: 0 | |
3235 catch /x1/ | |
3236 Xpath 32 " X: 32 | |
3237 endtry | |
3238 Xpath 64 " X: 64 | |
3239 | |
3240 try | |
3241 try | |
3242 Xpath 128 " X: 128 | |
3243 throw "x2" | |
3244 Xpath 256 " X: 0 | |
3245 catch /x2/ | |
3246 Xpath 512 " X: 512 | |
3247 catch /x3/ | |
3248 Xpath 1024 " X: 0 | |
3249 finally | |
3250 Xpath 2048 " X: 2048 | |
3251 throw "x3" | |
3252 Xpath 4096 " X: 0 | |
3253 endtry | |
3254 Xpath 8192 " X: 0 | |
3255 catch /x2/ | |
3256 Xpath 16384 " X: 0 | |
3257 catch /x3/ | |
3258 Xpath 32768 " X: 32768 | |
3259 endtry | |
3260 Xpath 65536 " X: 65536 | |
3261 | |
3262 try | |
3263 try | |
3264 try | |
3265 Xpath 131072 " X: 131072 | |
3266 throw "x4" | |
3267 Xpath 262144 " X: 0 | |
3268 catch /x5/ | |
3269 Xpath 524288 " X: 0 | |
3270 finally | |
3271 Xpath 1048576 " X: 1048576 | |
3272 throw "x5" " discards "x4" | |
3273 Xpath 2097152 " X: 0 | |
3274 endtry | |
3275 Xpath 4194304 " X: 0 | |
3276 catch /x4/ | |
3277 Xpath 8388608 " X: 0 | |
3278 finally | |
3279 Xpath 16777216 " X: 16777216 | |
3280 endtry | |
3281 Xpath 33554432 " X: 0 | |
3282 catch /x5/ | |
3283 Xpath 67108864 " X: 67108864 | |
3284 endtry | |
3285 Xpath 134217728 " X: 134217728 | |
3286 | |
3287 catch /.*/ | |
3288 Xpath 268435456 " X: 0 | |
3289 Xout v:exception "in" v:throwpoint | |
3290 endtry | |
3291 Xpath 536870912 " X: 536870912 | |
3292 | |
3293 Xcheck 756255461 | |
3294 | 2095 |
3295 | 2096 |
3296 "------------------------------------------------------------------------------- | 2097 "------------------------------------------------------------------------------- |
3297 " Test 49: Throwing exceptions across functions {{{1 | 2098 " Test 49: Throwing exceptions across functions {{{1 |
3298 " | 2099 " |
3441 unlet scriptC scriptT1 scriptT2 | 2242 unlet scriptC scriptT1 scriptT2 |
3442 delfunction F | 2243 delfunction F |
3443 | 2244 |
3444 Xcheck 363550045 | 2245 Xcheck 363550045 |
3445 | 2246 |
3446 | 2247 " Test 51 was moved to test_trycatch.vim |
3447 "------------------------------------------------------------------------------- | 2248 let Xtest = 52 |
3448 " Test 51: Throwing exceptions across :execute and user commands {{{1 | |
3449 " | |
3450 " A :throw command may be executed under an ":execute" or from | |
3451 " a user command. | |
3452 "------------------------------------------------------------------------------- | |
3453 | |
3454 XpathINIT | |
3455 | |
3456 command! -nargs=? THROW1 throw <args> | throw 1 | |
3457 command! -nargs=? THROW2 try | throw <args> | endtry | throw 2 | |
3458 command! -nargs=? THROW3 try | throw 3 | catch /3/ | throw <args> | endtry | |
3459 command! -nargs=? THROW4 try | throw 4 | finally | throw <args> | endtry | |
3460 | |
3461 try | |
3462 | |
3463 try | |
3464 try | |
3465 Xpath 1 " X: 1 | |
3466 THROW1 "A" | |
3467 catch /A/ | |
3468 Xpath 2 " X: 2 | |
3469 endtry | |
3470 catch /1/ | |
3471 Xpath 4 " X: 0 | |
3472 endtry | |
3473 | |
3474 try | |
3475 try | |
3476 Xpath 8 " X: 8 | |
3477 THROW2 "B" | |
3478 catch /B/ | |
3479 Xpath 16 " X: 16 | |
3480 endtry | |
3481 catch /2/ | |
3482 Xpath 32 " X: 0 | |
3483 endtry | |
3484 | |
3485 try | |
3486 try | |
3487 Xpath 64 " X: 64 | |
3488 THROW3 "C" | |
3489 catch /C/ | |
3490 Xpath 128 " X: 128 | |
3491 endtry | |
3492 catch /3/ | |
3493 Xpath 256 " X: 0 | |
3494 endtry | |
3495 | |
3496 try | |
3497 try | |
3498 Xpath 512 " X: 512 | |
3499 THROW4 "D" | |
3500 catch /D/ | |
3501 Xpath 1024 " X: 1024 | |
3502 endtry | |
3503 catch /4/ | |
3504 Xpath 2048 " X: 0 | |
3505 endtry | |
3506 | |
3507 try | |
3508 try | |
3509 Xpath 4096 " X: 4096 | |
3510 execute 'throw "E" | throw 5' | |
3511 catch /E/ | |
3512 Xpath 8192 " X: 8192 | |
3513 endtry | |
3514 catch /5/ | |
3515 Xpath 16384 " X: 0 | |
3516 endtry | |
3517 | |
3518 try | |
3519 try | |
3520 Xpath 32768 " X: 32768 | |
3521 execute 'try | throw "F" | endtry | throw 6' | |
3522 catch /F/ | |
3523 Xpath 65536 " X: 65536 | |
3524 endtry | |
3525 catch /6/ | |
3526 Xpath 131072 " X: 0 | |
3527 endtry | |
3528 | |
3529 try | |
3530 try | |
3531 Xpath 262144 " X: 262144 | |
3532 execute'try | throw 7 | catch /7/ | throw "G" | endtry' | |
3533 catch /G/ | |
3534 Xpath 524288 " X: 524288 | |
3535 endtry | |
3536 catch /7/ | |
3537 Xpath 1048576 " X: 0 | |
3538 endtry | |
3539 | |
3540 try | |
3541 try | |
3542 Xpath 2097152 " X: 2097152 | |
3543 execute 'try | throw 8 | finally | throw "H" | endtry' | |
3544 catch /H/ | |
3545 Xpath 4194304 " X: 4194304 | |
3546 endtry | |
3547 catch /8/ | |
3548 Xpath 8388608 " X: 0 | |
3549 endtry | |
3550 | |
3551 catch /.*/ | |
3552 Xpath 16777216 " X: 0 | |
3553 Xout v:exception "in" v:throwpoint | |
3554 endtry | |
3555 | |
3556 Xpath 33554432 " X: 33554432 | |
3557 | |
3558 delcommand THROW1 | |
3559 delcommand THROW2 | |
3560 delcommand THROW3 | |
3561 delcommand THROW4 | |
3562 | |
3563 Xcheck 40744667 | |
3564 | 2249 |
3565 | 2250 |
3566 "------------------------------------------------------------------------------- | 2251 "------------------------------------------------------------------------------- |
3567 " Test 52: Uncaught exceptions {{{1 | 2252 " Test 52: Uncaught exceptions {{{1 |
3568 " | 2253 " |
6225 delfunction ARG | 4910 delfunction ARG |
6226 delfunction F | 4911 delfunction F |
6227 | 4912 |
6228 Xcheck 212514423 | 4913 Xcheck 212514423 |
6229 | 4914 |
6230 | 4915 " Tests 69 to 75 were moved to test_trycatch.vim |
6231 "------------------------------------------------------------------------------- | 4916 let Xtest = 76 |
6232 " Test 69: :throw across :if, :elseif, :while {{{1 | |
6233 " | |
6234 " On an :if, :elseif, or :while command, an exception might be thrown | |
6235 " during evaluation of the expression to test. The exception can be | |
6236 " caught by the script. | |
6237 "------------------------------------------------------------------------------- | |
6238 | |
6239 XpathINIT | |
6240 | |
6241 XloopINIT! 1 2 | |
6242 | |
6243 function! THROW(x) | |
6244 XloopNEXT | |
6245 Xloop 1 " X: 1 + 2 + 4 | |
6246 throw a:x | |
6247 endfunction | |
6248 | |
6249 try | |
6250 | |
6251 try | |
6252 Xpath 8 " X: 8 | |
6253 if 4711 == THROW("if") + 111 | |
6254 Xpath 16 " X: 0 | |
6255 else | |
6256 Xpath 32 " X: 0 | |
6257 endif | |
6258 Xpath 64 " X: 0 | |
6259 catch /^if$/ | |
6260 Xpath 128 " X: 128 | |
6261 catch /.*/ | |
6262 Xpath 256 " X: 0 | |
6263 Xout "if:" v:exception "in" v:throwpoint | |
6264 endtry | |
6265 | |
6266 try | |
6267 Xpath 512 " X: 512 | |
6268 if 4711 == 4 + 7 + 1 + 1 | |
6269 Xpath 1024 " X: 0 | |
6270 elseif 4711 == THROW("elseif") + 222 | |
6271 Xpath 2048 " X: 0 | |
6272 else | |
6273 Xpath 4096 " X: 0 | |
6274 endif | |
6275 Xpath 8192 " X: 0 | |
6276 catch /^elseif$/ | |
6277 Xpath 16384 " X: 16384 | |
6278 catch /.*/ | |
6279 Xpath 32768 " X: 0 | |
6280 Xout "elseif:" v:exception "in" v:throwpoint | |
6281 endtry | |
6282 | |
6283 try | |
6284 Xpath 65536 " X: 65536 | |
6285 while 4711 == THROW("while") + 4711 | |
6286 Xpath 131072 " X: 0 | |
6287 break | |
6288 endwhile | |
6289 Xpath 262144 " X: 0 | |
6290 catch /^while$/ | |
6291 Xpath 524288 " X: 524288 | |
6292 catch /.*/ | |
6293 Xpath 1048576 " X: 0 | |
6294 Xout "while:" v:exception "in" v:throwpoint | |
6295 endtry | |
6296 | |
6297 catch /^0$/ " default return value | |
6298 Xpath 2097152 " X: 0 | |
6299 Xout v:throwpoint | |
6300 catch /.*/ | |
6301 Xout v:exception "in" v:throwpoint | |
6302 Xpath 4194304 " X: 0 | |
6303 endtry | |
6304 | |
6305 Xpath 8388608 " X: 8388608 | |
6306 | |
6307 delfunction THROW | |
6308 | |
6309 Xcheck 8995471 | |
6310 | |
6311 | |
6312 "------------------------------------------------------------------------------- | |
6313 " Test 70: :throw across :return or :throw {{{1 | |
6314 " | |
6315 " On a :return or :throw command, an exception might be thrown during | |
6316 " evaluation of the expression to return or throw, respectively. The | |
6317 " exception can be caught by the script. | |
6318 "------------------------------------------------------------------------------- | |
6319 | |
6320 XpathINIT | |
6321 | |
6322 let taken = "" | |
6323 | |
6324 function! THROW(x, n) | |
6325 let g:taken = g:taken . "T" . a:n | |
6326 throw a:x | |
6327 endfunction | |
6328 | |
6329 function! F(x, y, n) | |
6330 let g:taken = g:taken . "F" . a:n | |
6331 return a:x + THROW(a:y, a:n) | |
6332 endfunction | |
6333 | |
6334 function! G(x, y, n) | |
6335 let g:taken = g:taken . "G" . a:n | |
6336 throw a:x . THROW(a:y, a:n) | |
6337 return a:x | |
6338 endfunction | |
6339 | |
6340 try | |
6341 try | |
6342 Xpath 1 " X: 1 | |
6343 call F(4711, "return", 1) | |
6344 Xpath 2 " X: 0 | |
6345 catch /^return$/ | |
6346 Xpath 4 " X: 4 | |
6347 catch /.*/ | |
6348 Xpath 8 " X: 0 | |
6349 Xout "return:" v:exception "in" v:throwpoint | |
6350 endtry | |
6351 | |
6352 try | |
6353 Xpath 16 " X: 16 | |
6354 let var = F(4712, "return-var", 2) | |
6355 Xpath 32 " X: 0 | |
6356 catch /^return-var$/ | |
6357 Xpath 64 " X: 64 | |
6358 catch /.*/ | |
6359 Xpath 128 " X: 0 | |
6360 Xout "return-var:" v:exception "in" v:throwpoint | |
6361 finally | |
6362 unlet! var | |
6363 endtry | |
6364 | |
6365 try | |
6366 Xpath 256 " X: 256 | |
6367 throw "except1" . THROW("throw1", 3) | |
6368 Xpath 512 " X: 0 | |
6369 catch /^except1/ | |
6370 Xpath 1024 " X: 0 | |
6371 catch /^throw1$/ | |
6372 Xpath 2048 " X: 2048 | |
6373 catch /.*/ | |
6374 Xpath 4096 " X: 0 | |
6375 Xout "throw1:" v:exception "in" v:throwpoint | |
6376 endtry | |
6377 | |
6378 try | |
6379 Xpath 8192 " X: 8192 | |
6380 call G("except2", "throw2", 4) | |
6381 Xpath 16384 " X: 0 | |
6382 catch /^except2/ | |
6383 Xpath 32768 " X: 0 | |
6384 catch /^throw2$/ | |
6385 Xpath 65536 " X: 65536 | |
6386 catch /.*/ | |
6387 Xpath 131072 " X: 0 | |
6388 Xout "throw2:" v:exception "in" v:throwpoint | |
6389 endtry | |
6390 | |
6391 try | |
6392 Xpath 262144 " X: 262144 | |
6393 let var = G("except3", "throw3", 5) | |
6394 Xpath 524288 " X: 0 | |
6395 catch /^except3/ | |
6396 Xpath 1048576 " X: 0 | |
6397 catch /^throw3$/ | |
6398 Xpath 2097152 " X: 2097152 | |
6399 catch /.*/ | |
6400 Xpath 4194304 " X: 0 | |
6401 Xout "throw3:" v:exception "in" v:throwpoint | |
6402 finally | |
6403 unlet! var | |
6404 endtry | |
6405 | |
6406 let expected = "F1T1F2T2T3G4T4G5T5" | |
6407 if taken != expected | |
6408 Xpath 8388608 " X: 0 | |
6409 Xout "'taken' is" taken "instead of" expected | |
6410 endif | |
6411 | |
6412 catch /^0$/ " default return value | |
6413 Xpath 16777216 " X: 0 | |
6414 Xout v:throwpoint | |
6415 catch /.*/ | |
6416 Xpath 33554432 " X: 0 | |
6417 Xout v:exception "in" v:throwpoint | |
6418 endtry | |
6419 | |
6420 Xpath 67108864 " X: 67108864 | |
6421 | |
6422 unlet taken expected | |
6423 delfunction THROW | |
6424 delfunction F | |
6425 delfunction G | |
6426 | |
6427 Xcheck 69544277 | |
6428 | |
6429 | |
6430 "------------------------------------------------------------------------------- | |
6431 " Test 71: :throw across :echo variants and :execute {{{1 | |
6432 " | |
6433 " On an :echo, :echon, :echomsg, :echoerr, or :execute command, an | |
6434 " exception might be thrown during evaluation of the arguments to | |
6435 " be displayed or executed as a command, respectively. Any following | |
6436 " arguments are not evaluated, then. The exception can be caught by | |
6437 " the script. | |
6438 "------------------------------------------------------------------------------- | |
6439 | |
6440 XpathINIT | |
6441 | |
6442 let taken = "" | |
6443 | |
6444 function! THROW(x, n) | |
6445 let g:taken = g:taken . "T" . a:n | |
6446 throw a:x | |
6447 endfunction | |
6448 | |
6449 function! F(n) | |
6450 let g:taken = g:taken . "F" . a:n | |
6451 return "F" . a:n | |
6452 endfunction | |
6453 | |
6454 try | |
6455 try | |
6456 Xpath 1 " X: 1 | |
6457 echo "echo" . THROW("echo-except", 1) F(1) | |
6458 Xpath 2 " X: 0 | |
6459 catch /^echo-except$/ | |
6460 Xpath 4 " X: 4 | |
6461 catch /.*/ | |
6462 Xpath 8 " X: 0 | |
6463 Xout "echo:" v:exception "in" v:throwpoint | |
6464 endtry | |
6465 | |
6466 try | |
6467 Xpath 16 " X: 16 | |
6468 echon "echon" . THROW("echon-except", 2) F(2) | |
6469 Xpath 32 " X: 0 | |
6470 catch /^echon-except$/ | |
6471 Xpath 64 " X: 64 | |
6472 catch /.*/ | |
6473 Xpath 128 " X: 0 | |
6474 Xout "echon:" v:exception "in" v:throwpoint | |
6475 endtry | |
6476 | |
6477 try | |
6478 Xpath 256 " X: 256 | |
6479 echomsg "echomsg" . THROW("echomsg-except", 3) F(3) | |
6480 Xpath 512 " X: 0 | |
6481 catch /^echomsg-except$/ | |
6482 Xpath 1024 " X: 1024 | |
6483 catch /.*/ | |
6484 Xpath 2048 " X: 0 | |
6485 Xout "echomsg:" v:exception "in" v:throwpoint | |
6486 endtry | |
6487 | |
6488 try | |
6489 Xpath 4096 " X: 4096 | |
6490 echoerr "echoerr" . THROW("echoerr-except", 4) F(4) | |
6491 Xpath 8192 " X: 0 | |
6492 catch /^echoerr-except$/ | |
6493 Xpath 16384 " X: 16384 | |
6494 catch /Vim/ | |
6495 Xpath 32768 " X: 0 | |
6496 catch /echoerr/ | |
6497 Xpath 65536 " X: 0 | |
6498 catch /.*/ | |
6499 Xpath 131072 " X: 0 | |
6500 Xout "echoerr:" v:exception "in" v:throwpoint | |
6501 endtry | |
6502 | |
6503 try | |
6504 Xpath 262144 " X: 262144 | |
6505 execute "echo 'execute" . THROW("execute-except", 5) F(5) "'" | |
6506 Xpath 524288 " X: 0 | |
6507 catch /^execute-except$/ | |
6508 Xpath 1048576 " X: 1048576 | |
6509 catch /.*/ | |
6510 Xpath 2097152 " X: 0 | |
6511 Xout "execute:" v:exception "in" v:throwpoint | |
6512 endtry | |
6513 | |
6514 let expected = "T1T2T3T4T5" | |
6515 if taken != expected | |
6516 Xpath 4194304 " X: 0 | |
6517 Xout "'taken' is" taken "instead of" expected | |
6518 endif | |
6519 | |
6520 catch /^0$/ " default return value | |
6521 Xpath 8388608 " X: 0 | |
6522 Xout v:throwpoint | |
6523 catch /.*/ | |
6524 Xpath 16777216 " X: 0 | |
6525 Xout v:exception "in" v:throwpoint | |
6526 endtry | |
6527 | |
6528 Xpath 33554432 " X: 33554432 | |
6529 | |
6530 unlet taken expected | |
6531 delfunction THROW | |
6532 delfunction F | |
6533 | |
6534 Xcheck 34886997 | |
6535 | |
6536 | |
6537 "------------------------------------------------------------------------------- | |
6538 " Test 72: :throw across :let or :unlet {{{1 | |
6539 " | |
6540 " On a :let command, an exception might be thrown during evaluation | |
6541 " of the expression to assign. On an :let or :unlet command, the | |
6542 " evaluation of the name of the variable to be assigned or list or | |
6543 " deleted, respectively, may throw an exception. Any following | |
6544 " arguments are not evaluated, then. The exception can be caught by | |
6545 " the script. | |
6546 "------------------------------------------------------------------------------- | |
6547 | |
6548 XpathINIT | |
6549 | |
6550 let throwcount = 0 | |
6551 | |
6552 function! THROW(x) | |
6553 let g:throwcount = g:throwcount + 1 | |
6554 throw a:x | |
6555 endfunction | |
6556 | |
6557 try | |
6558 try | |
6559 let $VAR = "old_value" | |
6560 Xpath 1 " X: 1 | |
6561 let $VAR = "let(" . THROW("var") . ")" | |
6562 Xpath 2 " X: 0 | |
6563 catch /^var$/ | |
6564 Xpath 4 " X: 4 | |
6565 finally | |
6566 if $VAR != "old_value" | |
6567 Xpath 8 " X: 0 | |
6568 endif | |
6569 endtry | |
6570 | |
6571 try | |
6572 let @a = "old_value" | |
6573 Xpath 16 " X: 16 | |
6574 let @a = "let(" . THROW("reg") . ")" | |
6575 Xpath 32 " X: 0 | |
6576 catch /^reg$/ | |
6577 try | |
6578 Xpath 64 " X: 64 | |
6579 let @A = "let(" . THROW("REG") . ")" | |
6580 Xpath 128 " X: 0 | |
6581 catch /^REG$/ | |
6582 Xpath 256 " X: 256 | |
6583 endtry | |
6584 finally | |
6585 if @a != "old_value" | |
6586 Xpath 512 " X: 0 | |
6587 endif | |
6588 if @A != "old_value" | |
6589 Xpath 1024 " X: 0 | |
6590 endif | |
6591 endtry | |
6592 | |
6593 try | |
6594 let saved_gpath = &g:path | |
6595 let saved_lpath = &l:path | |
6596 Xpath 2048 " X: 2048 | |
6597 let &path = "let(" . THROW("opt") . ")" | |
6598 Xpath 4096 " X: 0 | |
6599 catch /^opt$/ | |
6600 try | |
6601 Xpath 8192 " X: 8192 | |
6602 let &g:path = "let(" . THROW("gopt") . ")" | |
6603 Xpath 16384 " X: 0 | |
6604 catch /^gopt$/ | |
6605 try | |
6606 Xpath 32768 " X: 32768 | |
6607 let &l:path = "let(" . THROW("lopt") . ")" | |
6608 Xpath 65536 " X: 0 | |
6609 catch /^lopt$/ | |
6610 Xpath 131072 " X: 131072 | |
6611 endtry | |
6612 endtry | |
6613 finally | |
6614 if &g:path != saved_gpath || &l:path != saved_lpath | |
6615 Xpath 262144 " X: 0 | |
6616 endif | |
6617 let &g:path = saved_gpath | |
6618 let &l:path = saved_lpath | |
6619 endtry | |
6620 | |
6621 unlet! var1 var2 var3 | |
6622 | |
6623 try | |
6624 Xpath 524288 " X: 524288 | |
6625 let var1 = "let(" . THROW("var1") . ")" | |
6626 Xpath 1048576 " X: 0 | |
6627 catch /^var1$/ | |
6628 Xpath 2097152 " X: 2097152 | |
6629 finally | |
6630 if exists("var1") | |
6631 Xpath 4194304 " X: 0 | |
6632 endif | |
6633 endtry | |
6634 | |
6635 try | |
6636 let var2 = "old_value" | |
6637 Xpath 8388608 " X: 8388608 | |
6638 let var2 = "let(" . THROW("var2"). ")" | |
6639 Xpath 16777216 " X: 0 | |
6640 catch /^var2$/ | |
6641 Xpath 33554432 " X: 33554432 | |
6642 finally | |
6643 if var2 != "old_value" | |
6644 Xpath 67108864 " X: 0 | |
6645 endif | |
6646 endtry | |
6647 | |
6648 try | |
6649 Xpath 134217728 " X: 134217728 | |
6650 let var{THROW("var3")} = 4711 | |
6651 Xpath 268435456 " X: 0 | |
6652 catch /^var3$/ | |
6653 Xpath 536870912 " X: 536870912 | |
6654 endtry | |
6655 | |
6656 let addpath = "" | |
6657 | |
6658 function ADDPATH(p) | |
6659 let g:addpath = g:addpath . a:p | |
6660 endfunction | |
6661 | |
6662 try | |
6663 call ADDPATH("T1") | |
6664 let var{THROW("var4")} var{ADDPATH("T2")} | call ADDPATH("T3") | |
6665 call ADDPATH("T4") | |
6666 catch /^var4$/ | |
6667 call ADDPATH("T5") | |
6668 endtry | |
6669 | |
6670 try | |
6671 call ADDPATH("T6") | |
6672 unlet var{THROW("var5")} var{ADDPATH("T7")} | call ADDPATH("T8") | |
6673 call ADDPATH("T9") | |
6674 catch /^var5$/ | |
6675 call ADDPATH("T10") | |
6676 endtry | |
6677 | |
6678 if addpath != "T1T5T6T10" || throwcount != 11 | |
6679 throw "addpath: " . addpath . ", throwcount: " . throwcount | |
6680 endif | |
6681 | |
6682 Xpath 1073741824 " X: 1073741824 | |
6683 | |
6684 catch /.*/ | |
6685 " The Xpath command does not accept 2^31 (negative); add explicitly: | |
6686 let Xpath = Xpath + 2147483648 " X: 0 | |
6687 Xout v:exception "in" v:throwpoint | |
6688 endtry | |
6689 | |
6690 unlet! var1 var2 var3 addpath throwcount | |
6691 delfunction THROW | |
6692 | |
6693 Xcheck 1789569365 | |
6694 | |
6695 | |
6696 "------------------------------------------------------------------------------- | |
6697 " Test 73: :throw across :function, :delfunction {{{1 | |
6698 " | |
6699 " The :function and :delfunction commands may cause an expression | |
6700 " specified in braces to be evaluated. During evaluation, an | |
6701 " exception might be thrown. The exception can be caught by the | |
6702 " script. | |
6703 "------------------------------------------------------------------------------- | |
6704 | |
6705 XpathINIT | |
6706 | |
6707 let taken = "" | |
6708 | |
6709 function! THROW(x, n) | |
6710 let g:taken = g:taken . "T" . a:n | |
6711 throw a:x | |
6712 endfunction | |
6713 | |
6714 function! EXPR(x, n) | |
6715 let g:taken = g:taken . "E" . a:n | |
6716 if a:n % 2 == 0 | |
6717 call THROW(a:x, a:n) | |
6718 endif | |
6719 return 2 - a:n % 2 | |
6720 endfunction | |
6721 | |
6722 try | |
6723 try | |
6724 " Define function. | |
6725 Xpath 1 " X: 1 | |
6726 function! F0() | |
6727 endfunction | |
6728 Xpath 2 " X: 2 | |
6729 function! F{EXPR("function-def-ok", 1)}() | |
6730 endfunction | |
6731 Xpath 4 " X: 4 | |
6732 function! F{EXPR("function-def", 2)}() | |
6733 endfunction | |
6734 Xpath 8 " X: 0 | |
6735 catch /^function-def-ok$/ | |
6736 Xpath 16 " X: 0 | |
6737 catch /^function-def$/ | |
6738 Xpath 32 " X: 32 | |
6739 catch /.*/ | |
6740 Xpath 64 " X: 0 | |
6741 Xout "def:" v:exception "in" v:throwpoint | |
6742 endtry | |
6743 | |
6744 try | |
6745 " List function. | |
6746 Xpath 128 " X: 128 | |
6747 function F0 | |
6748 Xpath 256 " X: 256 | |
6749 function F{EXPR("function-lst-ok", 3)} | |
6750 Xpath 512 " X: 512 | |
6751 function F{EXPR("function-lst", 4)} | |
6752 Xpath 1024 " X: 0 | |
6753 catch /^function-lst-ok$/ | |
6754 Xpath 2048 " X: 0 | |
6755 catch /^function-lst$/ | |
6756 Xpath 4096 " X: 4096 | |
6757 catch /.*/ | |
6758 Xpath 8192 " X: 0 | |
6759 Xout "lst:" v:exception "in" v:throwpoint | |
6760 endtry | |
6761 | |
6762 try | |
6763 " Delete function | |
6764 Xpath 16384 " X: 16384 | |
6765 delfunction F0 | |
6766 Xpath 32768 " X: 32768 | |
6767 delfunction F{EXPR("function-del-ok", 5)} | |
6768 Xpath 65536 " X: 65536 | |
6769 delfunction F{EXPR("function-del", 6)} | |
6770 Xpath 131072 " X: 0 | |
6771 catch /^function-del-ok$/ | |
6772 Xpath 262144 " X: 0 | |
6773 catch /^function-del$/ | |
6774 Xpath 524288 " X: 524288 | |
6775 catch /.*/ | |
6776 Xpath 1048576 " X: 0 | |
6777 Xout "del:" v:exception "in" v:throwpoint | |
6778 endtry | |
6779 | |
6780 let expected = "E1E2T2E3E4T4E5E6T6" | |
6781 if taken != expected | |
6782 Xpath 2097152 " X: 0 | |
6783 Xout "'taken' is" taken "instead of" expected | |
6784 endif | |
6785 | |
6786 catch /.*/ | |
6787 Xpath 4194304 " X: 0 | |
6788 Xout v:exception "in" v:throwpoint | |
6789 endtry | |
6790 | |
6791 Xpath 8388608 " X: 8388608 | |
6792 | |
6793 unlet taken expected | |
6794 delfunction THROW | |
6795 delfunction EXPR | |
6796 | |
6797 Xcheck 9032615 | |
6798 | |
6799 | |
6800 "------------------------------------------------------------------------------- | |
6801 " Test 74: :throw across builtin functions and commands {{{1 | |
6802 " | |
6803 " Some functions like exists(), searchpair() take expression | |
6804 " arguments, other functions or commands like substitute() or | |
6805 " :substitute cause an expression (specified in the regular | |
6806 " expression) to be evaluated. During evaluation an exception | |
6807 " might be thrown. The exception can be caught by the script. | |
6808 "------------------------------------------------------------------------------- | |
6809 | |
6810 XpathINIT | |
6811 | |
6812 let taken = "" | |
6813 | |
6814 function! THROW(x, n) | |
6815 let g:taken = g:taken . "T" . a:n | |
6816 throw a:x | |
6817 endfunction | |
6818 | |
6819 function! EXPR(x, n) | |
6820 let g:taken = g:taken . "E" . a:n | |
6821 call THROW(a:x . a:n, a:n) | |
6822 return "EXPR" | |
6823 endfunction | |
6824 | |
6825 function! SKIP(x, n) | |
6826 let g:taken = g:taken . "S" . a:n . "(" . line(".") | |
6827 let theline = getline(".") | |
6828 if theline =~ "skip" | |
6829 let g:taken = g:taken . "s)" | |
6830 return 1 | |
6831 elseif theline =~ "throw" | |
6832 let g:taken = g:taken . "t)" | |
6833 call THROW(a:x . a:n, a:n) | |
6834 else | |
6835 let g:taken = g:taken . ")" | |
6836 return 0 | |
6837 endif | |
6838 endfunction | |
6839 | |
6840 function! SUBST(x, n) | |
6841 let g:taken = g:taken . "U" . a:n . "(" . line(".") | |
6842 let theline = getline(".") | |
6843 if theline =~ "not" " SUBST() should not be called for this line | |
6844 let g:taken = g:taken . "n)" | |
6845 call THROW(a:x . a:n, a:n) | |
6846 elseif theline =~ "throw" | |
6847 let g:taken = g:taken . "t)" | |
6848 call THROW(a:x . a:n, a:n) | |
6849 else | |
6850 let g:taken = g:taken . ")" | |
6851 return "replaced" | |
6852 endif | |
6853 endfunction | |
6854 | |
6855 try | |
6856 try | |
6857 Xpath 1 " X: 1 | |
6858 let result = exists('*{EXPR("exists", 1)}') | |
6859 Xpath 2 " X: 0 | |
6860 catch /^exists1$/ | |
6861 Xpath 4 " X: 4 | |
6862 try | |
6863 let result = exists('{EXPR("exists", 2)}') | |
6864 Xpath 8 " X: 0 | |
6865 catch /^exists2$/ | |
6866 Xpath 16 " X: 16 | |
6867 catch /.*/ | |
6868 Xpath 32 " X: 0 | |
6869 Xout "exists2:" v:exception "in" v:throwpoint | |
6870 endtry | |
6871 catch /.*/ | |
6872 Xpath 64 " X: 0 | |
6873 Xout "exists1:" v:exception "in" v:throwpoint | |
6874 endtry | |
6875 | |
6876 try | |
6877 let file = tempname() | |
6878 exec "edit" file | |
6879 insert | |
6880 begin | |
6881 xx | |
6882 middle 3 | |
6883 xx | |
6884 middle 5 skip | |
6885 xx | |
6886 middle 7 throw | |
6887 xx | |
6888 end | |
6889 . | |
6890 normal! gg | |
6891 Xpath 128 " X: 128 | |
6892 let result = | |
6893 \ searchpair("begin", "middle", "end", '', 'SKIP("searchpair", 3)') | |
6894 Xpath 256 " X: 256 | |
6895 let result = | |
6896 \ searchpair("begin", "middle", "end", '', 'SKIP("searchpair", 4)') | |
6897 Xpath 512 " X: 0 | |
6898 let result = | |
6899 \ searchpair("begin", "middle", "end", '', 'SKIP("searchpair", 5)') | |
6900 Xpath 1024 " X: 0 | |
6901 catch /^searchpair[35]$/ | |
6902 Xpath 2048 " X: 0 | |
6903 catch /^searchpair4$/ | |
6904 Xpath 4096 " X: 4096 | |
6905 catch /.*/ | |
6906 Xpath 8192 " X: 0 | |
6907 Xout "searchpair:" v:exception "in" v:throwpoint | |
6908 finally | |
6909 bwipeout! | |
6910 call delete(file) | |
6911 endtry | |
6912 | |
6913 try | |
6914 let file = tempname() | |
6915 exec "edit" file | |
6916 insert | |
6917 subst 1 | |
6918 subst 2 | |
6919 not | |
6920 subst 4 | |
6921 subst throw | |
6922 subst 6 | |
6923 . | |
6924 normal! gg | |
6925 Xpath 16384 " X: 16384 | |
6926 1,2substitute/subst/\=SUBST("substitute", 6)/ | |
6927 try | |
6928 Xpath 32768 " X: 32768 | |
6929 try | |
6930 let v:errmsg = "" | |
6931 3substitute/subst/\=SUBST("substitute", 7)/ | |
6932 finally | |
6933 if v:errmsg != "" | |
6934 " If exceptions are not thrown on errors, fake the error | |
6935 " exception in order to get the same execution path. | |
6936 throw "faked Vim(substitute)" | |
6937 endif | |
6938 endtry | |
6939 catch /Vim(substitute)/ " Pattern not found ('e' flag missing) | |
6940 Xpath 65536 " X: 65536 | |
6941 3substitute/subst/\=SUBST("substitute", 8)/e | |
6942 Xpath 131072 " X: 131072 | |
6943 endtry | |
6944 Xpath 262144 " X: 262144 | |
6945 4,6substitute/subst/\=SUBST("substitute", 9)/ | |
6946 Xpath 524288 " X: 0 | |
6947 catch /^substitute[678]/ | |
6948 Xpath 1048576 " X: 0 | |
6949 catch /^substitute9/ | |
6950 Xpath 2097152 " X: 2097152 | |
6951 finally | |
6952 bwipeout! | |
6953 call delete(file) | |
6954 endtry | |
6955 | |
6956 try | |
6957 Xpath 4194304 " X: 4194304 | |
6958 let var = substitute("sub", "sub", '\=THROW("substitute()y", 10)', '') | |
6959 Xpath 8388608 " X: 0 | |
6960 catch /substitute()y/ | |
6961 Xpath 16777216 " X: 16777216 | |
6962 catch /.*/ | |
6963 Xpath 33554432 " X: 0 | |
6964 Xout "substitute()y:" v:exception "in" v:throwpoint | |
6965 endtry | |
6966 | |
6967 try | |
6968 Xpath 67108864 " X: 67108864 | |
6969 let var = substitute("not", "sub", '\=THROW("substitute()n", 11)', '') | |
6970 Xpath 134217728 " X: 134217728 | |
6971 catch /substitute()n/ | |
6972 Xpath 268435456 " X: 0 | |
6973 catch /.*/ | |
6974 Xpath 536870912 " X: 0 | |
6975 Xout "substitute()n:" v:exception "in" v:throwpoint | |
6976 endtry | |
6977 | |
6978 let expected = "E1T1E2T2S3(3)S4(5s)S4(7t)T4U6(1)U6(2)U9(4)U9(5t)T9T10" | |
6979 if taken != expected | |
6980 Xpath 1073741824 " X: 0 | |
6981 Xout "'taken' is" taken "instead of" expected | |
6982 endif | |
6983 | |
6984 catch /.*/ | |
6985 " The Xpath command does not accept 2^31 (negative); add explicitly: | |
6986 let Xpath = Xpath + 2147483648 " X: 0 | |
6987 Xout v:exception "in" v:throwpoint | |
6988 endtry | |
6989 | |
6990 unlet result var taken expected | |
6991 delfunction THROW | |
6992 delfunction EXPR | |
6993 delfunction SKIP | |
6994 delfunction SUBST | |
6995 | |
6996 Xcheck 224907669 | |
6997 | |
6998 | |
6999 "------------------------------------------------------------------------------- | |
7000 " Test 75: Errors in builtin functions. {{{1 | |
7001 " | |
7002 " On an error in a builtin function called inside a :try/:endtry | |
7003 " region, the evaluation of the expression calling that function and | |
7004 " the command containing that expression are abandoned. The error can | |
7005 " be caught as an exception. | |
7006 " | |
7007 " A simple :call of the builtin function is a trivial case. If the | |
7008 " builtin function is called in the argument list of another function, | |
7009 " no further arguments are evaluated, and the other function is not | |
7010 " executed. If the builtin function is called from the argument of | |
7011 " a :return command, the :return command is not executed. If the | |
7012 " builtin function is called from the argument of a :throw command, | |
7013 " the :throw command is not executed. The evaluation of the | |
7014 " expression calling the builtin function is abandoned. | |
7015 "------------------------------------------------------------------------------- | |
7016 | |
7017 XpathINIT | |
7018 | |
7019 function! F1(arg1) | |
7020 Xpath 1 " X: 0 | |
7021 endfunction | |
7022 | |
7023 function! F2(arg1, arg2) | |
7024 Xpath 2 " X: 0 | |
7025 endfunction | |
7026 | |
7027 function! G() | |
7028 Xpath 4 " X: 0 | |
7029 endfunction | |
7030 | |
7031 function! H() | |
7032 Xpath 8 " X: 0 | |
7033 endfunction | |
7034 | |
7035 function! R() | |
7036 while 1 | |
7037 try | |
7038 let caught = 0 | |
7039 let v:errmsg = "" | |
7040 Xpath 16 " X: 16 | |
7041 return append(1, "s") | |
7042 catch /E21/ | |
7043 let caught = 1 | |
7044 catch /.*/ | |
7045 Xpath 32 " X: 0 | |
7046 finally | |
7047 Xpath 64 " X: 64 | |
7048 if caught || $VIMNOERRTHROW && v:errmsg =~ 'E21' | |
7049 Xpath 128 " X: 128 | |
7050 endif | |
7051 break " discard error for $VIMNOERRTHROW | |
7052 endtry | |
7053 endwhile | |
7054 Xpath 256 " X: 256 | |
7055 endfunction | |
7056 | |
7057 try | |
7058 set noma " let append() fail with "E21" | |
7059 | |
7060 while 1 | |
7061 try | |
7062 let caught = 0 | |
7063 let v:errmsg = "" | |
7064 Xpath 512 " X: 512 | |
7065 call append(1, "s") | |
7066 catch /E21/ | |
7067 let caught = 1 | |
7068 catch /.*/ | |
7069 Xpath 1024 " X: 0 | |
7070 finally | |
7071 Xpath 2048 " X: 2048 | |
7072 if caught || $VIMNOERRTHROW && v:errmsg =~ 'E21' | |
7073 Xpath 4096 " X: 4096 | |
7074 endif | |
7075 break " discard error for $VIMNOERRTHROW | |
7076 endtry | |
7077 endwhile | |
7078 | |
7079 while 1 | |
7080 try | |
7081 let caught = 0 | |
7082 let v:errmsg = "" | |
7083 Xpath 8192 " X: 8192 | |
7084 call F1('x' . append(1, "s")) | |
7085 catch /E21/ | |
7086 let caught = 1 | |
7087 catch /.*/ | |
7088 Xpath 16384 " X: 0 | |
7089 finally | |
7090 Xpath 32768 " X: 32768 | |
7091 if caught || $VIMNOERRTHROW && v:errmsg =~ 'E21' | |
7092 Xpath 65536 " X: 65536 | |
7093 endif | |
7094 break " discard error for $VIMNOERRTHROW | |
7095 endtry | |
7096 endwhile | |
7097 | |
7098 while 1 | |
7099 try | |
7100 let caught = 0 | |
7101 let v:errmsg = "" | |
7102 Xpath 131072 " X: 131072 | |
7103 call F2('x' . append(1, "s"), G()) | |
7104 catch /E21/ | |
7105 let caught = 1 | |
7106 catch /.*/ | |
7107 Xpath 262144 " X: 0 | |
7108 finally | |
7109 Xpath 524288 " X: 524288 | |
7110 if caught || $VIMNOERRTHROW && v:errmsg =~ 'E21' | |
7111 Xpath 1048576 " X: 1048576 | |
7112 endif | |
7113 break " discard error for $VIMNOERRTHROW | |
7114 endtry | |
7115 endwhile | |
7116 | |
7117 call R() | |
7118 | |
7119 while 1 | |
7120 try | |
7121 let caught = 0 | |
7122 let v:errmsg = "" | |
7123 Xpath 2097152 " X: 2097152 | |
7124 throw "T" . append(1, "s") | |
7125 catch /E21/ | |
7126 let caught = 1 | |
7127 catch /^T.*/ | |
7128 Xpath 4194304 " X: 0 | |
7129 catch /.*/ | |
7130 Xpath 8388608 " X: 0 | |
7131 finally | |
7132 Xpath 16777216 " X: 16777216 | |
7133 if caught || $VIMNOERRTHROW && v:errmsg =~ 'E21' | |
7134 Xpath 33554432 " X: 33554432 | |
7135 endif | |
7136 break " discard error for $VIMNOERRTHROW | |
7137 endtry | |
7138 endwhile | |
7139 | |
7140 while 1 | |
7141 try | |
7142 let caught = 0 | |
7143 let v:errmsg = "" | |
7144 Xpath 67108864 " X: 67108864 | |
7145 let x = "a" | |
7146 let x = x . "b" . append(1, "s") . H() | |
7147 catch /E21/ | |
7148 let caught = 1 | |
7149 catch /.*/ | |
7150 Xpath 134217728 " X: 0 | |
7151 finally | |
7152 Xpath 268435456 " X: 268435456 | |
7153 if caught || $VIMNOERRTHROW && v:errmsg =~ 'E21' | |
7154 Xpath 536870912 " X: 536870912 | |
7155 endif | |
7156 if x == "a" | |
7157 Xpath 1073741824 " X: 1073741824 | |
7158 endif | |
7159 break " discard error for $VIMNOERRTHROW | |
7160 endtry | |
7161 endwhile | |
7162 catch /.*/ | |
7163 " The Xpath command does not accept 2^31 (negative); add explicitly: | |
7164 let Xpath = Xpath + 2147483648 " X: 0 | |
7165 Xout v:exception "in" v:throwpoint | |
7166 finally | |
7167 set ma& | |
7168 endtry | |
7169 | |
7170 unlet! caught x | |
7171 delfunction F1 | |
7172 delfunction F2 | |
7173 delfunction G | |
7174 delfunction H | |
7175 delfunction R | |
7176 | |
7177 Xcheck 2000403408 | |
7178 | 4917 |
7179 | 4918 |
7180 "------------------------------------------------------------------------------- | 4919 "------------------------------------------------------------------------------- |
7181 " Test 76: Errors, interrupts, :throw during expression evaluation {{{1 | 4920 " Test 76: Errors, interrupts, :throw during expression evaluation {{{1 |
7182 " | 4921 " |
8778 | 6517 |
8779 delfunction F | 6518 delfunction F |
8780 Xout "No Crash for vimgrep on BufUnload" | 6519 Xout "No Crash for vimgrep on BufUnload" |
8781 Xcheck 0 | 6520 Xcheck 0 |
8782 | 6521 |
8783 "------------------------------------------------------------------------------- | 6522 " Test 87 was moved to test_vimscript.vim |
8784 " Test 87 using (expr) ? funcref : funcref {{{1 | 6523 let Xtest = 88 |
8785 " | 6524 |
8786 " Vim needs to correctly parse the funcref and even when it does | |
8787 " not execute the funcref, it needs to consume the trailing () | |
8788 "------------------------------------------------------------------------------- | |
8789 | |
8790 XpathINIT | |
8791 | |
8792 func Add2(x1, x2) | |
8793 return a:x1 + a:x2 | |
8794 endfu | |
8795 | |
8796 func GetStr() | |
8797 return "abcdefghijklmnopqrstuvwxyp" | |
8798 endfu | |
8799 | |
8800 echo function('Add2')(2,3) | |
8801 | |
8802 Xout 1 ? function('Add2')(1,2) : function('Add2')(2,3) | |
8803 Xout 0 ? function('Add2')(1,2) : function('Add2')(2,3) | |
8804 " Make sure, GetStr() still works. | |
8805 Xout GetStr()[0:10] | |
8806 | |
8807 | |
8808 delfunction GetStr | |
8809 delfunction Add2 | |
8810 Xout "Successfully executed funcref Add2" | |
8811 | |
8812 Xcheck 0 | |
8813 | 6525 |
8814 "------------------------------------------------------------------------------- | 6526 "------------------------------------------------------------------------------- |
8815 " Test 88: $VIMNOERRTHROW and $VIMNOINTTHROW support {{{1 | 6527 " Test 88: $VIMNOERRTHROW and $VIMNOINTTHROW support {{{1 |
8816 " | 6528 " |
8817 " It is possible to configure Vim for throwing exceptions on error | 6529 " It is possible to configure Vim for throwing exceptions on error |