Bram Moolenaar | 72defda | 2016-01-17 18:04:33 +0100 | [diff] [blame] | 1 | " Test argument list commands |
| 2 | |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 3 | source shared.vim |
| 4 | source term_util.vim |
| 5 | |
Bram Moolenaar | 72defda | 2016-01-17 18:04:33 +0100 | [diff] [blame] | 6 | func Test_argidx() |
| 7 | args a b c |
| 8 | last |
| 9 | call assert_equal(2, argidx()) |
| 10 | %argdelete |
| 11 | call assert_equal(0, argidx()) |
Bram Moolenaar | 69a92fb | 2017-03-09 15:58:30 +0100 | [diff] [blame] | 12 | " doing it again doesn't result in an error |
| 13 | %argdelete |
| 14 | call assert_equal(0, argidx()) |
| 15 | call assert_fails('2argdelete', 'E16:') |
Bram Moolenaar | 72defda | 2016-01-17 18:04:33 +0100 | [diff] [blame] | 16 | |
| 17 | args a b c |
| 18 | call assert_equal(0, argidx()) |
| 19 | next |
| 20 | call assert_equal(1, argidx()) |
| 21 | next |
| 22 | call assert_equal(2, argidx()) |
| 23 | 1argdelete |
| 24 | call assert_equal(1, argidx()) |
| 25 | 1argdelete |
| 26 | call assert_equal(0, argidx()) |
| 27 | 1argdelete |
| 28 | call assert_equal(0, argidx()) |
| 29 | endfunc |
Bram Moolenaar | a24f0a5 | 2016-01-17 19:39:00 +0100 | [diff] [blame] | 30 | |
| 31 | func Test_argadd() |
| 32 | %argdelete |
| 33 | argadd a b c |
| 34 | call assert_equal(0, argidx()) |
| 35 | |
| 36 | %argdelete |
| 37 | argadd a |
| 38 | call assert_equal(0, argidx()) |
| 39 | argadd b c d |
| 40 | call assert_equal(0, argidx()) |
| 41 | |
| 42 | call Init_abc() |
| 43 | argadd x |
| 44 | call Assert_argc(['a', 'b', 'x', 'c']) |
| 45 | call assert_equal(1, argidx()) |
| 46 | |
| 47 | call Init_abc() |
| 48 | 0argadd x |
| 49 | call Assert_argc(['x', 'a', 'b', 'c']) |
| 50 | call assert_equal(2, argidx()) |
| 51 | |
| 52 | call Init_abc() |
| 53 | 1argadd x |
| 54 | call Assert_argc(['a', 'x', 'b', 'c']) |
| 55 | call assert_equal(2, argidx()) |
| 56 | |
| 57 | call Init_abc() |
| 58 | $argadd x |
| 59 | call Assert_argc(['a', 'b', 'c', 'x']) |
| 60 | call assert_equal(1, argidx()) |
| 61 | |
| 62 | call Init_abc() |
| 63 | $argadd x |
| 64 | +2argadd y |
| 65 | call Assert_argc(['a', 'b', 'c', 'x', 'y']) |
| 66 | call assert_equal(1, argidx()) |
Bram Moolenaar | 2faa29f | 2016-01-23 23:02:34 +0100 | [diff] [blame] | 67 | |
| 68 | %argd |
| 69 | edit d |
| 70 | arga |
Bram Moolenaar | 398ee73 | 2017-08-03 14:29:14 +0200 | [diff] [blame] | 71 | call assert_equal(1, len(argv())) |
| 72 | call assert_equal('d', get(argv(), 0, '')) |
| 73 | |
| 74 | %argd |
| 75 | edit some\ file |
| 76 | arga |
| 77 | call assert_equal(1, len(argv())) |
| 78 | call assert_equal('some file', get(argv(), 0, '')) |
Bram Moolenaar | 2faa29f | 2016-01-23 23:02:34 +0100 | [diff] [blame] | 79 | |
| 80 | %argd |
| 81 | new |
| 82 | arga |
Bram Moolenaar | 398ee73 | 2017-08-03 14:29:14 +0200 | [diff] [blame] | 83 | call assert_equal(0, len(argv())) |
Bram Moolenaar | a24f0a5 | 2016-01-17 19:39:00 +0100 | [diff] [blame] | 84 | endfunc |
| 85 | |
Bram Moolenaar | 32bbd00 | 2018-08-31 23:06:22 +0200 | [diff] [blame] | 86 | func Test_argadd_empty_curbuf() |
| 87 | new |
| 88 | let curbuf = bufnr('%') |
| 89 | call writefile(['test', 'Xargadd'], 'Xargadd') |
| 90 | " must not re-use the current buffer. |
| 91 | argadd Xargadd |
| 92 | call assert_equal(curbuf, bufnr('%')) |
| 93 | call assert_equal('', bufname('%')) |
Bram Moolenaar | 02b3111 | 2019-08-31 22:16:38 +0200 | [diff] [blame] | 94 | call assert_equal(1, '$'->line()) |
Bram Moolenaar | 32bbd00 | 2018-08-31 23:06:22 +0200 | [diff] [blame] | 95 | rew |
Bram Moolenaar | 073e4b9 | 2019-08-18 23:01:56 +0200 | [diff] [blame] | 96 | call assert_notequal(curbuf, '%'->bufnr()) |
| 97 | call assert_equal('Xargadd', '%'->bufname()) |
Bram Moolenaar | 32bbd00 | 2018-08-31 23:06:22 +0200 | [diff] [blame] | 98 | call assert_equal(2, line('$')) |
| 99 | |
Bram Moolenaar | d339828 | 2018-09-24 21:32:11 +0200 | [diff] [blame] | 100 | call delete('Xargadd') |
Bram Moolenaar | 32bbd00 | 2018-08-31 23:06:22 +0200 | [diff] [blame] | 101 | %argd |
| 102 | bwipe! |
| 103 | endfunc |
| 104 | |
Bram Moolenaar | a24f0a5 | 2016-01-17 19:39:00 +0100 | [diff] [blame] | 105 | func Init_abc() |
| 106 | args a b c |
| 107 | next |
| 108 | endfunc |
| 109 | |
| 110 | func Assert_argc(l) |
| 111 | call assert_equal(len(a:l), argc()) |
| 112 | let i = 0 |
| 113 | while i < len(a:l) && i < argc() |
| 114 | call assert_equal(a:l[i], argv(i)) |
| 115 | let i += 1 |
| 116 | endwhile |
| 117 | endfunc |
Bram Moolenaar | 99dbe29 | 2016-01-19 13:07:23 +0100 | [diff] [blame] | 118 | |
| 119 | " Test for [count]argument and [count]argdelete commands |
| 120 | " Ported from the test_argument_count.in test script |
Bram Moolenaar | 8c34aa0 | 2017-03-16 22:52:32 +0100 | [diff] [blame] | 121 | func Test_argument() |
Bram Moolenaar | 99dbe29 | 2016-01-19 13:07:23 +0100 | [diff] [blame] | 122 | " Clean the argument list |
| 123 | arga a | %argd |
| 124 | |
| 125 | let save_hidden = &hidden |
| 126 | set hidden |
| 127 | |
| 128 | let g:buffers = [] |
| 129 | augroup TEST |
| 130 | au BufEnter * call add(buffers, expand('%:t')) |
| 131 | augroup END |
| 132 | |
| 133 | argadd a b c d |
| 134 | $argu |
| 135 | $-argu |
| 136 | -argu |
| 137 | 1argu |
| 138 | +2argu |
| 139 | |
| 140 | augroup TEST |
| 141 | au! |
| 142 | augroup END |
| 143 | |
| 144 | call assert_equal(['d', 'c', 'b', 'a', 'c'], g:buffers) |
| 145 | |
Bram Moolenaar | 949f198 | 2019-07-23 23:00:08 +0200 | [diff] [blame] | 146 | call assert_equal("\na b [c] d ", execute(':args')) |
Bram Moolenaar | 99dbe29 | 2016-01-19 13:07:23 +0100 | [diff] [blame] | 147 | |
| 148 | .argd |
| 149 | call assert_equal(['a', 'b', 'd'], argv()) |
| 150 | |
| 151 | -argd |
| 152 | call assert_equal(['a', 'd'], argv()) |
| 153 | |
| 154 | $argd |
| 155 | call assert_equal(['a'], argv()) |
| 156 | |
| 157 | 1arga c |
| 158 | 1arga b |
| 159 | $argu |
| 160 | $arga x |
| 161 | call assert_equal(['a', 'b', 'c', 'x'], argv()) |
| 162 | |
Bram Moolenaar | 3014170 | 2016-01-19 14:14:08 +0100 | [diff] [blame] | 163 | 0arga y |
| 164 | call assert_equal(['y', 'a', 'b', 'c', 'x'], argv()) |
Bram Moolenaar | 99dbe29 | 2016-01-19 13:07:23 +0100 | [diff] [blame] | 165 | |
| 166 | %argd |
| 167 | call assert_equal([], argv()) |
| 168 | |
| 169 | arga a b c d e f |
| 170 | 2,$-argd |
| 171 | call assert_equal(['a', 'f'], argv()) |
| 172 | |
| 173 | let &hidden = save_hidden |
| 174 | |
Bram Moolenaar | 9800bfe | 2019-07-27 21:23:45 +0200 | [diff] [blame] | 175 | let save_columns = &columns |
| 176 | let &columns = 79 |
| 177 | exe 'args ' .. join(range(1, 81)) |
| 178 | call assert_equal(join([ |
| 179 | \ '', |
| 180 | \ '[1] 6 11 16 21 26 31 36 41 46 51 56 61 66 71 76 81 ', |
| 181 | \ '2 7 12 17 22 27 32 37 42 47 52 57 62 67 72 77 ', |
| 182 | \ '3 8 13 18 23 28 33 38 43 48 53 58 63 68 73 78 ', |
| 183 | \ '4 9 14 19 24 29 34 39 44 49 54 59 64 69 74 79 ', |
| 184 | \ '5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 ', |
| 185 | \ ], "\n"), |
| 186 | \ execute('args')) |
| 187 | |
| 188 | " No trailing newline with one item per row. |
| 189 | let long_arg = repeat('X', 81) |
| 190 | exe 'args ' .. long_arg |
| 191 | call assert_equal("\n[".long_arg.']', execute('args')) |
| 192 | let &columns = save_columns |
| 193 | |
Bram Moolenaar | 99dbe29 | 2016-01-19 13:07:23 +0100 | [diff] [blame] | 194 | " Setting argument list should fail when the current buffer has unsaved |
| 195 | " changes |
| 196 | %argd |
| 197 | enew! |
| 198 | set modified |
| 199 | call assert_fails('args x y z', 'E37:') |
| 200 | args! x y z |
| 201 | call assert_equal(['x', 'y', 'z'], argv()) |
| 202 | call assert_equal('x', expand('%:t')) |
| 203 | |
| 204 | last | enew | argu |
| 205 | call assert_equal('z', expand('%:t')) |
| 206 | |
| 207 | %argdelete |
| 208 | call assert_fails('argument', 'E163:') |
Bram Moolenaar | 8c34aa0 | 2017-03-16 22:52:32 +0100 | [diff] [blame] | 209 | endfunc |
Bram Moolenaar | 99dbe29 | 2016-01-19 13:07:23 +0100 | [diff] [blame] | 210 | |
Bram Moolenaar | 5d69da4 | 2018-04-20 22:01:41 +0200 | [diff] [blame] | 211 | func Test_list_arguments() |
| 212 | " Clean the argument list |
| 213 | arga a | %argd |
| 214 | |
| 215 | " four args half the screen width makes two lines with two columns |
| 216 | let aarg = repeat('a', &columns / 2 - 4) |
| 217 | let barg = repeat('b', &columns / 2 - 4) |
| 218 | let carg = repeat('c', &columns / 2 - 4) |
| 219 | let darg = repeat('d', &columns / 2 - 4) |
| 220 | exe 'argadd ' aarg barg carg darg |
| 221 | |
| 222 | redir => result |
| 223 | args |
| 224 | redir END |
| 225 | call assert_match('\[' . aarg . '] \+' . carg . '\n' . barg . ' \+' . darg, trim(result)) |
| 226 | |
| 227 | " if one arg is longer than half the screen make one column |
| 228 | exe 'argdel' aarg |
| 229 | let aarg = repeat('a', &columns / 2 + 2) |
| 230 | exe '0argadd' aarg |
| 231 | redir => result |
| 232 | args |
| 233 | redir END |
| 234 | call assert_match(aarg . '\n\[' . barg . ']\n' . carg . '\n' . darg, trim(result)) |
| 235 | |
| 236 | %argdelete |
| 237 | endfunc |
| 238 | |
Bram Moolenaar | 2ac372c | 2018-12-28 19:06:47 +0100 | [diff] [blame] | 239 | func Test_args_with_quote() |
Bram Moolenaar | 3de8c2d | 2018-12-28 19:29:35 +0100 | [diff] [blame] | 240 | " Only on Unix can a file name include a double quote. |
| 241 | if has('unix') |
| 242 | args \"foobar |
| 243 | call assert_equal('"foobar', argv(0)) |
| 244 | %argdelete |
| 245 | endif |
Bram Moolenaar | 2ac372c | 2018-12-28 19:06:47 +0100 | [diff] [blame] | 246 | endfunc |
| 247 | |
Bram Moolenaar | 99dbe29 | 2016-01-19 13:07:23 +0100 | [diff] [blame] | 248 | " Test for 0argadd and 0argedit |
| 249 | " Ported from the test_argument_0count.in test script |
Bram Moolenaar | 8c34aa0 | 2017-03-16 22:52:32 +0100 | [diff] [blame] | 250 | func Test_zero_argadd() |
Bram Moolenaar | 99dbe29 | 2016-01-19 13:07:23 +0100 | [diff] [blame] | 251 | " Clean the argument list |
| 252 | arga a | %argd |
| 253 | |
| 254 | arga a b c d |
| 255 | 2argu |
| 256 | 0arga added |
| 257 | call assert_equal(['added', 'a', 'b', 'c', 'd'], argv()) |
| 258 | |
| 259 | 2argu |
| 260 | arga third |
| 261 | call assert_equal(['added', 'a', 'third', 'b', 'c', 'd'], argv()) |
| 262 | |
| 263 | %argd |
| 264 | arga a b c d |
| 265 | 2argu |
| 266 | 0arge edited |
| 267 | call assert_equal(['edited', 'a', 'b', 'c', 'd'], argv()) |
| 268 | |
| 269 | 2argu |
| 270 | arga third |
| 271 | call assert_equal(['edited', 'a', 'third', 'b', 'c', 'd'], argv()) |
Bram Moolenaar | 90305c6 | 2017-07-16 15:31:17 +0200 | [diff] [blame] | 272 | |
| 273 | 2argu |
| 274 | argedit file\ with\ spaces another file |
| 275 | call assert_equal(['edited', 'a', 'file with spaces', 'another', 'file', 'third', 'b', 'c', 'd'], argv()) |
| 276 | call assert_equal('file with spaces', expand('%')) |
Bram Moolenaar | 8c34aa0 | 2017-03-16 22:52:32 +0100 | [diff] [blame] | 277 | endfunc |
Bram Moolenaar | 99dbe29 | 2016-01-19 13:07:23 +0100 | [diff] [blame] | 278 | |
Bram Moolenaar | 8c34aa0 | 2017-03-16 22:52:32 +0100 | [diff] [blame] | 279 | func Reset_arglist() |
Bram Moolenaar | 99dbe29 | 2016-01-19 13:07:23 +0100 | [diff] [blame] | 280 | args a | %argd |
Bram Moolenaar | 8c34aa0 | 2017-03-16 22:52:32 +0100 | [diff] [blame] | 281 | endfunc |
Bram Moolenaar | 99dbe29 | 2016-01-19 13:07:23 +0100 | [diff] [blame] | 282 | |
| 283 | " Test for argc() |
Bram Moolenaar | 8c34aa0 | 2017-03-16 22:52:32 +0100 | [diff] [blame] | 284 | func Test_argc() |
Bram Moolenaar | 99dbe29 | 2016-01-19 13:07:23 +0100 | [diff] [blame] | 285 | call Reset_arglist() |
| 286 | call assert_equal(0, argc()) |
| 287 | argadd a b |
| 288 | call assert_equal(2, argc()) |
Bram Moolenaar | 8c34aa0 | 2017-03-16 22:52:32 +0100 | [diff] [blame] | 289 | endfunc |
Bram Moolenaar | 99dbe29 | 2016-01-19 13:07:23 +0100 | [diff] [blame] | 290 | |
| 291 | " Test for arglistid() |
Bram Moolenaar | 8c34aa0 | 2017-03-16 22:52:32 +0100 | [diff] [blame] | 292 | func Test_arglistid() |
Bram Moolenaar | 99dbe29 | 2016-01-19 13:07:23 +0100 | [diff] [blame] | 293 | call Reset_arglist() |
| 294 | arga a b |
| 295 | call assert_equal(0, arglistid()) |
| 296 | split |
| 297 | arglocal |
| 298 | call assert_equal(1, arglistid()) |
| 299 | tabnew | tabfirst |
| 300 | call assert_equal(0, arglistid(2)) |
| 301 | call assert_equal(1, arglistid(1, 1)) |
| 302 | call assert_equal(0, arglistid(2, 1)) |
| 303 | call assert_equal(1, arglistid(1, 2)) |
| 304 | tabonly | only | enew! |
| 305 | argglobal |
| 306 | call assert_equal(0, arglistid()) |
Bram Moolenaar | 8c34aa0 | 2017-03-16 22:52:32 +0100 | [diff] [blame] | 307 | endfunc |
Bram Moolenaar | 99dbe29 | 2016-01-19 13:07:23 +0100 | [diff] [blame] | 308 | |
Bram Moolenaar | e6e3989 | 2018-10-25 12:32:11 +0200 | [diff] [blame] | 309 | " Tests for argv() and argc() |
Bram Moolenaar | 8c34aa0 | 2017-03-16 22:52:32 +0100 | [diff] [blame] | 310 | func Test_argv() |
Bram Moolenaar | 99dbe29 | 2016-01-19 13:07:23 +0100 | [diff] [blame] | 311 | call Reset_arglist() |
| 312 | call assert_equal([], argv()) |
| 313 | call assert_equal("", argv(2)) |
Bram Moolenaar | e6e3989 | 2018-10-25 12:32:11 +0200 | [diff] [blame] | 314 | call assert_equal(0, argc()) |
Bram Moolenaar | 99dbe29 | 2016-01-19 13:07:23 +0100 | [diff] [blame] | 315 | argadd a b c d |
Bram Moolenaar | e6e3989 | 2018-10-25 12:32:11 +0200 | [diff] [blame] | 316 | call assert_equal(4, argc()) |
Bram Moolenaar | 99dbe29 | 2016-01-19 13:07:23 +0100 | [diff] [blame] | 317 | call assert_equal('c', argv(2)) |
Bram Moolenaar | e6e3989 | 2018-10-25 12:32:11 +0200 | [diff] [blame] | 318 | |
| 319 | let w1_id = win_getid() |
| 320 | split |
| 321 | let w2_id = win_getid() |
| 322 | arglocal |
| 323 | args e f g |
| 324 | tabnew |
| 325 | let w3_id = win_getid() |
| 326 | split |
| 327 | let w4_id = win_getid() |
| 328 | argglobal |
| 329 | tabfirst |
| 330 | call assert_equal(4, argc(w1_id)) |
| 331 | call assert_equal('b', argv(1, w1_id)) |
| 332 | call assert_equal(['a', 'b', 'c', 'd'], argv(-1, w1_id)) |
| 333 | |
| 334 | call assert_equal(3, argc(w2_id)) |
| 335 | call assert_equal('f', argv(1, w2_id)) |
| 336 | call assert_equal(['e', 'f', 'g'], argv(-1, w2_id)) |
| 337 | |
| 338 | call assert_equal(3, argc(w3_id)) |
| 339 | call assert_equal('e', argv(0, w3_id)) |
| 340 | call assert_equal(['e', 'f', 'g'], argv(-1, w3_id)) |
| 341 | |
| 342 | call assert_equal(4, argc(w4_id)) |
| 343 | call assert_equal('c', argv(2, w4_id)) |
| 344 | call assert_equal(['a', 'b', 'c', 'd'], argv(-1, w4_id)) |
| 345 | |
| 346 | call assert_equal(4, argc(-1)) |
| 347 | call assert_equal(3, argc()) |
| 348 | call assert_equal('d', argv(3, -1)) |
| 349 | call assert_equal(['a', 'b', 'c', 'd'], argv(-1, -1)) |
| 350 | tabonly | only | enew! |
| 351 | " Negative test cases |
| 352 | call assert_equal(-1, argc(100)) |
| 353 | call assert_equal('', argv(1, 100)) |
| 354 | call assert_equal([], argv(-1, 100)) |
| 355 | call assert_equal('', argv(10, -1)) |
Bram Moolenaar | 8c34aa0 | 2017-03-16 22:52:32 +0100 | [diff] [blame] | 356 | endfunc |
Bram Moolenaar | 99dbe29 | 2016-01-19 13:07:23 +0100 | [diff] [blame] | 357 | |
| 358 | " Test for the :argedit command |
Bram Moolenaar | 8c34aa0 | 2017-03-16 22:52:32 +0100 | [diff] [blame] | 359 | func Test_argedit() |
Bram Moolenaar | 99dbe29 | 2016-01-19 13:07:23 +0100 | [diff] [blame] | 360 | call Reset_arglist() |
| 361 | argedit a |
| 362 | call assert_equal(['a'], argv()) |
| 363 | call assert_equal('a', expand('%:t')) |
| 364 | argedit b |
| 365 | call assert_equal(['a', 'b'], argv()) |
| 366 | call assert_equal('b', expand('%:t')) |
| 367 | argedit a |
Bram Moolenaar | 90305c6 | 2017-07-16 15:31:17 +0200 | [diff] [blame] | 368 | call assert_equal(['a', 'b', 'a'], argv()) |
Bram Moolenaar | 99dbe29 | 2016-01-19 13:07:23 +0100 | [diff] [blame] | 369 | call assert_equal('a', expand('%:t')) |
Bram Moolenaar | 9b50bba | 2017-07-16 16:42:13 +0200 | [diff] [blame] | 370 | " When file name case is ignored, an existing buffer with only case |
Bram Moolenaar | cf1ba35 | 2017-10-27 00:55:04 +0200 | [diff] [blame] | 371 | " difference is re-used. |
Bram Moolenaar | 90305c6 | 2017-07-16 15:31:17 +0200 | [diff] [blame] | 372 | argedit C D |
| 373 | call assert_equal('C', expand('%:t')) |
| 374 | call assert_equal(['a', 'b', 'a', 'C', 'D'], argv()) |
Bram Moolenaar | 99dbe29 | 2016-01-19 13:07:23 +0100 | [diff] [blame] | 375 | argedit c |
Bram Moolenaar | 9b50bba | 2017-07-16 16:42:13 +0200 | [diff] [blame] | 376 | if has('fname_case') |
| 377 | call assert_equal(['a', 'b', 'a', 'C', 'c', 'D'], argv()) |
| 378 | else |
| 379 | call assert_equal(['a', 'b', 'a', 'C', 'C', 'D'], argv()) |
| 380 | endif |
Bram Moolenaar | 99dbe29 | 2016-01-19 13:07:23 +0100 | [diff] [blame] | 381 | 0argedit x |
Bram Moolenaar | 9b50bba | 2017-07-16 16:42:13 +0200 | [diff] [blame] | 382 | if has('fname_case') |
| 383 | call assert_equal(['x', 'a', 'b', 'a', 'C', 'c', 'D'], argv()) |
| 384 | else |
| 385 | call assert_equal(['x', 'a', 'b', 'a', 'C', 'C', 'D'], argv()) |
| 386 | endif |
Bram Moolenaar | 99dbe29 | 2016-01-19 13:07:23 +0100 | [diff] [blame] | 387 | enew! | set modified |
| 388 | call assert_fails('argedit y', 'E37:') |
| 389 | argedit! y |
Bram Moolenaar | 9b50bba | 2017-07-16 16:42:13 +0200 | [diff] [blame] | 390 | if has('fname_case') |
| 391 | call assert_equal(['x', 'y', 'y', 'a', 'b', 'a', 'C', 'c', 'D'], argv()) |
| 392 | else |
| 393 | call assert_equal(['x', 'y', 'y', 'a', 'b', 'a', 'C', 'C', 'D'], argv()) |
| 394 | endif |
Bram Moolenaar | 99dbe29 | 2016-01-19 13:07:23 +0100 | [diff] [blame] | 395 | %argd |
Bram Moolenaar | 9b50bba | 2017-07-16 16:42:13 +0200 | [diff] [blame] | 396 | bwipe! C |
| 397 | bwipe! D |
Bram Moolenaar | 46a53df | 2018-04-24 21:58:51 +0200 | [diff] [blame] | 398 | |
| 399 | " :argedit reuses the current buffer if it is empty |
| 400 | %argd |
| 401 | " make sure to use a new buffer number for x when it is loaded |
| 402 | bw! x |
| 403 | new |
Bram Moolenaar | a8eee21 | 2019-08-24 22:14:58 +0200 | [diff] [blame] | 404 | let a = bufnr() |
Bram Moolenaar | 46a53df | 2018-04-24 21:58:51 +0200 | [diff] [blame] | 405 | argedit x |
Bram Moolenaar | a8eee21 | 2019-08-24 22:14:58 +0200 | [diff] [blame] | 406 | call assert_equal(a, bufnr()) |
| 407 | call assert_equal('x', bufname()) |
Bram Moolenaar | 46a53df | 2018-04-24 21:58:51 +0200 | [diff] [blame] | 408 | %argd |
| 409 | bw! x |
Bram Moolenaar | 8c34aa0 | 2017-03-16 22:52:32 +0100 | [diff] [blame] | 410 | endfunc |
Bram Moolenaar | 99dbe29 | 2016-01-19 13:07:23 +0100 | [diff] [blame] | 411 | |
| 412 | " Test for the :argdelete command |
Bram Moolenaar | 8c34aa0 | 2017-03-16 22:52:32 +0100 | [diff] [blame] | 413 | func Test_argdelete() |
Bram Moolenaar | 99dbe29 | 2016-01-19 13:07:23 +0100 | [diff] [blame] | 414 | call Reset_arglist() |
| 415 | args aa a aaa b bb |
| 416 | argdelete a* |
| 417 | call assert_equal(['b', 'bb'], argv()) |
| 418 | call assert_equal('aa', expand('%:t')) |
| 419 | last |
| 420 | argdelete % |
| 421 | call assert_equal(['b'], argv()) |
| 422 | call assert_fails('argdelete', 'E471:') |
| 423 | call assert_fails('1,100argdelete', 'E16:') |
| 424 | %argd |
Bram Moolenaar | 8c34aa0 | 2017-03-16 22:52:32 +0100 | [diff] [blame] | 425 | endfunc |
Bram Moolenaar | 99dbe29 | 2016-01-19 13:07:23 +0100 | [diff] [blame] | 426 | |
Bram Moolenaar | b513d30 | 2018-12-02 14:55:08 +0100 | [diff] [blame] | 427 | func Test_argdelete_completion() |
| 428 | args foo bar |
| 429 | |
| 430 | call feedkeys(":argdelete \<C-A>\<C-B>\"\<CR>", 'tx') |
| 431 | call assert_equal('"argdelete bar foo', @:) |
| 432 | |
| 433 | call feedkeys(":argdelete x \<C-A>\<C-B>\"\<CR>", 'tx') |
| 434 | call assert_equal('"argdelete x bar foo', @:) |
| 435 | |
| 436 | %argd |
| 437 | endfunc |
| 438 | |
Bram Moolenaar | 99dbe29 | 2016-01-19 13:07:23 +0100 | [diff] [blame] | 439 | " Tests for the :next, :prev, :first, :last, :rewind commands |
Bram Moolenaar | 8c34aa0 | 2017-03-16 22:52:32 +0100 | [diff] [blame] | 440 | func Test_argpos() |
Bram Moolenaar | 99dbe29 | 2016-01-19 13:07:23 +0100 | [diff] [blame] | 441 | call Reset_arglist() |
| 442 | args a b c d |
| 443 | last |
| 444 | call assert_equal(3, argidx()) |
| 445 | call assert_fails('next', 'E165:') |
| 446 | prev |
| 447 | call assert_equal(2, argidx()) |
| 448 | Next |
| 449 | call assert_equal(1, argidx()) |
| 450 | first |
| 451 | call assert_equal(0, argidx()) |
| 452 | call assert_fails('prev', 'E164:') |
| 453 | 3next |
| 454 | call assert_equal(3, argidx()) |
| 455 | rewind |
| 456 | call assert_equal(0, argidx()) |
| 457 | %argd |
Bram Moolenaar | 8c34aa0 | 2017-03-16 22:52:32 +0100 | [diff] [blame] | 458 | endfunc |
Bram Moolenaar | 53f1673 | 2016-09-07 20:46:39 +0200 | [diff] [blame] | 459 | |
| 460 | " Test for autocommand that redefines the argument list, when doing ":all". |
Bram Moolenaar | 8c34aa0 | 2017-03-16 22:52:32 +0100 | [diff] [blame] | 461 | func Test_arglist_autocmd() |
Bram Moolenaar | 53f1673 | 2016-09-07 20:46:39 +0200 | [diff] [blame] | 462 | autocmd BufReadPost Xxx2 next Xxx2 Xxx1 |
| 463 | call writefile(['test file Xxx1'], 'Xxx1') |
| 464 | call writefile(['test file Xxx2'], 'Xxx2') |
| 465 | call writefile(['test file Xxx3'], 'Xxx3') |
| 466 | |
| 467 | new |
| 468 | " redefine arglist; go to Xxx1 |
| 469 | next! Xxx1 Xxx2 Xxx3 |
| 470 | " open window for all args |
| 471 | all |
| 472 | call assert_equal('test file Xxx1', getline(1)) |
| 473 | wincmd w |
| 474 | wincmd w |
| 475 | call assert_equal('test file Xxx1', getline(1)) |
| 476 | " should now be in Xxx2 |
| 477 | rewind |
| 478 | call assert_equal('test file Xxx2', getline(1)) |
| 479 | |
| 480 | autocmd! BufReadPost Xxx2 |
| 481 | enew! | only |
| 482 | call delete('Xxx1') |
| 483 | call delete('Xxx2') |
| 484 | call delete('Xxx3') |
| 485 | argdelete Xxx* |
| 486 | bwipe! Xxx1 Xxx2 Xxx3 |
Bram Moolenaar | 8c34aa0 | 2017-03-16 22:52:32 +0100 | [diff] [blame] | 487 | endfunc |
| 488 | |
| 489 | func Test_arg_all_expand() |
| 490 | call writefile(['test file Xxx1'], 'Xx x') |
| 491 | next notexist Xx\ x runtest.vim |
| 492 | call assert_equal('notexist Xx\ x runtest.vim', expand('##')) |
| 493 | call delete('Xx x') |
| 494 | endfunc |
Bram Moolenaar | e961cba | 2018-09-18 21:51:47 +0200 | [diff] [blame] | 495 | |
| 496 | func Test_large_arg() |
| 497 | " Argument longer or equal to the number of columns used to cause |
| 498 | " access to invalid memory. |
| 499 | exe 'argadd ' .repeat('x', &columns) |
| 500 | args |
| 501 | endfunc |
Bram Moolenaar | 72e1b39 | 2019-08-03 13:50:08 +0200 | [diff] [blame] | 502 | |
| 503 | func Test_argdo() |
| 504 | next! Xa.c Xb.c Xc.c |
| 505 | new |
| 506 | let l = [] |
| 507 | argdo call add(l, expand('%')) |
| 508 | call assert_equal(['Xa.c', 'Xb.c', 'Xc.c'], l) |
| 509 | bwipe Xa.c Xb.c Xc.c |
| 510 | endfunc |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 511 | |
| 512 | " Test for quiting Vim with unedited files in the argument list |
| 513 | func Test_quit_with_arglist() |
| 514 | if !CanRunVimInTerminal() |
| 515 | throw 'Skipped: cannot run vim in terminal' |
| 516 | endif |
| 517 | let buf = RunVimInTerminal('', {'rows': 6}) |
Bram Moolenaar | 818fc9a | 2020-02-21 17:54:45 +0100 | [diff] [blame] | 518 | call term_sendkeys(buf, ":set nomore\n") |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 519 | call term_sendkeys(buf, ":args a b c\n") |
| 520 | call term_sendkeys(buf, ":quit\n") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame^] | 521 | call TermWait(buf) |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 522 | call WaitForAssert({-> assert_match('^E173:', term_getline(buf, 6))}) |
| 523 | call StopVimInTerminal(buf) |
Bram Moolenaar | 406cd90 | 2020-02-18 21:54:41 +0100 | [diff] [blame] | 524 | |
| 525 | " Try :confirm quit with unedited files in arglist |
| 526 | let buf = RunVimInTerminal('', {'rows': 6}) |
| 527 | call term_sendkeys(buf, ":set nomore\n") |
| 528 | call term_sendkeys(buf, ":args a b c\n") |
| 529 | call term_sendkeys(buf, ":confirm quit\n") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame^] | 530 | call TermWait(buf) |
Bram Moolenaar | 406cd90 | 2020-02-18 21:54:41 +0100 | [diff] [blame] | 531 | call WaitForAssert({-> assert_match('^\[Y\]es, (N)o: *$', |
| 532 | \ term_getline(buf, 6))}) |
| 533 | call term_sendkeys(buf, "N") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame^] | 534 | call TermWait(buf) |
Bram Moolenaar | 406cd90 | 2020-02-18 21:54:41 +0100 | [diff] [blame] | 535 | call term_sendkeys(buf, ":confirm quit\n") |
| 536 | call WaitForAssert({-> assert_match('^\[Y\]es, (N)o: *$', |
| 537 | \ term_getline(buf, 6))}) |
| 538 | call term_sendkeys(buf, "Y") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame^] | 539 | call TermWait(buf) |
Bram Moolenaar | 818fc9a | 2020-02-21 17:54:45 +0100 | [diff] [blame] | 540 | call WaitForAssert({-> assert_equal("finished", term_getstatus(buf))}) |
| 541 | only! |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 542 | " When this test fails, swap files are left behind which breaks subsequent |
| 543 | " tests |
| 544 | call delete('.a.swp') |
| 545 | call delete('.b.swp') |
| 546 | call delete('.c.swp') |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 547 | endfunc |
| 548 | |
| 549 | " vim: shiftwidth=2 sts=2 expandtab |