robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqvim-patch:9.2.0812: :argdelete with pattern leads to wrong argidx() (#40876)60b643a815

master
20.4 KiB851 linesraw
1" Test argument list commands
2
3source check.vim
4source shared.vim
5source term_util.vim
6
7func Reset_arglist()
8  args a | %argd
9endfunc
10
11func Test_argidx()
12  args a b c
13  last
14  call assert_equal(2, argidx())
15  %argdelete
16  call assert_equal(0, argidx())
17  " doing it again doesn't result in an error
18  %argdelete
19  call assert_equal(0, argidx())
20  call assert_fails('2argdelete', 'E16:')
21
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
35
36func Test_argadd()
37  call Reset_arglist()
38
39  %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())
74
75  %argd
76  edit d
77  arga
78  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, ''))
86
87  %argd
88  new
89  arga
90  call assert_equal(0, len(argv()))
91
92  if has('unix')
93    call assert_fails('argadd `Xdoes_not_exist`', 'E479:')
94  endif
95endfunc
96
97func Test_argadd_empty_curbuf()
98  new
99  let curbuf = bufnr('%')
100  call writefile(['test', 'Xargadd'], 'Xargadd', 'D')
101  " must not re-use the current buffer.
102  argadd Xargadd
103  call assert_equal(curbuf, bufnr('%'))
104  call assert_equal('', bufname('%'))
105  call assert_equal(1, '$'->line())
106  rew
107  call assert_notequal(curbuf, '%'->bufnr())
108  call assert_equal('Xargadd', '%'->bufname())
109  call assert_equal(2, line('$'))
110
111  %argd
112  bwipe!
113endfunc
114
115func 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
128
129" Test for [count]argument and [count]argdelete commands
130" Ported from the test_argument_count.in test script
131func Test_argument()
132  call Reset_arglist()
133
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
155  call assert_equal("\na   b   [c] d   ", execute(':args'))
156
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
172  0arga y
173  call assert_equal(['y', 'a', 'b', 'c', 'x'], argv())
174
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
184  let save_columns = &columns
185  let &columns = 79
186  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'))
197
198    " 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
205
206  " 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:')
221endfunc
222
223func Test_list_arguments()
224  " Clean the argument list
225  arga a | %argd
226
227  " four args half the screen width makes two lines with two columns
228  let aarg = repeat('a', &columns / 2 - 4)
229  let barg = repeat('b', &columns / 2 - 4)
230  let carg = repeat('c', &columns / 2 - 4)
231  let darg = repeat('d', &columns / 2 - 4)
232  exe 'argadd ' aarg barg carg darg
233
234  redir => result
235  args
236  redir END
237  call assert_match('\[' . aarg . '] \+' . carg . '\n' . barg . ' \+' . darg, trim(result))
238
239  " if one arg is longer than half the screen make one column
240  exe 'argdel' aarg
241  let aarg = repeat('a', &columns / 2 + 2)
242  exe '0argadd' aarg
243  redir => result
244  args
245  redir END
246  call assert_match(aarg . '\n\[' . barg . ']\n' . carg . '\n' . darg, trim(result))
247
248  %argdelete
249endfunc
250
251func Test_args_with_quote()
252  " Only on Unix can a file name include a double quote.
253  if has('unix')
254    args \"foobar
255    call assert_equal('"foobar', argv(0))
256    %argdelete
257  endif
258endfunc
259
260" Test for 0argadd and 0argedit
261" Ported from the test_argument_0count.in test script
262func Test_zero_argadd()
263  call Reset_arglist()
264
265  arga a b c d
266  2argu
267  0arga added
268  call assert_equal(['added', 'a', 'b', 'c', 'd'], argv())
269
270  2argu
271  arga third
272  call assert_equal(['added', 'a', 'third', 'b', 'c', 'd'], argv())
273
274  %argd
275  arga a b c d
276  2argu
277  0arge edited
278  call assert_equal(['edited', 'a', 'b', 'c', 'd'], argv())
279
280  2argu
281  arga third
282  call assert_equal(['edited', 'a', 'third', 'b', 'c', 'd'], argv())
283
284  2argu
285  argedit file\ with\ spaces another file
286  call assert_equal(['edited', 'a', 'file with spaces', 'another', 'file', 'third', 'b', 'c', 'd'], argv())
287  call assert_equal('file with spaces', expand('%'))
288endfunc
289
290" Test for argc()
291func Test_argc()
292  call Reset_arglist()
293  call assert_equal(0, argc())
294  argadd a b
295  call assert_equal(2, argc())
296endfunc
297
298" Test for arglistid()
299func Test_arglistid()
300  call Reset_arglist()
301  arga a b
302  call assert_equal(0, arglistid())
303  split
304  arglocal
305  call assert_equal(1, arglistid())
306  tabnew | tabfirst
307  call assert_equal(0, arglistid(2))
308  call assert_equal(1, arglistid(1, 1))
309  call assert_equal(0, arglistid(2, 1))
310  call assert_equal(1, arglistid(1, 2))
311  tabonly | only | enew!
312  argglobal
313  call assert_equal(0, arglistid())
314endfunc
315
316" Tests for argv() and argc()
317func Test_argv()
318  call Reset_arglist()
319  call assert_equal([], argv())
320  call assert_equal("", argv(2))
321  call assert_equal(0, argc())
322  argadd a b c d
323  call assert_equal(4, argc())
324  call assert_equal('c', argv(2))
325
326  let w1_id = win_getid()
327  split
328  let w2_id = win_getid()
329  arglocal
330  args e f g
331  tabnew
332  let w3_id = win_getid()
333  split
334  let w4_id = win_getid()
335  argglobal
336  tabfirst
337  call assert_equal(4, argc(w1_id))
338  call assert_equal('b', argv(1, w1_id))
339  call assert_equal(['a', 'b', 'c', 'd'], argv(-1, w1_id))
340
341  call assert_equal(3, argc(w2_id))
342  call assert_equal('f', argv(1, w2_id))
343  call assert_equal(['e', 'f', 'g'], argv(-1, w2_id))
344
345  call assert_equal(3, argc(w3_id))
346  call assert_equal('e', argv(0, w3_id))
347  call assert_equal(['e', 'f', 'g'], argv(-1, w3_id))
348
349  call assert_equal(4, argc(w4_id))
350  call assert_equal('c', argv(2, w4_id))
351  call assert_equal(['a', 'b', 'c', 'd'], argv(-1, w4_id))
352
353  call assert_equal(4, argc(-1))
354  call assert_equal(3, argc())
355  call assert_equal('d', argv(3, -1))
356  call assert_equal(['a', 'b', 'c', 'd'], argv(-1, -1))
357  tabonly | only | enew!
358  " Negative test cases
359  call assert_equal(-1, argc(100))
360  call assert_equal('', argv(1, 100))
361  call assert_equal([], argv(-1, 100))
362  call assert_equal('', argv(10, -1))
363  %argdelete
364endfunc
365
366" Test for the :argedit command
367func Test_argedit()
368  call Reset_arglist()
369  argedit a
370  call assert_equal(['a'], argv())
371  call assert_equal('a', expand('%:t'))
372  argedit b
373  call assert_equal(['a', 'b'], argv())
374  call assert_equal('b', expand('%:t'))
375  argedit a
376  call assert_equal(['a', 'b', 'a'], argv())
377  call assert_equal('a', expand('%:t'))
378  " When file name case is ignored, an existing buffer with only case
379  " difference is re-used.
380  argedit C D
381  call assert_equal('C', expand('%:t'))
382  call assert_equal(['a', 'b', 'a', 'C', 'D'], argv())
383  argedit c
384  if has('fname_case')
385    call assert_equal(['a', 'b', 'a', 'C', 'c', 'D'], argv())
386  else
387    call assert_equal(['a', 'b', 'a', 'C', 'C', 'D'], argv())
388  endif
389  0argedit x
390  if has('fname_case')
391    call assert_equal(['x', 'a', 'b', 'a', 'C', 'c', 'D'], argv())
392  else
393    call assert_equal(['x', 'a', 'b', 'a', 'C', 'C', 'D'], argv())
394  endif
395  enew! | set modified
396  call assert_fails('argedit y', 'E37:')
397  argedit! y
398  if has('fname_case')
399    call assert_equal(['x', 'y', 'y', 'a', 'b', 'a', 'C', 'c', 'D'], argv())
400  else
401    call assert_equal(['x', 'y', 'y', 'a', 'b', 'a', 'C', 'C', 'D'], argv())
402  endif
403  %argd
404  bwipe! C
405  bwipe! D
406
407  " :argedit reuses the current buffer if it is empty
408  %argd
409  " make sure to use a new buffer number for x when it is loaded
410  bw! x
411  new
412  let a = bufnr()
413  argedit x
414  call assert_equal(a, bufnr())
415  call assert_equal('x', bufname())
416  %argd
417  bw! x
418endfunc
419
420" Test for the :argdedupe command
421func Test_argdedupe()
422  call Reset_arglist()
423  argdedupe
424  call assert_equal([], argv())
425
426  args a a a aa b b a b aa
427  argdedupe
428  call assert_equal(['a', 'aa', 'b'], argv())
429
430  args a b c
431  argdedupe
432  call assert_equal(['a', 'b', 'c'], argv())
433
434  args a
435  argdedupe
436  call assert_equal(['a'], argv())
437
438  args a A b B
439  argdedupe
440  if has('fname_case')
441    call assert_equal(['a', 'A', 'b', 'B'], argv())
442  else
443    call assert_equal(['a', 'b'], argv())
444  endif
445
446  args a b a c a b
447  last
448  argdedupe
449  next
450  call assert_equal('c', expand('%:t'))
451
452  args a ./a
453  argdedupe
454  call assert_equal(['a'], argv())
455
456  %argd
457endfunc
458
459" Test for the :argdelete command
460func Test_argdelete()
461  call Reset_arglist()
462  args aa a aaa b bb
463  argdelete a*
464  call assert_equal(['b', 'bb'], argv())
465  call assert_equal(0, argidx())
466  call assert_equal('aa', expand('%:t'))
467  last
468  call assert_equal(1, argidx())
469  call assert_equal('bb', expand('%:t'))
470  argdelete %
471  call assert_equal(['b'], argv())
472  call assert_equal(0, argidx())
473  call assert_equal('bb', expand('%:t'))
474
475  call assert_fails('1,100argdelete', 'E16:')
476  call assert_fails('argdel /\)/', 'E55:')
477  call assert_fails('1argdel 1', 'E474:')
478
479  call Reset_arglist()
480  args aa a aaa b bb
481  4argument
482  call assert_equal(3, argidx())
483  call assert_equal('b', expand('%:t'))
484  argdelete aa*
485  call assert_equal(['a', 'b', 'bb'], argv())
486  call assert_equal(1, argidx())
487  call assert_equal('b', expand('%:t'))
488  2argdelete
489  call assert_equal(['a', 'bb'], argv())
490  call assert_equal(1, argidx())
491  call assert_equal('b', expand('%:t'))
492  %argdelete
493  call assert_equal([], argv())
494  call assert_equal(0, argidx())
495  call assert_equal('b', expand('%:t'))
496  " :%argdelete when the arglist is already empty should not error
497  %argdelete
498
499  call Reset_arglist()
500  args a b c d
501  next
502  argdel
503  call Assert_argc(['a', 'c', 'd'])
504  %argdel
505
506  call assert_fails('argdel does_not_exist', 'E480:')
507endfunc
508
509func Test_argdelete_completion()
510  args foo bar
511
512  call feedkeys(":argdelete \<C-A>\<C-B>\"\<CR>", 'tx')
513  call assert_equal('"argdelete bar foo', @:)
514
515  call feedkeys(":argdelete x \<C-A>\<C-B>\"\<CR>", 'tx')
516  call assert_equal('"argdelete x bar foo', @:)
517
518  %argd
519endfunc
520
521" Tests for the :next, :prev, :first, :last, :rewind commands
522func Test_argpos()
523  call Reset_arglist()
524  args a b c d
525  last
526  call assert_equal(3, argidx())
527  call assert_fails('next', 'E165:')
528  prev
529  call assert_equal(2, argidx())
530  Next
531  call assert_equal(1, argidx())
532  first
533  call assert_equal(0, argidx())
534  call assert_fails('prev', 'E164:')
535  3next
536  call assert_equal(3, argidx())
537  rewind
538  call assert_equal(0, argidx())
539  %argd
540endfunc
541
542" Test for autocommand that redefines the argument list, when doing ":all".
543func Test_arglist_autocmd()
544  autocmd BufReadPost Xxx2 next Xxx2 Xxx1
545  call writefile(['test file Xxx1'], 'Xxx1', 'D')
546  call writefile(['test file Xxx2'], 'Xxx2', 'D')
547  call writefile(['test file Xxx3'], 'Xxx3', 'D')
548
549  new
550  " redefine arglist; go to Xxx1
551  next! Xxx1 Xxx2 Xxx3
552  " open window for all args; Reading Xxx2 will try to change the arglist and
553  " that will fail
554  call assert_fails("all", "E1156:")
555  call assert_equal('test file Xxx1', getline(1))
556  wincmd w
557  call assert_equal('test file Xxx2', getline(1))
558  wincmd w
559  call assert_equal('test file Xxx3', getline(1))
560
561  autocmd! BufReadPost Xxx2
562  enew! | only
563  argdelete Xxx*
564  bwipe! Xxx1 Xxx2 Xxx3
565endfunc
566
567func Test_arg_all_expand()
568  call writefile(['test file Xxx1'], 'Xx x', 'D')
569  next notexist Xx\ x runtest.vim
570  call assert_equal('notexist Xx\ x runtest.vim', expand('##'))
571endfunc
572
573func Test_large_arg()
574  " Argument longer or equal to the number of columns used to cause
575  " access to invalid memory.
576  exe 'argadd ' .repeat('x', &columns)
577  args
578endfunc
579
580func Test_argdo()
581  next! Xa.c Xb.c Xc.c
582  new
583
584  let g:bufenter = 0
585  let g:bufleave = 0
586  autocmd BufEnter * let g:bufenter += 1
587  autocmd BufLeave * let g:bufleave += 1
588
589  let l = []
590  argdo call add(l, expand('%'))
591  call assert_equal(['Xa.c', 'Xb.c', 'Xc.c'], l)
592  call assert_equal(3, g:bufenter)
593  call assert_equal(3, g:bufleave)
594
595  let g:bufenter = 0
596  let g:bufleave = 0
597
598  set eventignore=BufEnter,BufLeave
599  let l = []
600  argdo call add(l, expand('%'))
601  call assert_equal(['Xa.c', 'Xb.c', 'Xc.c'], l)
602  call assert_equal(0, g:bufenter)
603  call assert_equal(0, g:bufleave)
604  call assert_equal('BufEnter,BufLeave', &eventignore)
605  set eventignore&
606
607  autocmd! BufEnter
608  autocmd! BufLeave
609  unlet g:bufenter
610  unlet g:bufleave
611  bwipe Xa.c Xb.c Xc.c
612endfunc
613
614" Test for quitting Vim with unedited files in the argument list
615func Test_quit_with_arglist()
616  CheckRunVimInTerminal
617  let buf = RunVimInTerminal('', {'rows': 6})
618  call term_sendkeys(buf, ":set nomore\n")
619  call term_sendkeys(buf, ":args a b c\n")
620  call term_sendkeys(buf, ":quit\n")
621  call TermWait(buf)
622  call WaitForAssert({-> assert_match('^E173:', term_getline(buf, 6))})
623  call StopVimInTerminal(buf)
624
625  " Try :confirm quit with unedited files in arglist
626  let buf = RunVimInTerminal('', {'rows': 6})
627  call term_sendkeys(buf, ":set nomore\n")
628  call term_sendkeys(buf, ":args a b c\n")
629  call term_sendkeys(buf, ":confirm quit\n")
630  call TermWait(buf)
631  call WaitForAssert({-> assert_match('^\[Y\]es, (N)o: *$',
632        \ term_getline(buf, 6))})
633  call term_sendkeys(buf, "N")
634  call TermWait(buf)
635  call term_sendkeys(buf, ":confirm quit\n")
636  call WaitForAssert({-> assert_match('^\[Y\]es, (N)o: *$',
637        \ term_getline(buf, 6))})
638  call term_sendkeys(buf, "Y")
639  call TermWait(buf)
640  call WaitForAssert({-> assert_equal("finished", term_getstatus(buf))})
641  only!
642  " When this test fails, swap files are left behind which breaks subsequent
643  " tests
644  call delete('.a.swp')
645  call delete('.b.swp')
646  call delete('.c.swp')
647endfunc
648
649" Test for ":all" not working when in the cmdline window
650func Test_all_not_allowed_from_cmdwin()
651  throw 'Skipped: Nvim supports cmdwin freedom #40312'
652  au BufEnter * all
653  next x
654  " Use try/catch here, somehow assert_fails() doesn't work on MS-Windows
655  " console.
656  let caught = 'no'
657  try
658    exe ":norm! 7q?apat\<CR>"
659  catch /E11:/
660    let caught = 'yes'
661  endtry
662  call assert_equal('yes', caught)
663  au! BufEnter
664endfunc
665
666func Test_clear_arglist_in_all()
667  n 0 00 000 0000 00000 000000
668  au WinNew 0 n 0
669  call assert_fails("all", "E1156:")
670  au! *
671endfunc
672
673" Test for the :all command
674func Test_all_command()
675  %argdelete
676
677  " :all command should not close windows with files in the argument list,
678  " but can rearrange the windows.
679  args Xargnew1 Xargnew2
680  %bw!
681  edit Xargold1
682  split Xargnew1
683  let Xargnew1_winid = win_getid()
684  split Xargold2
685  split Xargnew2
686  let Xargnew2_winid = win_getid()
687  split Xargold3
688  all
689  call assert_equal(2, winnr('$'))
690  call assert_equal([Xargnew1_winid, Xargnew2_winid],
691        \ [win_getid(1), win_getid(2)])
692  call assert_equal([bufnr('Xargnew1'), bufnr('Xargnew2')],
693        \ [winbufnr(1), winbufnr(2)])
694
695  " :all command should close windows for files which are not in the
696  " argument list in the current tab page.
697  %bw!
698  edit Xargold1
699  split Xargold2
700  tabedit Xargold3
701  split Xargold4
702  tabedit Xargold5
703  tabfirst
704  all
705  call assert_equal(3, tabpagenr('$'))
706  call assert_equal([bufnr('Xargnew1'), bufnr('Xargnew2')], tabpagebuflist(1))
707  call assert_equal([bufnr('Xargold4'), bufnr('Xargold3')], tabpagebuflist(2))
708  call assert_equal([bufnr('Xargold5')], tabpagebuflist(3))
709
710  " :tab all command should close windows for files which are not in the
711  " argument list across all the tab pages.
712  %bw!
713  edit Xargold1
714  split Xargold2
715  tabedit Xargold3
716  split Xargold4
717  tabedit Xargold5
718  tabfirst
719  args Xargnew1 Xargnew2
720  tab all
721  call assert_equal(2, tabpagenr('$'))
722  call assert_equal([bufnr('Xargnew1')], tabpagebuflist(1))
723  call assert_equal([bufnr('Xargnew2')], tabpagebuflist(2))
724
725  " If a count is specified, then :all should open only that many windows.
726  %bw!
727  args Xargnew1 Xargnew2 Xargnew3 Xargnew4 Xargnew5
728  all 3
729  call assert_equal(3, winnr('$'))
730  call assert_equal([bufnr('Xargnew1'), bufnr('Xargnew2'), bufnr('Xargnew3')],
731        \ [winbufnr(1), winbufnr(2), winbufnr(3)])
732
733  " The :all command should not open more than 'tabpagemax' tab pages.
734  " If there are more files, then they should be opened in the last tab page.
735  %bw!
736  set tabpagemax=3
737  tab all
738  call assert_equal(3, tabpagenr('$'))
739  call assert_equal([bufnr('Xargnew1')], tabpagebuflist(1))
740  call assert_equal([bufnr('Xargnew2')], tabpagebuflist(2))
741  call assert_equal([bufnr('Xargnew3'), bufnr('Xargnew4'), bufnr('Xargnew5')],
742        \ tabpagebuflist(3))
743  set tabpagemax&
744
745  " Without the 'hidden' option, modified buffers should not be closed.
746  args Xargnew1 Xargnew2
747  %bw!
748  edit Xargtemp1
749  call setline(1, 'temp buffer 1')
750  split Xargtemp2
751  call setline(1, 'temp buffer 2')
752  all
753  call assert_equal(4, winnr('$'))
754  call assert_equal([bufnr('Xargtemp2'), bufnr('Xargtemp1'), bufnr('Xargnew1'),
755        \ bufnr('Xargnew2')],
756        \ [winbufnr(1), winbufnr(2), winbufnr(3), winbufnr(4)])
757
758  " With the 'hidden' option set, both modified and unmodified buffers in
759  " closed windows should be hidden.
760  set hidden
761  all
762  call assert_equal(2, winnr('$'))
763  call assert_equal([bufnr('Xargnew1'), bufnr('Xargnew2')],
764        \ [winbufnr(1), winbufnr(2)])
765  call assert_equal([1, 1, 0, 0], [getbufinfo('Xargtemp1')[0].hidden,
766        \ getbufinfo('Xargtemp2')[0].hidden,
767        \ getbufinfo('Xargnew1')[0].hidden,
768        \ getbufinfo('Xargnew2')[0].hidden])
769  set nohidden
770
771  " When 'winheight' is set to a large value, :all should open only one
772  " window.
773  args Xargnew1 Xargnew2 Xargnew3 Xargnew4 Xargnew5
774  %bw!
775  set winheight=9999
776  call assert_fails('all', 'E36:')
777  call assert_equal([1, bufnr('Xargnew1')], [winnr('$'), winbufnr(1)])
778  set winheight&
779
780  " When 'winwidth' is set to a large value, :vert all should open only one
781  " window.
782  %bw!
783  set winwidth=9999
784  call assert_fails('vert all', 'E36:')
785  call assert_equal([1, bufnr('Xargnew1')], [winnr('$'), winbufnr(1)])
786  set winwidth&
787
788  " empty argument list tests
789  %bw!
790  %argdelete
791  call assert_equal('', execute('args'))
792  all
793  call assert_equal(1, winnr('$'))
794
795  %argdelete
796  %bw!
797endfunc
798
799" Test for deleting buffer when creating an arglist. This was accessing freed
800" memory
801func Test_crash_arglist_uaf()
802  "%argdelete
803  new one
804  au BufAdd XUAFlocal :bw
805  arglocal XUAFlocal
806  au! BufAdd
807  bw! XUAFlocal
808
809  au BufAdd XUAFlocal2 :bw
810  new two
811  new three
812  arglocal
813  argadd XUAFlocal2 Xfoobar
814  bw! XUAFlocal2
815  bw! two
816
817  au! BufAdd
818endfunc
819
820" This was using freed memory again
821func Test_crash_arglist_uaf2()
822  new
823  au BufAdd XUAFlocal :bw
824  arglocal XUAFlocal
825  redraw!
826  put ='abc'
827  2#
828  au! BufAdd
829endfunc
830
831func Test_arglist_w_locked_unlock()
832  au BufAdd * split
833
834  args a
835  call assert_equal(2, winnr('$'))
836  wincmd p
837  quit
838  call assert_equal(1, winnr('$'))
839
840  argedit b
841  call assert_equal(2, winnr('$'))
842  wincmd p
843  quit
844  call assert_equal(1, winnr('$'))
845
846  %argd
847  %bw!
848  au! BufAdd
849endfunc
850
851" vim: shiftwidth=2 sts=2 expandtab