blob: 1bc556fa916ca0d1614bbafd3a32d31b4667b472 [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())
423 args a a a aa b b a b aa
424 argdedupe
425 call assert_equal(['a', 'aa', 'b'], argv())
426 args a b c
427 argdedupe
428 call assert_equal(['a', 'b', 'c'], argv())
429 args a
430 argdedupe
431 call assert_equal(['a'], argv())
432 args a A b B
433 argdedupe
434 if has('fname_case')
435 call assert_equal(['a', 'A', 'b', 'B'], argv())
436 else
437 call assert_equal(['a', 'b'], argv())
438 endif
439 args a b a c a b
440 last
441 argdedupe
442 next
443 call assert_equal('c', expand('%:t'))
444 %argd
445endfunc
446
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100447" Test for the :argdelete command
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100448func Test_argdelete()
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100449 call Reset_arglist()
450 args aa a aaa b bb
451 argdelete a*
452 call assert_equal(['b', 'bb'], argv())
453 call assert_equal('aa', expand('%:t'))
454 last
455 argdelete %
456 call assert_equal(['b'], argv())
Bram Moolenaar7b221172020-08-17 19:34:10 +0200457 call assert_fails('argdelete', 'E610:')
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100458 call assert_fails('1,100argdelete', 'E16:')
Bram Moolenaar531be472020-09-23 22:38:05 +0200459 call assert_fails('argdel /\)/', 'E55:')
Bram Moolenaarafe8cf62020-10-05 20:07:18 +0200460 call assert_fails('1argdel 1', 'E474:')
Bram Moolenaar7b221172020-08-17 19:34:10 +0200461
462 call Reset_arglist()
463 args a b c d
464 next
465 argdel
466 call Assert_argc(['a', 'c', 'd'])
467 %argdel
Dominique Pellebfb2bb12021-08-14 21:11:51 +0200468
469 call assert_fails('argdel does_not_exist', 'E480:')
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100470endfunc
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100471
Bram Moolenaarb513d302018-12-02 14:55:08 +0100472func Test_argdelete_completion()
473 args foo bar
474
475 call feedkeys(":argdelete \<C-A>\<C-B>\"\<CR>", 'tx')
476 call assert_equal('"argdelete bar foo', @:)
477
478 call feedkeys(":argdelete x \<C-A>\<C-B>\"\<CR>", 'tx')
479 call assert_equal('"argdelete x bar foo', @:)
480
481 %argd
482endfunc
483
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100484" Tests for the :next, :prev, :first, :last, :rewind commands
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100485func Test_argpos()
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100486 call Reset_arglist()
487 args a b c d
488 last
489 call assert_equal(3, argidx())
490 call assert_fails('next', 'E165:')
491 prev
492 call assert_equal(2, argidx())
493 Next
494 call assert_equal(1, argidx())
495 first
496 call assert_equal(0, argidx())
497 call assert_fails('prev', 'E164:')
498 3next
499 call assert_equal(3, argidx())
500 rewind
501 call assert_equal(0, argidx())
502 %argd
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100503endfunc
Bram Moolenaar53f16732016-09-07 20:46:39 +0200504
505" Test for autocommand that redefines the argument list, when doing ":all".
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100506func Test_arglist_autocmd()
Bram Moolenaar53f16732016-09-07 20:46:39 +0200507 autocmd BufReadPost Xxx2 next Xxx2 Xxx1
Bram Moolenaare1f3ab72022-09-04 21:29:08 +0100508 call writefile(['test file Xxx1'], 'Xxx1', 'D')
509 call writefile(['test file Xxx2'], 'Xxx2', 'D')
510 call writefile(['test file Xxx3'], 'Xxx3', 'D')
Bram Moolenaar53f16732016-09-07 20:46:39 +0200511
512 new
513 " redefine arglist; go to Xxx1
514 next! Xxx1 Xxx2 Xxx3
Bram Moolenaar679140c2021-12-24 18:58:46 +0000515 " open window for all args; Reading Xxx2 will try to change the arglist and
516 " that will fail
517 call assert_fails("all", "E1156:")
Bram Moolenaar53f16732016-09-07 20:46:39 +0200518 call assert_equal('test file Xxx1', getline(1))
519 wincmd w
Bram Moolenaar53f16732016-09-07 20:46:39 +0200520 call assert_equal('test file Xxx2', getline(1))
Bram Moolenaar679140c2021-12-24 18:58:46 +0000521 wincmd w
522 call assert_equal('test file Xxx3', getline(1))
Bram Moolenaar53f16732016-09-07 20:46:39 +0200523
524 autocmd! BufReadPost Xxx2
525 enew! | only
Bram Moolenaar53f16732016-09-07 20:46:39 +0200526 argdelete Xxx*
527 bwipe! Xxx1 Xxx2 Xxx3
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100528endfunc
529
530func Test_arg_all_expand()
Bram Moolenaare1f3ab72022-09-04 21:29:08 +0100531 call writefile(['test file Xxx1'], 'Xx x', 'D')
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100532 next notexist Xx\ x runtest.vim
533 call assert_equal('notexist Xx\ x runtest.vim', expand('##'))
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100534endfunc
Bram Moolenaare961cba2018-09-18 21:51:47 +0200535
536func Test_large_arg()
537 " Argument longer or equal to the number of columns used to cause
538 " access to invalid memory.
539 exe 'argadd ' .repeat('x', &columns)
540 args
541endfunc
Bram Moolenaar72e1b392019-08-03 13:50:08 +0200542
543func Test_argdo()
544 next! Xa.c Xb.c Xc.c
545 new
546 let l = []
547 argdo call add(l, expand('%'))
548 call assert_equal(['Xa.c', 'Xb.c', 'Xc.c'], l)
549 bwipe Xa.c Xb.c Xc.c
550endfunc
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100551
Bram Moolenaar8e7d6222020-12-18 19:49:56 +0100552" Test for quitting Vim with unedited files in the argument list
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100553func Test_quit_with_arglist()
Bram Moolenaar494e9062020-05-31 21:28:02 +0200554 CheckRunVimInTerminal
Bram Moolenaar21829c52021-01-26 22:42:21 +0100555
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100556 let buf = RunVimInTerminal('', {'rows': 6})
Bram Moolenaar818fc9a2020-02-21 17:54:45 +0100557 call term_sendkeys(buf, ":set nomore\n")
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100558 call term_sendkeys(buf, ":args a b c\n")
559 call term_sendkeys(buf, ":quit\n")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200560 call TermWait(buf)
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100561 call WaitForAssert({-> assert_match('^E173:', term_getline(buf, 6))})
562 call StopVimInTerminal(buf)
Bram Moolenaar406cd902020-02-18 21:54:41 +0100563
564 " Try :confirm quit with unedited files in arglist
565 let buf = RunVimInTerminal('', {'rows': 6})
566 call term_sendkeys(buf, ":set nomore\n")
567 call term_sendkeys(buf, ":args a b c\n")
568 call term_sendkeys(buf, ":confirm quit\n")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200569 call TermWait(buf)
Bram Moolenaar406cd902020-02-18 21:54:41 +0100570 call WaitForAssert({-> assert_match('^\[Y\]es, (N)o: *$',
571 \ term_getline(buf, 6))})
572 call term_sendkeys(buf, "N")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200573 call TermWait(buf)
Bram Moolenaar406cd902020-02-18 21:54:41 +0100574 call term_sendkeys(buf, ":confirm quit\n")
575 call WaitForAssert({-> assert_match('^\[Y\]es, (N)o: *$',
576 \ term_getline(buf, 6))})
577 call term_sendkeys(buf, "Y")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200578 call TermWait(buf)
Bram Moolenaar818fc9a2020-02-21 17:54:45 +0100579 call WaitForAssert({-> assert_equal("finished", term_getstatus(buf))})
580 only!
Bram Moolenaar1671f442020-03-10 07:48:13 +0100581 " When this test fails, swap files are left behind which breaks subsequent
582 " tests
583 call delete('.a.swp')
584 call delete('.b.swp')
585 call delete('.c.swp')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100586endfunc
587
Bram Moolenaarbb4b93e2021-01-26 21:35:08 +0100588" Test for ":all" not working when in the cmdline window
589func Test_all_not_allowed_from_cmdwin()
590 au BufEnter * all
591 next x
Bram Moolenaarbed72df2021-01-27 20:34:29 +0100592 " Use try/catch here, somehow assert_fails() doesn't work on MS-Windows
593 " console.
594 let caught = 'no'
595 try
596 exe ":norm! 7q?apat\<CR>"
597 catch /E11:/
598 let caught = 'yes'
599 endtry
600 call assert_equal('yes', caught)
Bram Moolenaarbb4b93e2021-01-26 21:35:08 +0100601 au! BufEnter
602endfunc
603
Bram Moolenaar6f983712021-12-24 18:11:27 +0000604func Test_clear_arglist_in_all()
605 n 0 00 000 0000 00000 000000
Bram Moolenaarb6db1462021-12-24 19:24:47 +0000606 au WinNew 0 n 0
Bram Moolenaar679140c2021-12-24 18:58:46 +0000607 call assert_fails("all", "E1156")
Bram Moolenaar6f983712021-12-24 18:11:27 +0000608 au! *
609endfunc
610
Yegappan Lakshmanan0dc2fd32022-09-09 11:27:59 +0100611" Test for the :all command
612func Test_all_command()
613 %argdelete
614
615 " :all command should not close windows with files in the argument list,
616 " but can rearrange the windows.
617 args Xargnew1 Xargnew2
618 %bw!
619 edit Xargold1
620 split Xargnew1
621 let Xargnew1_winid = win_getid()
622 split Xargold2
623 split Xargnew2
624 let Xargnew2_winid = win_getid()
625 split Xargold3
626 all
627 call assert_equal(2, winnr('$'))
628 call assert_equal([Xargnew1_winid, Xargnew2_winid],
629 \ [win_getid(1), win_getid(2)])
630 call assert_equal([bufnr('Xargnew1'), bufnr('Xargnew2')],
631 \ [winbufnr(1), winbufnr(2)])
632
633 " :all command should close windows for files which are not in the
634 " argument list in the current tab page.
635 %bw!
636 edit Xargold1
637 split Xargold2
638 tabedit Xargold3
639 split Xargold4
640 tabedit Xargold5
641 tabfirst
642 all
643 call assert_equal(3, tabpagenr('$'))
644 call assert_equal([bufnr('Xargnew1'), bufnr('Xargnew2')], tabpagebuflist(1))
645 call assert_equal([bufnr('Xargold4'), bufnr('Xargold3')], tabpagebuflist(2))
646 call assert_equal([bufnr('Xargold5')], tabpagebuflist(3))
647
648 " :tab all command should close windows for files which are not in the
649 " argument list across all the tab pages.
650 %bw!
651 edit Xargold1
652 split Xargold2
653 tabedit Xargold3
654 split Xargold4
655 tabedit Xargold5
656 tabfirst
657 args Xargnew1 Xargnew2
658 tab all
659 call assert_equal(2, tabpagenr('$'))
660 call assert_equal([bufnr('Xargnew1')], tabpagebuflist(1))
661 call assert_equal([bufnr('Xargnew2')], tabpagebuflist(2))
662
663 " If a count is specified, then :all should open only that many windows.
664 %bw!
665 args Xargnew1 Xargnew2 Xargnew3 Xargnew4 Xargnew5
666 all 3
667 call assert_equal(3, winnr('$'))
668 call assert_equal([bufnr('Xargnew1'), bufnr('Xargnew2'), bufnr('Xargnew3')],
669 \ [winbufnr(1), winbufnr(2), winbufnr(3)])
670
671 " The :all command should not open more than 'tabpagemax' tab pages.
672 " If there are more files, then they should be opened in the last tab page.
673 %bw!
674 set tabpagemax=3
675 tab all
676 call assert_equal(3, tabpagenr('$'))
677 call assert_equal([bufnr('Xargnew1')], tabpagebuflist(1))
678 call assert_equal([bufnr('Xargnew2')], tabpagebuflist(2))
679 call assert_equal([bufnr('Xargnew3'), bufnr('Xargnew4'), bufnr('Xargnew5')],
680 \ tabpagebuflist(3))
681 set tabpagemax&
682
683 " Without the 'hidden' option, modified buffers should not be closed.
684 args Xargnew1 Xargnew2
685 %bw!
686 edit Xargtemp1
687 call setline(1, 'temp buffer 1')
688 split Xargtemp2
689 call setline(1, 'temp buffer 2')
690 all
691 call assert_equal(4, winnr('$'))
692 call assert_equal([bufnr('Xargtemp2'), bufnr('Xargtemp1'), bufnr('Xargnew1'),
693 \ bufnr('Xargnew2')],
694 \ [winbufnr(1), winbufnr(2), winbufnr(3), winbufnr(4)])
695
696 " With the 'hidden' option set, both modified and unmodified buffers in
697 " closed windows should be hidden.
698 set hidden
699 all
700 call assert_equal(2, winnr('$'))
701 call assert_equal([bufnr('Xargnew1'), bufnr('Xargnew2')],
702 \ [winbufnr(1), winbufnr(2)])
703 call assert_equal([1, 1, 0, 0], [getbufinfo('Xargtemp1')[0].hidden,
704 \ getbufinfo('Xargtemp2')[0].hidden,
705 \ getbufinfo('Xargnew1')[0].hidden,
706 \ getbufinfo('Xargnew2')[0].hidden])
707 set nohidden
708
709 " When 'winheight' is set to a large value, :all should open only one
710 " window.
711 args Xargnew1 Xargnew2 Xargnew3 Xargnew4 Xargnew5
712 %bw!
713 set winheight=9999
714 call assert_fails('all', 'E36:')
715 call assert_equal([1, bufnr('Xargnew1')], [winnr('$'), winbufnr(1)])
716 set winheight&
717
718 " When 'winwidth' is set to a large value, :vert all should open only one
719 " window.
720 %bw!
721 set winwidth=9999
722 call assert_fails('vert all', 'E36:')
723 call assert_equal([1, bufnr('Xargnew1')], [winnr('$'), winbufnr(1)])
724 set winwidth&
725
726 " empty argument list tests
727 %bw!
728 %argdelete
729 call assert_equal('', execute('args'))
730 all
731 call assert_equal(1, winnr('$'))
732
733 %argdelete
734 %bw!
735endfunc
736
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100737" vim: shiftwidth=2 sts=2 expandtab