Mercurial > vim
comparison src/testdir/test_substitute.vim @ 28205:553ff405b719 v8.2.4628
patch 8.2.4628: not enough testing for 2/3 letter substitute commands
Commit: https://github.com/vim/vim/commit/5e877baf87530d5c4fe4da2c5a6269cf19526c27
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Fri Mar 25 21:19:26 2022 +0000
patch 8.2.4628: not enough testing for 2/3 letter substitute commands
Problem: Not enough testing for 2/3 letter substitute commands.
Solution: Add more tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/10019)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 25 Mar 2022 22:30:03 +0100 |
parents | 40e35cefeac6 |
children | 1890fa76a634 |
comparison
equal
deleted
inserted
replaced
28204:d3d7b955a4d5 | 28205:553ff405b719 |
---|---|
1 " Tests for multi-line regexps with ":s". | 1 " Tests for the substitute (:s) command |
2 | 2 |
3 source shared.vim | 3 source shared.vim |
4 source check.vim | 4 source check.vim |
5 | 5 |
6 func Test_multiline_subst() | 6 func Test_multiline_subst() |
998 delfunc Repl | 998 delfunc Repl |
999 bwipe! | 999 bwipe! |
1000 set nocompatible | 1000 set nocompatible |
1001 endfunc | 1001 endfunc |
1002 | 1002 |
1003 " Test for the 2-letter and 3-letter :substitute commands | |
1004 func Test_substitute_short_cmd() | |
1005 new | |
1006 call setline(1, ['one', 'one one one']) | |
1007 s/one/two | |
1008 call cursor(2, 1) | |
1009 | |
1010 " :sc | |
1011 call feedkeys(":sc\<CR>y", 'xt') | |
1012 call assert_equal('two one one', getline(2)) | |
1013 | |
1014 " :scg | |
1015 call setline(2, 'one one one') | |
1016 call feedkeys(":scg\<CR>nyq", 'xt') | |
1017 call assert_equal('one two one', getline(2)) | |
1018 | |
1019 " :sci | |
1020 call setline(2, 'ONE One onE') | |
1021 call feedkeys(":sci\<CR>y", 'xt') | |
1022 call assert_equal('two One onE', getline(2)) | |
1023 | |
1024 " :scI | |
1025 set ignorecase | |
1026 call setline(2, 'ONE One one') | |
1027 call feedkeys(":scI\<CR>y", 'xt') | |
1028 call assert_equal('ONE One two', getline(2)) | |
1029 set ignorecase& | |
1030 | |
1031 " :scn | |
1032 call setline(2, 'one one one') | |
1033 let t = execute('scn')->split("\n") | |
1034 call assert_equal(['1 match on 1 line'], t) | |
1035 call assert_equal('one one one', getline(2)) | |
1036 | |
1037 " :scp | |
1038 call setline(2, "\tone one one") | |
1039 redir => output | |
1040 call feedkeys(":scp\<CR>y", 'xt') | |
1041 redir END | |
1042 call assert_equal(' two one one', output->split("\n")[-1]) | |
1043 call assert_equal("\ttwo one one", getline(2)) | |
1044 | |
1045 " :scl | |
1046 call setline(2, "\tone one one") | |
1047 redir => output | |
1048 call feedkeys(":scl\<CR>y", 'xt') | |
1049 redir END | |
1050 call assert_equal("^Itwo one one$", output->split("\n")[-1]) | |
1051 call assert_equal("\ttwo one one", getline(2)) | |
1052 | |
1053 " :sgc | |
1054 call setline(2, 'one one one one one') | |
1055 call feedkeys(":sgc\<CR>nyyq", 'xt') | |
1056 call assert_equal('one two two one one', getline(2)) | |
1057 | |
1058 " :sg | |
1059 call setline(2, 'one one one') | |
1060 sg | |
1061 call assert_equal('two two two', getline(2)) | |
1062 | |
1063 " :sgi | |
1064 call setline(2, 'ONE One onE') | |
1065 sgi | |
1066 call assert_equal('two two two', getline(2)) | |
1067 | |
1068 " :sgI | |
1069 set ignorecase | |
1070 call setline(2, 'ONE One one') | |
1071 sgI | |
1072 call assert_equal('ONE One two', getline(2)) | |
1073 set ignorecase& | |
1074 | |
1075 " :sgn | |
1076 call setline(2, 'one one one') | |
1077 let t = execute('sgn')->split("\n") | |
1078 call assert_equal(['3 matches on 1 line'], t) | |
1079 call assert_equal('one one one', getline(2)) | |
1080 | |
1081 " :sgp | |
1082 call setline(2, "\tone one one") | |
1083 redir => output | |
1084 sgp | |
1085 redir END | |
1086 call assert_equal(' two two two', output->split("\n")[-1]) | |
1087 call assert_equal("\ttwo two two", getline(2)) | |
1088 | |
1089 " :sgl | |
1090 call setline(2, "\tone one one") | |
1091 redir => output | |
1092 sgl | |
1093 redir END | |
1094 call assert_equal("^Itwo two two$", output->split("\n")[-1]) | |
1095 call assert_equal("\ttwo two two", getline(2)) | |
1096 | |
1097 " :sgr | |
1098 call setline(2, "one one one") | |
1099 call cursor(2, 1) | |
1100 s/abc/xyz/e | |
1101 let @/ = 'one' | |
1102 sgr | |
1103 call assert_equal('xyz xyz xyz', getline(2)) | |
1104 | |
1105 " :sic | |
1106 call cursor(1, 1) | |
1107 s/one/two/e | |
1108 call setline(2, "ONE One one") | |
1109 call cursor(2, 1) | |
1110 call feedkeys(":sic\<CR>y", 'xt') | |
1111 call assert_equal('two One one', getline(2)) | |
1112 | |
1113 " :si | |
1114 call setline(2, "ONE One one") | |
1115 si | |
1116 call assert_equal('two One one', getline(2)) | |
1117 | |
1118 " :siI | |
1119 call setline(2, "ONE One one") | |
1120 siI | |
1121 call assert_equal('ONE One two', getline(2)) | |
1122 | |
1123 " :sin | |
1124 call setline(2, 'ONE One onE') | |
1125 let t = execute('sin')->split("\n") | |
1126 call assert_equal(['1 match on 1 line'], t) | |
1127 call assert_equal('ONE One onE', getline(2)) | |
1128 | |
1129 " :sip | |
1130 call setline(2, "\tONE One onE") | |
1131 redir => output | |
1132 sip | |
1133 redir END | |
1134 call assert_equal(' two One onE', output->split("\n")[-1]) | |
1135 call assert_equal("\ttwo One onE", getline(2)) | |
1136 | |
1137 " :sir | |
1138 call setline(2, "ONE One onE") | |
1139 call cursor(2, 1) | |
1140 s/abc/xyz/e | |
1141 let @/ = 'one' | |
1142 sir | |
1143 call assert_equal('xyz One onE', getline(2)) | |
1144 | |
1145 " :sIc | |
1146 call cursor(1, 1) | |
1147 s/one/two/e | |
1148 call setline(2, "ONE One one") | |
1149 call cursor(2, 1) | |
1150 call feedkeys(":sIc\<CR>y", 'xt') | |
1151 call assert_equal('ONE One two', getline(2)) | |
1152 | |
1153 " :sIg | |
1154 call setline(2, "ONE one onE one") | |
1155 sIg | |
1156 call assert_equal('ONE two onE two', getline(2)) | |
1157 | |
1158 " :sIi | |
1159 call setline(2, "ONE One one") | |
1160 sIi | |
1161 call assert_equal('two One one', getline(2)) | |
1162 | |
1163 " :sI | |
1164 call setline(2, "ONE One one") | |
1165 sI | |
1166 call assert_equal('ONE One two', getline(2)) | |
1167 | |
1168 " :sIn | |
1169 call setline(2, 'ONE One one') | |
1170 let t = execute('sIn')->split("\n") | |
1171 call assert_equal(['1 match on 1 line'], t) | |
1172 call assert_equal('ONE One one', getline(2)) | |
1173 | |
1174 " :sIp | |
1175 call setline(2, "\tONE One one") | |
1176 redir => output | |
1177 sIp | |
1178 redir END | |
1179 call assert_equal(' ONE One two', output->split("\n")[-1]) | |
1180 call assert_equal("\tONE One two", getline(2)) | |
1181 | |
1182 " :sIl | |
1183 call setline(2, "\tONE onE one") | |
1184 redir => output | |
1185 sIl | |
1186 redir END | |
1187 call assert_equal("^IONE onE two$", output->split("\n")[-1]) | |
1188 call assert_equal("\tONE onE two", getline(2)) | |
1189 | |
1190 " :sIr | |
1191 call setline(2, "ONE one onE") | |
1192 call cursor(2, 1) | |
1193 s/abc/xyz/e | |
1194 let @/ = 'one' | |
1195 sIr | |
1196 call assert_equal('ONE xyz onE', getline(2)) | |
1197 | |
1198 " :src | |
1199 call setline(2, "ONE one one") | |
1200 call cursor(2, 1) | |
1201 s/abc/xyz/e | |
1202 let @/ = 'one' | |
1203 call feedkeys(":src\<CR>y", 'xt') | |
1204 call assert_equal('ONE xyz one', getline(2)) | |
1205 | |
1206 " :srg | |
1207 call setline(2, "one one one") | |
1208 call cursor(2, 1) | |
1209 s/abc/xyz/e | |
1210 let @/ = 'one' | |
1211 srg | |
1212 call assert_equal('xyz xyz xyz', getline(2)) | |
1213 | |
1214 " :sri | |
1215 call setline(2, "ONE one onE") | |
1216 call cursor(2, 1) | |
1217 s/abc/xyz/e | |
1218 let @/ = 'one' | |
1219 sri | |
1220 call assert_equal('xyz one onE', getline(2)) | |
1221 | |
1222 " :srI | |
1223 call setline(2, "ONE one onE") | |
1224 call cursor(2, 1) | |
1225 s/abc/xyz/e | |
1226 let @/ = 'one' | |
1227 srI | |
1228 call assert_equal('ONE xyz onE', getline(2)) | |
1229 | |
1230 " :srn | |
1231 call setline(2, "ONE one onE") | |
1232 call cursor(2, 1) | |
1233 s/abc/xyz/e | |
1234 let @/ = 'one' | |
1235 let t = execute('srn')->split("\n") | |
1236 call assert_equal(['1 match on 1 line'], t) | |
1237 call assert_equal('ONE one onE', getline(2)) | |
1238 | |
1239 " :srp | |
1240 call setline(2, "\tONE one onE") | |
1241 call cursor(2, 1) | |
1242 s/abc/xyz/e | |
1243 let @/ = 'one' | |
1244 redir => output | |
1245 srp | |
1246 redir END | |
1247 call assert_equal(' ONE xyz onE', output->split("\n")[-1]) | |
1248 call assert_equal("\tONE xyz onE", getline(2)) | |
1249 | |
1250 " :srl | |
1251 call setline(2, "\tONE one onE") | |
1252 call cursor(2, 1) | |
1253 s/abc/xyz/e | |
1254 let @/ = 'one' | |
1255 redir => output | |
1256 srl | |
1257 redir END | |
1258 call assert_equal("^IONE xyz onE$", output->split("\n")[-1]) | |
1259 call assert_equal("\tONE xyz onE", getline(2)) | |
1260 | |
1261 " :sr | |
1262 call setline(2, "ONE one onE") | |
1263 call cursor(2, 1) | |
1264 s/abc/xyz/e | |
1265 let @/ = 'one' | |
1266 sr | |
1267 call assert_equal('ONE xyz onE', getline(2)) | |
1268 | |
1269 " :sce | |
1270 s/abc/xyz/e | |
1271 call assert_fails("sc", 'E486:') | |
1272 sce | |
1273 " :sge | |
1274 call assert_fails("sg", 'E486:') | |
1275 sge | |
1276 " :sie | |
1277 call assert_fails("si", 'E486:') | |
1278 sie | |
1279 " :sIe | |
1280 call assert_fails("sI", 'E486:') | |
1281 sIe | |
1282 | |
1283 bw! | |
1284 endfunc | |
1003 | 1285 |
1004 " vim: shiftwidth=2 sts=2 expandtab | 1286 " vim: shiftwidth=2 sts=2 expandtab |