blob: edc8b77429e20ac6c68c5434bb35a621b9888484 [file] [log] [blame]
Bram Moolenaar72defda2016-01-17 18:04:33 +01001" Test argument list commands
2
Bram Moolenaar494e9062020-05-31 21:28:02 +02003source check.vim
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01004source shared.vim
5source term_util.vim
6
Shougo Matsushita3cad4702021-11-18 15:37:29 +00007func Reset_arglist()
8 args a | %argd
9endfunc
10
Bram Moolenaar72defda2016-01-17 18:04:33 +010011func Test_argidx()
12 args a b c
13 last
14 call assert_equal(2, argidx())
15 %argdelete
16 call assert_equal(0, argidx())
Bram Moolenaar69a92fb2017-03-09 15:58:30 +010017 " doing it again doesn't result in an error
18 %argdelete
19 call assert_equal(0, argidx())
20 call assert_fails('2argdelete', 'E16:')
Bram Moolenaar72defda2016-01-17 18:04:33 +010021
22 args a b c
23 call assert_equal(0, argidx())
24 next
25 call assert_equal(1, argidx())
26 next
27 call assert_equal(2, argidx())
28 1argdelete
29 call assert_equal(1, argidx())
30 1argdelete
31 call assert_equal(0, argidx())
32 1argdelete
33 call assert_equal(0, argidx())
34endfunc
Bram Moolenaara24f0a52016-01-17 19:39:00 +010035
36func Test_argadd()
Shougo Matsushita3cad4702021-11-18 15:37:29 +000037 call Reset_arglist()
38
Bram Moolenaara24f0a52016-01-17 19:39:00 +010039 %argdelete
40 argadd a b c
41 call assert_equal(0, argidx())
42
43 %argdelete
44 argadd a
45 call assert_equal(0, argidx())
46 argadd b c d
47 call assert_equal(0, argidx())
48
49 call Init_abc()
50 argadd x
51 call Assert_argc(['a', 'b', 'x', 'c'])
52 call assert_equal(1, argidx())
53
54 call Init_abc()
55 0argadd x
56 call Assert_argc(['x', 'a', 'b', 'c'])
57 call assert_equal(2, argidx())
58
59 call Init_abc()
60 1argadd x
61 call Assert_argc(['a', 'x', 'b', 'c'])
62 call assert_equal(2, argidx())
63
64 call Init_abc()
65 $argadd x
66 call Assert_argc(['a', 'b', 'c', 'x'])
67 call assert_equal(1, argidx())
68
69 call Init_abc()
70 $argadd x
71 +2argadd y
72 call Assert_argc(['a', 'b', 'c', 'x', 'y'])
73 call assert_equal(1, argidx())
Bram Moolenaar2faa29f2016-01-23 23:02:34 +010074
75 %argd
76 edit d
77 arga
Bram Moolenaar398ee732017-08-03 14:29:14 +020078 call assert_equal(1, len(argv()))
79 call assert_equal('d', get(argv(), 0, ''))
80
81 %argd
82 edit some\ file
83 arga
84 call assert_equal(1, len(argv()))
85 call assert_equal('some file', get(argv(), 0, ''))
Bram Moolenaar2faa29f2016-01-23 23:02:34 +010086
87 %argd
88 new
89 arga
Bram Moolenaar398ee732017-08-03 14:29:14 +020090 call assert_equal(0, len(argv()))
Dominique Pellebfb2bb12021-08-14 21:11:51 +020091
92 if has('unix')
93 call assert_fails('argadd `Xdoes_not_exist`', 'E479:')
94 endif
Bram Moolenaara24f0a52016-01-17 19:39:00 +010095endfunc
96
Bram Moolenaar32bbd002018-08-31 23:06:22 +020097func Test_argadd_empty_curbuf()
98 new
99 let curbuf = bufnr('%')
Bram Moolenaare1f3ab72022-09-04 21:29:08 +0100100 call writefile(['test', 'Xargadd'], 'Xargadd', 'D')
Bram Moolenaar32bbd002018-08-31 23:06:22 +0200101 " must not re-use the current buffer.
102 argadd Xargadd
103 call assert_equal(curbuf, bufnr('%'))
104 call assert_equal('', bufname('%'))
Bram Moolenaar02b31112019-08-31 22:16:38 +0200105 call assert_equal(1, '$'->line())
Bram Moolenaar32bbd002018-08-31 23:06:22 +0200106 rew
Bram Moolenaar073e4b92019-08-18 23:01:56 +0200107 call assert_notequal(curbuf, '%'->bufnr())
108 call assert_equal('Xargadd', '%'->bufname())
Bram Moolenaar32bbd002018-08-31 23:06:22 +0200109 call assert_equal(2, line('$'))
110
111 %argd
112 bwipe!
113endfunc
114
Bram Moolenaara24f0a52016-01-17 19:39:00 +0100115func Init_abc()
116 args a b c
117 next
118endfunc
119
120func Assert_argc(l)
121 call assert_equal(len(a:l), argc())
122 let i = 0
123 while i < len(a:l) && i < argc()
124 call assert_equal(a:l[i], argv(i))
125 let i += 1
126 endwhile
127endfunc
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100128
129" Test for [count]argument and [count]argdelete commands
130" Ported from the test_argument_count.in test script
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100131func Test_argument()
Shougo Matsushita3cad4702021-11-18 15:37:29 +0000132 call Reset_arglist()
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100133
134 let save_hidden = &hidden
135 set hidden
136
137 let g:buffers = []
138 augroup TEST
139 au BufEnter * call add(buffers, expand('%:t'))
140 augroup END
141
142 argadd a b c d
143 $argu
144 $-argu
145 -argu
146 1argu
147 +2argu
148
149 augroup TEST
150 au!
151 augroup END
152
153 call assert_equal(['d', 'c', 'b', 'a', 'c'], g:buffers)
154
Bram Moolenaar949f1982019-07-23 23:00:08 +0200155 call assert_equal("\na b [c] d ", execute(':args'))
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100156
157 .argd
158 call assert_equal(['a', 'b', 'd'], argv())
159
160 -argd
161 call assert_equal(['a', 'd'], argv())
162
163 $argd
164 call assert_equal(['a'], argv())
165
166 1arga c
167 1arga b
168 $argu
169 $arga x
170 call assert_equal(['a', 'b', 'c', 'x'], argv())
171
Bram Moolenaar30141702016-01-19 14:14:08 +0100172 0arga y
173 call assert_equal(['y', 'a', 'b', 'c', 'x'], argv())
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100174
175 %argd
176 call assert_equal([], argv())
177
178 arga a b c d e f
179 2,$-argd
180 call assert_equal(['a', 'f'], argv())
181
182 let &hidden = save_hidden
183
Bram Moolenaar9800bfe2019-07-27 21:23:45 +0200184 let save_columns = &columns
185 let &columns = 79
Bram Moolenaar71478202020-06-26 22:46:27 +0200186 try
187 exe 'args ' .. join(range(1, 81))
188 call assert_equal(join([
189 \ '',
190 \ '[1] 6 11 16 21 26 31 36 41 46 51 56 61 66 71 76 81 ',
191 \ '2 7 12 17 22 27 32 37 42 47 52 57 62 67 72 77 ',
192 \ '3 8 13 18 23 28 33 38 43 48 53 58 63 68 73 78 ',
193 \ '4 9 14 19 24 29 34 39 44 49 54 59 64 69 74 79 ',
194 \ '5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 ',
195 \ ], "\n"),
196 \ execute('args'))
Bram Moolenaar9800bfe2019-07-27 21:23:45 +0200197
Bram Moolenaar71478202020-06-26 22:46:27 +0200198 " No trailing newline with one item per row.
199 let long_arg = repeat('X', 81)
200 exe 'args ' .. long_arg
201 call assert_equal("\n[".long_arg.']', execute('args'))
202 finally
203 let &columns = save_columns
204 endtry
Bram Moolenaar9800bfe2019-07-27 21:23:45 +0200205
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100206 " Setting argument list should fail when the current buffer has unsaved
207 " changes
208 %argd
209 enew!
210 set modified
211 call assert_fails('args x y z', 'E37:')
212 args! x y z
213 call assert_equal(['x', 'y', 'z'], argv())
214 call assert_equal('x', expand('%:t'))
215
216 last | enew | argu
217 call assert_equal('z', expand('%:t'))
218
219 %argdelete
220 call assert_fails('argument', 'E163:')
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100221endfunc
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100222
Bram Moolenaar5d69da42018-04-20 22:01:41 +0200223func Test_list_arguments()
Shougo Matsushita3cad4702021-11-18 15:37:29 +0000224 call Reset_arglist()
Bram Moolenaar5d69da42018-04-20 22:01:41 +0200225
226 " four args half the screen width makes two lines with two columns
227 let aarg = repeat('a', &columns / 2 - 4)
228 let barg = repeat('b', &columns / 2 - 4)
229 let carg = repeat('c', &columns / 2 - 4)
230 let darg = repeat('d', &columns / 2 - 4)
231 exe 'argadd ' aarg barg carg darg
232
233 redir => result
234 args
235 redir END
236 call assert_match('\[' . aarg . '] \+' . carg . '\n' . barg . ' \+' . darg, trim(result))
237
238 " if one arg is longer than half the screen make one column
239 exe 'argdel' aarg
240 let aarg = repeat('a', &columns / 2 + 2)
241 exe '0argadd' aarg
242 redir => result
243 args
244 redir END
245 call assert_match(aarg . '\n\[' . barg . ']\n' . carg . '\n' . darg, trim(result))
246
247 %argdelete
248endfunc
249
Bram Moolenaar2ac372c2018-12-28 19:06:47 +0100250func Test_args_with_quote()
Bram Moolenaar3de8c2d2018-12-28 19:29:35 +0100251 " Only on Unix can a file name include a double quote.
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200252 CheckUnix
253
254 args \"foobar
255 call assert_equal('"foobar', argv(0))
256 %argdelete
Bram Moolenaar2ac372c2018-12-28 19:06:47 +0100257endfunc
258
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100259" Test for 0argadd and 0argedit
260" Ported from the test_argument_0count.in test script
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100261func Test_zero_argadd()
Shougo Matsushita3cad4702021-11-18 15:37:29 +0000262 call Reset_arglist()
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100263
264 arga a b c d
265 2argu
266 0arga added
267 call assert_equal(['added', 'a', 'b', 'c', 'd'], argv())
268
269 2argu
270 arga third
271 call assert_equal(['added', 'a', 'third', 'b', 'c', 'd'], argv())
272
273 %argd
274 arga a b c d
275 2argu
276 0arge edited
277 call assert_equal(['edited', 'a', 'b', 'c', 'd'], argv())
278
279 2argu
280 arga third
281 call assert_equal(['edited', 'a', 'third', 'b', 'c', 'd'], argv())
Bram Moolenaar90305c62017-07-16 15:31:17 +0200282
283 2argu
284 argedit file\ with\ spaces another file
285 call assert_equal(['edited', 'a', 'file with spaces', 'another', 'file', 'third', 'b', 'c', 'd'], argv())
286 call assert_equal('file with spaces', expand('%'))
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100287endfunc
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100288
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100289" Test for argc()
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100290func Test_argc()
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100291 call Reset_arglist()
292 call assert_equal(0, argc())
293 argadd a b
294 call assert_equal(2, argc())
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100295endfunc
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100296
297" Test for arglistid()
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100298func Test_arglistid()
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100299 call Reset_arglist()
300 arga a b
301 call assert_equal(0, arglistid())
302 split
303 arglocal
304 call assert_equal(1, arglistid())
305 tabnew | tabfirst
306 call assert_equal(0, arglistid(2))
307 call assert_equal(1, arglistid(1, 1))
308 call assert_equal(0, arglistid(2, 1))
309 call assert_equal(1, arglistid(1, 2))
310 tabonly | only | enew!
311 argglobal
312 call assert_equal(0, arglistid())
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100313endfunc
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100314
Bram Moolenaare6e39892018-10-25 12:32:11 +0200315" Tests for argv() and argc()
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100316func Test_argv()
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100317 call Reset_arglist()
318 call assert_equal([], argv())
319 call assert_equal("", argv(2))
Bram Moolenaare6e39892018-10-25 12:32:11 +0200320 call assert_equal(0, argc())
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100321 argadd a b c d
Bram Moolenaare6e39892018-10-25 12:32:11 +0200322 call assert_equal(4, argc())
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100323 call assert_equal('c', argv(2))
Bram Moolenaare6e39892018-10-25 12:32:11 +0200324
325 let w1_id = win_getid()
326 split
327 let w2_id = win_getid()
328 arglocal
329 args e f g
330 tabnew
331 let w3_id = win_getid()
332 split
333 let w4_id = win_getid()
334 argglobal
335 tabfirst
336 call assert_equal(4, argc(w1_id))
337 call assert_equal('b', argv(1, w1_id))
338 call assert_equal(['a', 'b', 'c', 'd'], argv(-1, w1_id))
339
340 call assert_equal(3, argc(w2_id))
341 call assert_equal('f', argv(1, w2_id))
342 call assert_equal(['e', 'f', 'g'], argv(-1, w2_id))
343
344 call assert_equal(3, argc(w3_id))
345 call assert_equal('e', argv(0, w3_id))
346 call assert_equal(['e', 'f', 'g'], argv(-1, w3_id))
347
348 call assert_equal(4, argc(w4_id))
349 call assert_equal('c', argv(2, w4_id))
350 call assert_equal(['a', 'b', 'c', 'd'], argv(-1, w4_id))
351
352 call assert_equal(4, argc(-1))
353 call assert_equal(3, argc())
354 call assert_equal('d', argv(3, -1))
355 call assert_equal(['a', 'b', 'c', 'd'], argv(-1, -1))
356 tabonly | only | enew!
357 " Negative test cases
358 call assert_equal(-1, argc(100))
359 call assert_equal('', argv(1, 100))
360 call assert_equal([], argv(-1, 100))
361 call assert_equal('', argv(10, -1))
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100362endfunc
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100363
364" Test for the :argedit command
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100365func Test_argedit()
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100366 call Reset_arglist()
367 argedit a
368 call assert_equal(['a'], argv())
369 call assert_equal('a', expand('%:t'))
370 argedit b
371 call assert_equal(['a', 'b'], argv())
372 call assert_equal('b', expand('%:t'))
373 argedit a
Bram Moolenaar90305c62017-07-16 15:31:17 +0200374 call assert_equal(['a', 'b', 'a'], argv())
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100375 call assert_equal('a', expand('%:t'))
Bram Moolenaar9b50bba2017-07-16 16:42:13 +0200376 " When file name case is ignored, an existing buffer with only case
Bram Moolenaarcf1ba352017-10-27 00:55:04 +0200377 " difference is re-used.
Bram Moolenaar90305c62017-07-16 15:31:17 +0200378 argedit C D
379 call assert_equal('C', expand('%:t'))
380 call assert_equal(['a', 'b', 'a', 'C', 'D'], argv())
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100381 argedit c
Bram Moolenaar9b50bba2017-07-16 16:42:13 +0200382 if has('fname_case')
383 call assert_equal(['a', 'b', 'a', 'C', 'c', 'D'], argv())
384 else
385 call assert_equal(['a', 'b', 'a', 'C', 'C', 'D'], argv())
386 endif
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100387 0argedit x
Bram Moolenaar9b50bba2017-07-16 16:42:13 +0200388 if has('fname_case')
389 call assert_equal(['x', 'a', 'b', 'a', 'C', 'c', 'D'], argv())
390 else
391 call assert_equal(['x', 'a', 'b', 'a', 'C', 'C', 'D'], argv())
392 endif
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100393 enew! | set modified
394 call assert_fails('argedit y', 'E37:')
395 argedit! y
Bram Moolenaar9b50bba2017-07-16 16:42:13 +0200396 if has('fname_case')
397 call assert_equal(['x', 'y', 'y', 'a', 'b', 'a', 'C', 'c', 'D'], argv())
398 else
399 call assert_equal(['x', 'y', 'y', 'a', 'b', 'a', 'C', 'C', 'D'], argv())
400 endif
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100401 %argd
Bram Moolenaar9b50bba2017-07-16 16:42:13 +0200402 bwipe! C
403 bwipe! D
Bram Moolenaar46a53df2018-04-24 21:58:51 +0200404
405 " :argedit reuses the current buffer if it is empty
406 %argd
407 " make sure to use a new buffer number for x when it is loaded
408 bw! x
409 new
Bram Moolenaara8eee212019-08-24 22:14:58 +0200410 let a = bufnr()
Bram Moolenaar46a53df2018-04-24 21:58:51 +0200411 argedit x
Bram Moolenaara8eee212019-08-24 22:14:58 +0200412 call assert_equal(a, bufnr())
413 call assert_equal('x', bufname())
Bram Moolenaar46a53df2018-04-24 21:58:51 +0200414 %argd
415 bw! x
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100416endfunc
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100417
Nir Lichtman73a02422021-12-24 20:28:03 +0000418" Test for the :argdedupe command
419func Test_argdedupe()
420 call Reset_arglist()
421 argdedupe
422 call assert_equal([], argv())
Nir Lichtmanb3052aa2022-11-12 17:00:31 +0000423
Nir Lichtman73a02422021-12-24 20:28:03 +0000424 args a a a aa b b a b aa
425 argdedupe
426 call assert_equal(['a', 'aa', 'b'], argv())
Nir Lichtmanb3052aa2022-11-12 17:00:31 +0000427
Nir Lichtman73a02422021-12-24 20:28:03 +0000428 args a b c
429 argdedupe
430 call assert_equal(['a', 'b', 'c'], argv())
Nir Lichtmanb3052aa2022-11-12 17:00:31 +0000431
Nir Lichtman73a02422021-12-24 20:28:03 +0000432 args a
433 argdedupe
434 call assert_equal(['a'], argv())
Nir Lichtmanb3052aa2022-11-12 17:00:31 +0000435
Nir Lichtman73a02422021-12-24 20:28:03 +0000436 args a A b B
437 argdedupe
438 if has('fname_case')
439 call assert_equal(['a', 'A', 'b', 'B'], argv())
440 else
441 call assert_equal(['a', 'b'], argv())
442 endif
Nir Lichtmanb3052aa2022-11-12 17:00:31 +0000443
Nir Lichtman73a02422021-12-24 20:28:03 +0000444 args a b a c a b
445 last
446 argdedupe
447 next
448 call assert_equal('c', expand('%:t'))
Nir Lichtmanb3052aa2022-11-12 17:00:31 +0000449
450 args a ./a
451 argdedupe
452 call assert_equal(['a'], argv())
453
Nir Lichtman73a02422021-12-24 20:28:03 +0000454 %argd
455endfunc
456
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100457" Test for the :argdelete command
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100458func Test_argdelete()
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100459 call Reset_arglist()
460 args aa a aaa b bb
461 argdelete a*
462 call assert_equal(['b', 'bb'], argv())
463 call assert_equal('aa', expand('%:t'))
464 last
465 argdelete %
466 call assert_equal(['b'], argv())
Bram Moolenaar7b221172020-08-17 19:34:10 +0200467 call assert_fails('argdelete', 'E610:')
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100468 call assert_fails('1,100argdelete', 'E16:')
Bram Moolenaar531be472020-09-23 22:38:05 +0200469 call assert_fails('argdel /\)/', 'E55:')
Bram Moolenaarafe8cf62020-10-05 20:07:18 +0200470 call assert_fails('1argdel 1', 'E474:')
Bram Moolenaar7b221172020-08-17 19:34:10 +0200471
472 call Reset_arglist()
473 args a b c d
474 next
475 argdel
476 call Assert_argc(['a', 'c', 'd'])
477 %argdel
Dominique Pellebfb2bb12021-08-14 21:11:51 +0200478
479 call assert_fails('argdel does_not_exist', 'E480:')
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100480endfunc
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100481
Bram Moolenaarb513d302018-12-02 14:55:08 +0100482func Test_argdelete_completion()
483 args foo bar
484
485 call feedkeys(":argdelete \<C-A>\<C-B>\"\<CR>", 'tx')
486 call assert_equal('"argdelete bar foo', @:)
487
488 call feedkeys(":argdelete x \<C-A>\<C-B>\"\<CR>", 'tx')
489 call assert_equal('"argdelete x bar foo', @:)
490
491 %argd
492endfunc
493
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100494" Tests for the :next, :prev, :first, :last, :rewind commands
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100495func Test_argpos()
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100496 call Reset_arglist()
497 args a b c d
498 last
499 call assert_equal(3, argidx())
500 call assert_fails('next', 'E165:')
501 prev
502 call assert_equal(2, argidx())
503 Next
504 call assert_equal(1, argidx())
505 first
506 call assert_equal(0, argidx())
507 call assert_fails('prev', 'E164:')
508 3next
509 call assert_equal(3, argidx())
510 rewind
511 call assert_equal(0, argidx())
512 %argd
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100513endfunc
Bram Moolenaar53f16732016-09-07 20:46:39 +0200514
515" Test for autocommand that redefines the argument list, when doing ":all".
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100516func Test_arglist_autocmd()
Bram Moolenaar53f16732016-09-07 20:46:39 +0200517 autocmd BufReadPost Xxx2 next Xxx2 Xxx1
Bram Moolenaare1f3ab72022-09-04 21:29:08 +0100518 call writefile(['test file Xxx1'], 'Xxx1', 'D')
519 call writefile(['test file Xxx2'], 'Xxx2', 'D')
520 call writefile(['test file Xxx3'], 'Xxx3', 'D')
Bram Moolenaar53f16732016-09-07 20:46:39 +0200521
522 new
523 " redefine arglist; go to Xxx1
524 next! Xxx1 Xxx2 Xxx3
Bram Moolenaar679140c2021-12-24 18:58:46 +0000525 " open window for all args; Reading Xxx2 will try to change the arglist and
526 " that will fail
527 call assert_fails("all", "E1156:")
Bram Moolenaar53f16732016-09-07 20:46:39 +0200528 call assert_equal('test file Xxx1', getline(1))
529 wincmd w
Bram Moolenaar53f16732016-09-07 20:46:39 +0200530 call assert_equal('test file Xxx2', getline(1))
Bram Moolenaar679140c2021-12-24 18:58:46 +0000531 wincmd w
532 call assert_equal('test file Xxx3', getline(1))
Bram Moolenaar53f16732016-09-07 20:46:39 +0200533
534 autocmd! BufReadPost Xxx2
535 enew! | only
Bram Moolenaar53f16732016-09-07 20:46:39 +0200536 argdelete Xxx*
537 bwipe! Xxx1 Xxx2 Xxx3
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100538endfunc
539
540func Test_arg_all_expand()
Bram Moolenaare1f3ab72022-09-04 21:29:08 +0100541 call writefile(['test file Xxx1'], 'Xx x', 'D')
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100542 next notexist Xx\ x runtest.vim
543 call assert_equal('notexist Xx\ x runtest.vim', expand('##'))
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100544endfunc
Bram Moolenaare961cba2018-09-18 21:51:47 +0200545
546func Test_large_arg()
547 " Argument longer or equal to the number of columns used to cause
548 " access to invalid memory.
549 exe 'argadd ' .repeat('x', &columns)
550 args
551endfunc
Bram Moolenaar72e1b392019-08-03 13:50:08 +0200552
553func Test_argdo()
554 next! Xa.c Xb.c Xc.c
555 new
556 let l = []
557 argdo call add(l, expand('%'))
558 call assert_equal(['Xa.c', 'Xb.c', 'Xc.c'], l)
559 bwipe Xa.c Xb.c Xc.c
560endfunc
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100561
Bram Moolenaar8e7d6222020-12-18 19:49:56 +0100562" Test for quitting Vim with unedited files in the argument list
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100563func Test_quit_with_arglist()
Bram Moolenaar494e9062020-05-31 21:28:02 +0200564 CheckRunVimInTerminal
Bram Moolenaar21829c52021-01-26 22:42:21 +0100565
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100566 let buf = RunVimInTerminal('', {'rows': 6})
Bram Moolenaar818fc9a2020-02-21 17:54:45 +0100567 call term_sendkeys(buf, ":set nomore\n")
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100568 call term_sendkeys(buf, ":args a b c\n")
569 call term_sendkeys(buf, ":quit\n")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200570 call TermWait(buf)
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100571 call WaitForAssert({-> assert_match('^E173:', term_getline(buf, 6))})
572 call StopVimInTerminal(buf)
Bram Moolenaar406cd902020-02-18 21:54:41 +0100573
574 " Try :confirm quit with unedited files in arglist
575 let buf = RunVimInTerminal('', {'rows': 6})
576 call term_sendkeys(buf, ":set nomore\n")
577 call term_sendkeys(buf, ":args a b c\n")
578 call term_sendkeys(buf, ":confirm quit\n")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200579 call TermWait(buf)
Bram Moolenaar406cd902020-02-18 21:54:41 +0100580 call WaitForAssert({-> assert_match('^\[Y\]es, (N)o: *$',
581 \ term_getline(buf, 6))})
582 call term_sendkeys(buf, "N")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200583 call TermWait(buf)
Bram Moolenaar406cd902020-02-18 21:54:41 +0100584 call term_sendkeys(buf, ":confirm quit\n")
585 call WaitForAssert({-> assert_match('^\[Y\]es, (N)o: *$',
586 \ term_getline(buf, 6))})
587 call term_sendkeys(buf, "Y")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200588 call TermWait(buf)
Bram Moolenaar818fc9a2020-02-21 17:54:45 +0100589 call WaitForAssert({-> assert_equal("finished", term_getstatus(buf))})
590 only!
Bram Moolenaar1671f442020-03-10 07:48:13 +0100591 " When this test fails, swap files are left behind which breaks subsequent
592 " tests
593 call delete('.a.swp')
594 call delete('.b.swp')
595 call delete('.c.swp')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100596endfunc
597
Bram Moolenaarbb4b93e2021-01-26 21:35:08 +0100598" Test for ":all" not working when in the cmdline window
599func Test_all_not_allowed_from_cmdwin()
600 au BufEnter * all
601 next x
Bram Moolenaarbed72df2021-01-27 20:34:29 +0100602 " Use try/catch here, somehow assert_fails() doesn't work on MS-Windows
603 " console.
604 let caught = 'no'
605 try
606 exe ":norm! 7q?apat\<CR>"
607 catch /E11:/
608 let caught = 'yes'
609 endtry
610 call assert_equal('yes', caught)
Bram Moolenaarbb4b93e2021-01-26 21:35:08 +0100611 au! BufEnter
612endfunc
613
Bram Moolenaar6f983712021-12-24 18:11:27 +0000614func Test_clear_arglist_in_all()
615 n 0 00 000 0000 00000 000000
Bram Moolenaarb6db1462021-12-24 19:24:47 +0000616 au WinNew 0 n 0
Bram Moolenaar679140c2021-12-24 18:58:46 +0000617 call assert_fails("all", "E1156")
Bram Moolenaar6f983712021-12-24 18:11:27 +0000618 au! *
619endfunc
620
Yegappan Lakshmanan0dc2fd32022-09-09 11:27:59 +0100621" Test for the :all command
622func Test_all_command()
623 %argdelete
624
625 " :all command should not close windows with files in the argument list,
626 " but can rearrange the windows.
627 args Xargnew1 Xargnew2
628 %bw!
629 edit Xargold1
630 split Xargnew1
631 let Xargnew1_winid = win_getid()
632 split Xargold2
633 split Xargnew2
634 let Xargnew2_winid = win_getid()
635 split Xargold3
636 all
637 call assert_equal(2, winnr('$'))
638 call assert_equal([Xargnew1_winid, Xargnew2_winid],
639 \ [win_getid(1), win_getid(2)])
640 call assert_equal([bufnr('Xargnew1'), bufnr('Xargnew2')],
641 \ [winbufnr(1), winbufnr(2)])
642
643 " :all command should close windows for files which are not in the
644 " argument list in the current tab page.
645 %bw!
646 edit Xargold1
647 split Xargold2
648 tabedit Xargold3
649 split Xargold4
650 tabedit Xargold5
651 tabfirst
652 all
653 call assert_equal(3, tabpagenr('$'))
654 call assert_equal([bufnr('Xargnew1'), bufnr('Xargnew2')], tabpagebuflist(1))
655 call assert_equal([bufnr('Xargold4'), bufnr('Xargold3')], tabpagebuflist(2))
656 call assert_equal([bufnr('Xargold5')], tabpagebuflist(3))
657
658 " :tab all command should close windows for files which are not in the
659 " argument list across all the tab pages.
660 %bw!
661 edit Xargold1
662 split Xargold2
663 tabedit Xargold3
664 split Xargold4
665 tabedit Xargold5
666 tabfirst
667 args Xargnew1 Xargnew2
668 tab all
669 call assert_equal(2, tabpagenr('$'))
670 call assert_equal([bufnr('Xargnew1')], tabpagebuflist(1))
671 call assert_equal([bufnr('Xargnew2')], tabpagebuflist(2))
672
673 " If a count is specified, then :all should open only that many windows.
674 %bw!
675 args Xargnew1 Xargnew2 Xargnew3 Xargnew4 Xargnew5
676 all 3
677 call assert_equal(3, winnr('$'))
678 call assert_equal([bufnr('Xargnew1'), bufnr('Xargnew2'), bufnr('Xargnew3')],
679 \ [winbufnr(1), winbufnr(2), winbufnr(3)])
680
681 " The :all command should not open more than 'tabpagemax' tab pages.
682 " If there are more files, then they should be opened in the last tab page.
683 %bw!
684 set tabpagemax=3
685 tab all
686 call assert_equal(3, tabpagenr('$'))
687 call assert_equal([bufnr('Xargnew1')], tabpagebuflist(1))
688 call assert_equal([bufnr('Xargnew2')], tabpagebuflist(2))
689 call assert_equal([bufnr('Xargnew3'), bufnr('Xargnew4'), bufnr('Xargnew5')],
690 \ tabpagebuflist(3))
691 set tabpagemax&
692
693 " Without the 'hidden' option, modified buffers should not be closed.
694 args Xargnew1 Xargnew2
695 %bw!
696 edit Xargtemp1
697 call setline(1, 'temp buffer 1')
698 split Xargtemp2
699 call setline(1, 'temp buffer 2')
700 all
701 call assert_equal(4, winnr('$'))
702 call assert_equal([bufnr('Xargtemp2'), bufnr('Xargtemp1'), bufnr('Xargnew1'),
703 \ bufnr('Xargnew2')],
704 \ [winbufnr(1), winbufnr(2), winbufnr(3), winbufnr(4)])
705
706 " With the 'hidden' option set, both modified and unmodified buffers in
707 " closed windows should be hidden.
708 set hidden
709 all
710 call assert_equal(2, winnr('$'))
711 call assert_equal([bufnr('Xargnew1'), bufnr('Xargnew2')],
712 \ [winbufnr(1), winbufnr(2)])
713 call assert_equal([1, 1, 0, 0], [getbufinfo('Xargtemp1')[0].hidden,
714 \ getbufinfo('Xargtemp2')[0].hidden,
715 \ getbufinfo('Xargnew1')[0].hidden,
716 \ getbufinfo('Xargnew2')[0].hidden])
717 set nohidden
718
719 " When 'winheight' is set to a large value, :all should open only one
720 " window.
721 args Xargnew1 Xargnew2 Xargnew3 Xargnew4 Xargnew5
722 %bw!
723 set winheight=9999
724 call assert_fails('all', 'E36:')
725 call assert_equal([1, bufnr('Xargnew1')], [winnr('$'), winbufnr(1)])
726 set winheight&
727
728 " When 'winwidth' is set to a large value, :vert all should open only one
729 " window.
730 %bw!
731 set winwidth=9999
732 call assert_fails('vert all', 'E36:')
733 call assert_equal([1, bufnr('Xargnew1')], [winnr('$'), winbufnr(1)])
734 set winwidth&
735
736 " empty argument list tests
737 %bw!
738 %argdelete
739 call assert_equal('', execute('args'))
740 all
741 call assert_equal(1, winnr('$'))
742
743 %argdelete
744 %bw!
745endfunc
746
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100747" vim: shiftwidth=2 sts=2 expandtab