Mercurial > vim
comparison src/testdir/test_vimscript.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 | 8a2fb21c23c0 |
children | ed9690c0f27c |
comparison
equal
deleted
inserted
replaced
18503:d946c71f8b4c | 18504:ece46bd3c9af |
---|---|
921 func Test_if_bar_fail() | 921 func Test_if_bar_fail() |
922 call assert_equal('acdfh-acfh', g:test15_result) | 922 call assert_equal('acdfh-acfh', g:test15_result) |
923 endfunc | 923 endfunc |
924 | 924 |
925 "------------------------------------------------------------------------------- | 925 "------------------------------------------------------------------------------- |
926 " Test 16: Double :else or :elseif after :else {{{1 | |
927 " | |
928 " Multiple :elses or an :elseif after an :else are forbidden. | |
929 "------------------------------------------------------------------------------- | |
930 | |
931 func T16_F() abort | |
932 if 0 | |
933 Xpath 'a' | |
934 else | |
935 Xpath 'b' | |
936 else " aborts function | |
937 Xpath 'c' | |
938 endif | |
939 Xpath 'd' | |
940 endfunc | |
941 | |
942 func T16_G() abort | |
943 if 0 | |
944 Xpath 'a' | |
945 else | |
946 Xpath 'b' | |
947 elseif 1 " aborts function | |
948 Xpath 'c' | |
949 else | |
950 Xpath 'd' | |
951 endif | |
952 Xpath 'e' | |
953 endfunc | |
954 | |
955 func T16_H() abort | |
956 if 0 | |
957 Xpath 'a' | |
958 elseif 0 | |
959 Xpath 'b' | |
960 else | |
961 Xpath 'c' | |
962 else " aborts function | |
963 Xpath 'd' | |
964 endif | |
965 Xpath 'e' | |
966 endfunc | |
967 | |
968 func T16_I() abort | |
969 if 0 | |
970 Xpath 'a' | |
971 elseif 0 | |
972 Xpath 'b' | |
973 else | |
974 Xpath 'c' | |
975 elseif 1 " aborts function | |
976 Xpath 'd' | |
977 else | |
978 Xpath 'e' | |
979 endif | |
980 Xpath 'f' | |
981 endfunc | |
982 | |
983 func Test_Multi_Else() | |
984 XpathINIT | |
985 try | |
986 call T16_F() | |
987 catch /E583:/ | |
988 Xpath 'e' | |
989 endtry | |
990 call assert_equal('be', g:Xpath) | |
991 | |
992 XpathINIT | |
993 try | |
994 call T16_G() | |
995 catch /E584:/ | |
996 Xpath 'f' | |
997 endtry | |
998 call assert_equal('bf', g:Xpath) | |
999 | |
1000 XpathINIT | |
1001 try | |
1002 call T16_H() | |
1003 catch /E583:/ | |
1004 Xpath 'f' | |
1005 endtry | |
1006 call assert_equal('cf', g:Xpath) | |
1007 | |
1008 XpathINIT | |
1009 try | |
1010 call T16_I() | |
1011 catch /E584:/ | |
1012 Xpath 'g' | |
1013 endtry | |
1014 call assert_equal('cg', g:Xpath) | |
1015 endfunc | |
1016 | |
1017 "------------------------------------------------------------------------------- | |
1018 " Test 17: Nesting of unmatched :if or :endif inside a :while {{{1 | |
1019 " | |
1020 " The :while/:endwhile takes precedence in nesting over an unclosed | |
1021 " :if or an unopened :endif. | |
1022 "------------------------------------------------------------------------------- | |
1023 | |
1024 " While loops inside a function are continued on error. | |
1025 func T17_F() | |
1026 let loops = 3 | |
1027 while loops > 0 | |
1028 let loops -= 1 | |
1029 Xpath 'a' . loops | |
1030 if (loops == 1) | |
1031 Xpath 'b' . loops | |
1032 continue | |
1033 elseif (loops == 0) | |
1034 Xpath 'c' . loops | |
1035 break | |
1036 elseif 1 | |
1037 Xpath 'd' . loops | |
1038 " endif missing! | |
1039 endwhile " :endwhile after :if 1 | |
1040 Xpath 'e' | |
1041 endfunc | |
1042 | |
1043 func T17_G() | |
1044 let loops = 2 | |
1045 while loops > 0 | |
1046 let loops -= 1 | |
1047 Xpath 'a' . loops | |
1048 if 0 | |
1049 Xpath 'b' . loops | |
1050 " endif missing | |
1051 endwhile " :endwhile after :if 0 | |
1052 endfunc | |
1053 | |
1054 func T17_H() | |
1055 let loops = 2 | |
1056 while loops > 0 | |
1057 let loops -= 1 | |
1058 Xpath 'a' . loops | |
1059 " if missing! | |
1060 endif " :endif without :if in while | |
1061 Xpath 'b' . loops | |
1062 endwhile | |
1063 endfunc | |
1064 | |
1065 " Error continuation outside a function is at the outermost :endwhile or :endif. | |
1066 XpathINIT | |
1067 let v:errmsg = '' | |
1068 let loops = 2 | |
1069 while loops > 0 | |
1070 let loops -= 1 | |
1071 Xpath 'a' . loops | |
1072 if 0 | |
1073 Xpath 'b' . loops | |
1074 " endif missing! Following :endwhile fails. | |
1075 endwhile | Xpath 'c' | |
1076 Xpath 'd' | |
1077 call assert_match('E171:', v:errmsg) | |
1078 call assert_equal('a1d', g:Xpath) | |
1079 | |
1080 func Test_unmatched_if_in_while() | |
1081 XpathINIT | |
1082 call assert_fails('call T17_F()', 'E171:') | |
1083 call assert_equal('a2d2a1b1a0c0e', g:Xpath) | |
1084 | |
1085 XpathINIT | |
1086 call assert_fails('call T17_G()', 'E171:') | |
1087 call assert_equal('a1a0', g:Xpath) | |
1088 | |
1089 XpathINIT | |
1090 call assert_fails('call T17_H()', 'E580:') | |
1091 call assert_equal('a1b1a0b0', g:Xpath) | |
1092 endfunc | |
1093 | |
1094 "------------------------------------------------------------------------------- | |
1095 "------------------------------------------------------------------------------- | |
1096 "------------------------------------------------------------------------------- | |
1097 " Test 87 using (expr) ? funcref : funcref {{{1 | |
1098 " | |
1099 " Vim needs to correctly parse the funcref and even when it does | |
1100 " not execute the funcref, it needs to consume the trailing () | |
1101 "------------------------------------------------------------------------------- | |
1102 | |
1103 func Add2(x1, x2) | |
1104 return a:x1 + a:x2 | |
1105 endfu | |
1106 | |
1107 func GetStr() | |
1108 return "abcdefghijklmnopqrstuvwxyp" | |
1109 endfu | |
1110 | |
1111 func Test_funcref_with_condexpr() | |
1112 call assert_equal(5, function('Add2')(2,3)) | |
1113 | |
1114 call assert_equal(3, 1 ? function('Add2')(1,2) : function('Add2')(2,3)) | |
1115 call assert_equal(5, 0 ? function('Add2')(1,2) : function('Add2')(2,3)) | |
1116 " Make sure, GetStr() still works. | |
1117 call assert_equal('abcdefghijk', GetStr()[0:10]) | |
1118 endfunc | |
1119 | |
926 " Test 90: Recognizing {} in variable name. {{{1 | 1120 " Test 90: Recognizing {} in variable name. {{{1 |
927 "------------------------------------------------------------------------------- | 1121 "------------------------------------------------------------------------------- |
928 | 1122 |
929 func Test_curlies() | 1123 func Test_curlies() |
930 let s:var = 66 | 1124 let s:var = 66 |
1750 call delete('Xtest.vim') | 1944 call delete('Xtest.vim') |
1751 endfunc | 1945 endfunc |
1752 | 1946 |
1753 "------------------------------------------------------------------------------- | 1947 "------------------------------------------------------------------------------- |
1754 " Modelines {{{1 | 1948 " Modelines {{{1 |
1755 " vim: ts=8 sw=4 tw=80 fdm=marker | 1949 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker |
1756 "------------------------------------------------------------------------------- | 1950 "------------------------------------------------------------------------------- |