test_arglist.vim 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. " Test argument list commands
  2. source check.vim
  3. source shared.vim
  4. source term_util.vim
  5. func Reset_arglist()
  6. args a | %argd
  7. endfunc
  8. func Test_argidx()
  9. args a b c
  10. last
  11. call assert_equal(2, argidx())
  12. %argdelete
  13. call assert_equal(0, argidx())
  14. " doing it again doesn't result in an error
  15. %argdelete
  16. call assert_equal(0, argidx())
  17. call assert_fails('2argdelete', 'E16:')
  18. args a b c
  19. call assert_equal(0, argidx())
  20. next
  21. call assert_equal(1, argidx())
  22. next
  23. call assert_equal(2, argidx())
  24. 1argdelete
  25. call assert_equal(1, argidx())
  26. 1argdelete
  27. call assert_equal(0, argidx())
  28. 1argdelete
  29. call assert_equal(0, argidx())
  30. endfunc
  31. func Test_argadd()
  32. call Reset_arglist()
  33. %argdelete
  34. argadd a b c
  35. call assert_equal(0, argidx())
  36. %argdelete
  37. argadd a
  38. call assert_equal(0, argidx())
  39. argadd b c d
  40. call assert_equal(0, argidx())
  41. call Init_abc()
  42. argadd x
  43. call Assert_argc(['a', 'b', 'x', 'c'])
  44. call assert_equal(1, argidx())
  45. call Init_abc()
  46. 0argadd x
  47. call Assert_argc(['x', 'a', 'b', 'c'])
  48. call assert_equal(2, argidx())
  49. call Init_abc()
  50. 1argadd x
  51. call Assert_argc(['a', 'x', 'b', 'c'])
  52. call assert_equal(2, argidx())
  53. call Init_abc()
  54. $argadd x
  55. call Assert_argc(['a', 'b', 'c', 'x'])
  56. call assert_equal(1, argidx())
  57. call Init_abc()
  58. $argadd x
  59. +2argadd y
  60. call Assert_argc(['a', 'b', 'c', 'x', 'y'])
  61. call assert_equal(1, argidx())
  62. %argd
  63. edit d
  64. arga
  65. call assert_equal(1, len(argv()))
  66. call assert_equal('d', get(argv(), 0, ''))
  67. %argd
  68. edit some\ file
  69. arga
  70. call assert_equal(1, len(argv()))
  71. call assert_equal('some file', get(argv(), 0, ''))
  72. %argd
  73. new
  74. arga
  75. call assert_equal(0, len(argv()))
  76. if has('unix')
  77. call assert_fails('argadd `Xdoes_not_exist`', 'E479:')
  78. endif
  79. endfunc
  80. func Test_argadd_empty_curbuf()
  81. new
  82. let curbuf = bufnr('%')
  83. call writefile(['test', 'Xargadd'], 'Xargadd', 'D')
  84. " must not re-use the current buffer.
  85. argadd Xargadd
  86. call assert_equal(curbuf, bufnr('%'))
  87. call assert_equal('', bufname('%'))
  88. call assert_equal(1, '$'->line())
  89. rew
  90. call assert_notequal(curbuf, '%'->bufnr())
  91. call assert_equal('Xargadd', '%'->bufname())
  92. call assert_equal(2, line('$'))
  93. %argd
  94. bwipe!
  95. endfunc
  96. func Init_abc()
  97. args a b c
  98. next
  99. endfunc
  100. func Assert_argc(l)
  101. call assert_equal(len(a:l), argc())
  102. let i = 0
  103. while i < len(a:l) && i < argc()
  104. call assert_equal(a:l[i], argv(i))
  105. let i += 1
  106. endwhile
  107. endfunc
  108. " Test for [count]argument and [count]argdelete commands
  109. " Ported from the test_argument_count.in test script
  110. func Test_argument()
  111. call Reset_arglist()
  112. let save_hidden = &hidden
  113. set hidden
  114. let g:buffers = []
  115. augroup TEST
  116. au BufEnter * call add(buffers, expand('%:t'))
  117. augroup END
  118. argadd a b c d
  119. $argu
  120. $-argu
  121. -argu
  122. 1argu
  123. +2argu
  124. augroup TEST
  125. au!
  126. augroup END
  127. call assert_equal(['d', 'c', 'b', 'a', 'c'], g:buffers)
  128. call assert_equal("\na b [c] d ", execute(':args'))
  129. .argd
  130. call assert_equal(['a', 'b', 'd'], argv())
  131. -argd
  132. call assert_equal(['a', 'd'], argv())
  133. $argd
  134. call assert_equal(['a'], argv())
  135. 1arga c
  136. 1arga b
  137. $argu
  138. $arga x
  139. call assert_equal(['a', 'b', 'c', 'x'], argv())
  140. 0arga y
  141. call assert_equal(['y', 'a', 'b', 'c', 'x'], argv())
  142. %argd
  143. call assert_equal([], argv())
  144. arga a b c d e f
  145. 2,$-argd
  146. call assert_equal(['a', 'f'], argv())
  147. let &hidden = save_hidden
  148. let save_columns = &columns
  149. let &columns = 79
  150. try
  151. exe 'args ' .. join(range(1, 81))
  152. call assert_equal(join([
  153. \ '',
  154. \ '[1] 6 11 16 21 26 31 36 41 46 51 56 61 66 71 76 81 ',
  155. \ '2 7 12 17 22 27 32 37 42 47 52 57 62 67 72 77 ',
  156. \ '3 8 13 18 23 28 33 38 43 48 53 58 63 68 73 78 ',
  157. \ '4 9 14 19 24 29 34 39 44 49 54 59 64 69 74 79 ',
  158. \ '5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 ',
  159. \ ], "\n"),
  160. \ execute('args'))
  161. " No trailing newline with one item per row.
  162. let long_arg = repeat('X', 81)
  163. exe 'args ' .. long_arg
  164. call assert_equal("\n[".long_arg.']', execute('args'))
  165. finally
  166. let &columns = save_columns
  167. endtry
  168. " Setting argument list should fail when the current buffer has unsaved
  169. " changes
  170. %argd
  171. enew!
  172. set modified
  173. call assert_fails('args x y z', 'E37:')
  174. args! x y z
  175. call assert_equal(['x', 'y', 'z'], argv())
  176. call assert_equal('x', expand('%:t'))
  177. last | enew | argu
  178. call assert_equal('z', expand('%:t'))
  179. %argdelete
  180. call assert_fails('argument', 'E163:')
  181. endfunc
  182. func Test_list_arguments()
  183. " Clean the argument list
  184. arga a | %argd
  185. " four args half the screen width makes two lines with two columns
  186. let aarg = repeat('a', &columns / 2 - 4)
  187. let barg = repeat('b', &columns / 2 - 4)
  188. let carg = repeat('c', &columns / 2 - 4)
  189. let darg = repeat('d', &columns / 2 - 4)
  190. exe 'argadd ' aarg barg carg darg
  191. redir => result
  192. args
  193. redir END
  194. call assert_match('\[' . aarg . '] \+' . carg . '\n' . barg . ' \+' . darg, trim(result))
  195. " if one arg is longer than half the screen make one column
  196. exe 'argdel' aarg
  197. let aarg = repeat('a', &columns / 2 + 2)
  198. exe '0argadd' aarg
  199. redir => result
  200. args
  201. redir END
  202. call assert_match(aarg . '\n\[' . barg . ']\n' . carg . '\n' . darg, trim(result))
  203. %argdelete
  204. endfunc
  205. func Test_args_with_quote()
  206. " Only on Unix can a file name include a double quote.
  207. if has('unix')
  208. args \"foobar
  209. call assert_equal('"foobar', argv(0))
  210. %argdelete
  211. endif
  212. endfunc
  213. " Test for 0argadd and 0argedit
  214. " Ported from the test_argument_0count.in test script
  215. func Test_zero_argadd()
  216. call Reset_arglist()
  217. arga a b c d
  218. 2argu
  219. 0arga added
  220. call assert_equal(['added', 'a', 'b', 'c', 'd'], argv())
  221. 2argu
  222. arga third
  223. call assert_equal(['added', 'a', 'third', 'b', 'c', 'd'], argv())
  224. %argd
  225. arga a b c d
  226. 2argu
  227. 0arge edited
  228. call assert_equal(['edited', 'a', 'b', 'c', 'd'], argv())
  229. 2argu
  230. arga third
  231. call assert_equal(['edited', 'a', 'third', 'b', 'c', 'd'], argv())
  232. 2argu
  233. argedit file\ with\ spaces another file
  234. call assert_equal(['edited', 'a', 'file with spaces', 'another', 'file', 'third', 'b', 'c', 'd'], argv())
  235. call assert_equal('file with spaces', expand('%'))
  236. endfunc
  237. " Test for argc()
  238. func Test_argc()
  239. call Reset_arglist()
  240. call assert_equal(0, argc())
  241. argadd a b
  242. call assert_equal(2, argc())
  243. endfunc
  244. " Test for arglistid()
  245. func Test_arglistid()
  246. call Reset_arglist()
  247. arga a b
  248. call assert_equal(0, arglistid())
  249. split
  250. arglocal
  251. call assert_equal(1, arglistid())
  252. tabnew | tabfirst
  253. call assert_equal(0, arglistid(2))
  254. call assert_equal(1, arglistid(1, 1))
  255. call assert_equal(0, arglistid(2, 1))
  256. call assert_equal(1, arglistid(1, 2))
  257. tabonly | only | enew!
  258. argglobal
  259. call assert_equal(0, arglistid())
  260. endfunc
  261. " Tests for argv() and argc()
  262. func Test_argv()
  263. call Reset_arglist()
  264. call assert_equal([], argv())
  265. call assert_equal("", argv(2))
  266. call assert_equal(0, argc())
  267. argadd a b c d
  268. call assert_equal(4, argc())
  269. call assert_equal('c', argv(2))
  270. let w1_id = win_getid()
  271. split
  272. let w2_id = win_getid()
  273. arglocal
  274. args e f g
  275. tabnew
  276. let w3_id = win_getid()
  277. split
  278. let w4_id = win_getid()
  279. argglobal
  280. tabfirst
  281. call assert_equal(4, argc(w1_id))
  282. call assert_equal('b', argv(1, w1_id))
  283. call assert_equal(['a', 'b', 'c', 'd'], argv(-1, w1_id))
  284. call assert_equal(3, argc(w2_id))
  285. call assert_equal('f', argv(1, w2_id))
  286. call assert_equal(['e', 'f', 'g'], argv(-1, w2_id))
  287. call assert_equal(3, argc(w3_id))
  288. call assert_equal('e', argv(0, w3_id))
  289. call assert_equal(['e', 'f', 'g'], argv(-1, w3_id))
  290. call assert_equal(4, argc(w4_id))
  291. call assert_equal('c', argv(2, w4_id))
  292. call assert_equal(['a', 'b', 'c', 'd'], argv(-1, w4_id))
  293. call assert_equal(4, argc(-1))
  294. call assert_equal(3, argc())
  295. call assert_equal('d', argv(3, -1))
  296. call assert_equal(['a', 'b', 'c', 'd'], argv(-1, -1))
  297. tabonly | only | enew!
  298. " Negative test cases
  299. call assert_equal(-1, argc(100))
  300. call assert_equal('', argv(1, 100))
  301. call assert_equal([], argv(-1, 100))
  302. call assert_equal('', argv(10, -1))
  303. %argdelete
  304. endfunc
  305. " Test for the :argedit command
  306. func Test_argedit()
  307. call Reset_arglist()
  308. argedit a
  309. call assert_equal(['a'], argv())
  310. call assert_equal('a', expand('%:t'))
  311. argedit b
  312. call assert_equal(['a', 'b'], argv())
  313. call assert_equal('b', expand('%:t'))
  314. argedit a
  315. call assert_equal(['a', 'b', 'a'], argv())
  316. call assert_equal('a', expand('%:t'))
  317. " When file name case is ignored, an existing buffer with only case
  318. " difference is re-used.
  319. argedit C D
  320. call assert_equal('C', expand('%:t'))
  321. call assert_equal(['a', 'b', 'a', 'C', 'D'], argv())
  322. argedit c
  323. if has('fname_case')
  324. call assert_equal(['a', 'b', 'a', 'C', 'c', 'D'], argv())
  325. else
  326. call assert_equal(['a', 'b', 'a', 'C', 'C', 'D'], argv())
  327. endif
  328. 0argedit x
  329. if has('fname_case')
  330. call assert_equal(['x', 'a', 'b', 'a', 'C', 'c', 'D'], argv())
  331. else
  332. call assert_equal(['x', 'a', 'b', 'a', 'C', 'C', 'D'], argv())
  333. endif
  334. enew! | set modified
  335. call assert_fails('argedit y', 'E37:')
  336. argedit! y
  337. if has('fname_case')
  338. call assert_equal(['x', 'y', 'y', 'a', 'b', 'a', 'C', 'c', 'D'], argv())
  339. else
  340. call assert_equal(['x', 'y', 'y', 'a', 'b', 'a', 'C', 'C', 'D'], argv())
  341. endif
  342. %argd
  343. bwipe! C
  344. bwipe! D
  345. " :argedit reuses the current buffer if it is empty
  346. %argd
  347. " make sure to use a new buffer number for x when it is loaded
  348. bw! x
  349. new
  350. let a = bufnr()
  351. argedit x
  352. call assert_equal(a, bufnr())
  353. call assert_equal('x', bufname())
  354. %argd
  355. bw! x
  356. endfunc
  357. " Test for the :argdedupe command
  358. func Test_argdedupe()
  359. call Reset_arglist()
  360. argdedupe
  361. call assert_equal([], argv())
  362. args a a a aa b b a b aa
  363. argdedupe
  364. call assert_equal(['a', 'aa', 'b'], argv())
  365. args a b c
  366. argdedupe
  367. call assert_equal(['a', 'b', 'c'], argv())
  368. args a
  369. argdedupe
  370. call assert_equal(['a'], argv())
  371. args a A b B
  372. argdedupe
  373. if has('fname_case')
  374. call assert_equal(['a', 'A', 'b', 'B'], argv())
  375. else
  376. call assert_equal(['a', 'b'], argv())
  377. endif
  378. args a b a c a b
  379. last
  380. argdedupe
  381. next
  382. call assert_equal('c', expand('%:t'))
  383. args a ./a
  384. argdedupe
  385. call assert_equal(['a'], argv())
  386. %argd
  387. endfunc
  388. " Test for the :argdelete command
  389. func Test_argdelete()
  390. call Reset_arglist()
  391. args aa a aaa b bb
  392. argdelete a*
  393. call assert_equal(['b', 'bb'], argv())
  394. call assert_equal('aa', expand('%:t'))
  395. last
  396. argdelete %
  397. call assert_equal(['b'], argv())
  398. call assert_fails('argdelete', 'E610:')
  399. call assert_fails('1,100argdelete', 'E16:')
  400. call assert_fails('argdel /\)/', 'E55:')
  401. call assert_fails('1argdel 1', 'E474:')
  402. call Reset_arglist()
  403. args a b c d
  404. next
  405. argdel
  406. call Assert_argc(['a', 'c', 'd'])
  407. %argdel
  408. call assert_fails('argdel does_not_exist', 'E480:')
  409. endfunc
  410. func Test_argdelete_completion()
  411. args foo bar
  412. call feedkeys(":argdelete \<C-A>\<C-B>\"\<CR>", 'tx')
  413. call assert_equal('"argdelete bar foo', @:)
  414. call feedkeys(":argdelete x \<C-A>\<C-B>\"\<CR>", 'tx')
  415. call assert_equal('"argdelete x bar foo', @:)
  416. %argd
  417. endfunc
  418. " Tests for the :next, :prev, :first, :last, :rewind commands
  419. func Test_argpos()
  420. call Reset_arglist()
  421. args a b c d
  422. last
  423. call assert_equal(3, argidx())
  424. call assert_fails('next', 'E165:')
  425. prev
  426. call assert_equal(2, argidx())
  427. Next
  428. call assert_equal(1, argidx())
  429. first
  430. call assert_equal(0, argidx())
  431. call assert_fails('prev', 'E164:')
  432. 3next
  433. call assert_equal(3, argidx())
  434. rewind
  435. call assert_equal(0, argidx())
  436. %argd
  437. endfunc
  438. " Test for autocommand that redefines the argument list, when doing ":all".
  439. func Test_arglist_autocmd()
  440. autocmd BufReadPost Xxx2 next Xxx2 Xxx1
  441. call writefile(['test file Xxx1'], 'Xxx1', 'D')
  442. call writefile(['test file Xxx2'], 'Xxx2', 'D')
  443. call writefile(['test file Xxx3'], 'Xxx3', 'D')
  444. new
  445. " redefine arglist; go to Xxx1
  446. next! Xxx1 Xxx2 Xxx3
  447. " open window for all args; Reading Xxx2 will try to change the arglist and
  448. " that will fail
  449. call assert_fails("all", "E1156:")
  450. call assert_equal('test file Xxx1', getline(1))
  451. wincmd w
  452. call assert_equal('test file Xxx2', getline(1))
  453. wincmd w
  454. call assert_equal('test file Xxx3', getline(1))
  455. autocmd! BufReadPost Xxx2
  456. enew! | only
  457. argdelete Xxx*
  458. bwipe! Xxx1 Xxx2 Xxx3
  459. endfunc
  460. func Test_arg_all_expand()
  461. call writefile(['test file Xxx1'], 'Xx x', 'D')
  462. next notexist Xx\ x runtest.vim
  463. call assert_equal('notexist Xx\ x runtest.vim', expand('##'))
  464. endfunc
  465. func Test_large_arg()
  466. " Argument longer or equal to the number of columns used to cause
  467. " access to invalid memory.
  468. exe 'argadd ' .repeat('x', &columns)
  469. args
  470. endfunc
  471. func Test_argdo()
  472. next! Xa.c Xb.c Xc.c
  473. new
  474. let l = []
  475. argdo call add(l, expand('%'))
  476. call assert_equal(['Xa.c', 'Xb.c', 'Xc.c'], l)
  477. bwipe Xa.c Xb.c Xc.c
  478. endfunc
  479. " Test for quitting Vim with unedited files in the argument list
  480. func Test_quit_with_arglist()
  481. CheckRunVimInTerminal
  482. let buf = RunVimInTerminal('', {'rows': 6})
  483. call term_sendkeys(buf, ":set nomore\n")
  484. call term_sendkeys(buf, ":args a b c\n")
  485. call term_sendkeys(buf, ":quit\n")
  486. call TermWait(buf)
  487. call WaitForAssert({-> assert_match('^E173:', term_getline(buf, 6))})
  488. call StopVimInTerminal(buf)
  489. " Try :confirm quit with unedited files in arglist
  490. let buf = RunVimInTerminal('', {'rows': 6})
  491. call term_sendkeys(buf, ":set nomore\n")
  492. call term_sendkeys(buf, ":args a b c\n")
  493. call term_sendkeys(buf, ":confirm quit\n")
  494. call TermWait(buf)
  495. call WaitForAssert({-> assert_match('^\[Y\]es, (N)o: *$',
  496. \ term_getline(buf, 6))})
  497. call term_sendkeys(buf, "N")
  498. call TermWait(buf)
  499. call term_sendkeys(buf, ":confirm quit\n")
  500. call WaitForAssert({-> assert_match('^\[Y\]es, (N)o: *$',
  501. \ term_getline(buf, 6))})
  502. call term_sendkeys(buf, "Y")
  503. call TermWait(buf)
  504. call WaitForAssert({-> assert_equal("finished", term_getstatus(buf))})
  505. only!
  506. " When this test fails, swap files are left behind which breaks subsequent
  507. " tests
  508. call delete('.a.swp')
  509. call delete('.b.swp')
  510. call delete('.c.swp')
  511. endfunc
  512. " Test for ":all" not working when in the cmdline window
  513. func Test_all_not_allowed_from_cmdwin()
  514. au BufEnter * all
  515. next x
  516. " Use try/catch here, somehow assert_fails() doesn't work on MS-Windows
  517. " console.
  518. let caught = 'no'
  519. try
  520. exe ":norm! 7q?apat\<CR>"
  521. catch /E11:/
  522. let caught = 'yes'
  523. endtry
  524. call assert_equal('yes', caught)
  525. au! BufEnter
  526. endfunc
  527. func Test_clear_arglist_in_all()
  528. n 0 00 000 0000 00000 000000
  529. au WinNew 0 n 0
  530. call assert_fails("all", "E1156")
  531. au! *
  532. endfunc
  533. " Test for the :all command
  534. func Test_all_command()
  535. %argdelete
  536. " :all command should not close windows with files in the argument list,
  537. " but can rearrange the windows.
  538. args Xargnew1 Xargnew2
  539. %bw!
  540. edit Xargold1
  541. split Xargnew1
  542. let Xargnew1_winid = win_getid()
  543. split Xargold2
  544. split Xargnew2
  545. let Xargnew2_winid = win_getid()
  546. split Xargold3
  547. all
  548. call assert_equal(2, winnr('$'))
  549. call assert_equal([Xargnew1_winid, Xargnew2_winid],
  550. \ [win_getid(1), win_getid(2)])
  551. call assert_equal([bufnr('Xargnew1'), bufnr('Xargnew2')],
  552. \ [winbufnr(1), winbufnr(2)])
  553. " :all command should close windows for files which are not in the
  554. " argument list in the current tab page.
  555. %bw!
  556. edit Xargold1
  557. split Xargold2
  558. tabedit Xargold3
  559. split Xargold4
  560. tabedit Xargold5
  561. tabfirst
  562. all
  563. call assert_equal(3, tabpagenr('$'))
  564. call assert_equal([bufnr('Xargnew1'), bufnr('Xargnew2')], tabpagebuflist(1))
  565. call assert_equal([bufnr('Xargold4'), bufnr('Xargold3')], tabpagebuflist(2))
  566. call assert_equal([bufnr('Xargold5')], tabpagebuflist(3))
  567. " :tab all command should close windows for files which are not in the
  568. " argument list across all the tab pages.
  569. %bw!
  570. edit Xargold1
  571. split Xargold2
  572. tabedit Xargold3
  573. split Xargold4
  574. tabedit Xargold5
  575. tabfirst
  576. args Xargnew1 Xargnew2
  577. tab all
  578. call assert_equal(2, tabpagenr('$'))
  579. call assert_equal([bufnr('Xargnew1')], tabpagebuflist(1))
  580. call assert_equal([bufnr('Xargnew2')], tabpagebuflist(2))
  581. " If a count is specified, then :all should open only that many windows.
  582. %bw!
  583. args Xargnew1 Xargnew2 Xargnew3 Xargnew4 Xargnew5
  584. all 3
  585. call assert_equal(3, winnr('$'))
  586. call assert_equal([bufnr('Xargnew1'), bufnr('Xargnew2'), bufnr('Xargnew3')],
  587. \ [winbufnr(1), winbufnr(2), winbufnr(3)])
  588. " The :all command should not open more than 'tabpagemax' tab pages.
  589. " If there are more files, then they should be opened in the last tab page.
  590. %bw!
  591. set tabpagemax=3
  592. tab all
  593. call assert_equal(3, tabpagenr('$'))
  594. call assert_equal([bufnr('Xargnew1')], tabpagebuflist(1))
  595. call assert_equal([bufnr('Xargnew2')], tabpagebuflist(2))
  596. call assert_equal([bufnr('Xargnew3'), bufnr('Xargnew4'), bufnr('Xargnew5')],
  597. \ tabpagebuflist(3))
  598. set tabpagemax&
  599. " Without the 'hidden' option, modified buffers should not be closed.
  600. args Xargnew1 Xargnew2
  601. %bw!
  602. edit Xargtemp1
  603. call setline(1, 'temp buffer 1')
  604. split Xargtemp2
  605. call setline(1, 'temp buffer 2')
  606. all
  607. call assert_equal(4, winnr('$'))
  608. call assert_equal([bufnr('Xargtemp2'), bufnr('Xargtemp1'), bufnr('Xargnew1'),
  609. \ bufnr('Xargnew2')],
  610. \ [winbufnr(1), winbufnr(2), winbufnr(3), winbufnr(4)])
  611. " With the 'hidden' option set, both modified and unmodified buffers in
  612. " closed windows should be hidden.
  613. set hidden
  614. all
  615. call assert_equal(2, winnr('$'))
  616. call assert_equal([bufnr('Xargnew1'), bufnr('Xargnew2')],
  617. \ [winbufnr(1), winbufnr(2)])
  618. call assert_equal([1, 1, 0, 0], [getbufinfo('Xargtemp1')[0].hidden,
  619. \ getbufinfo('Xargtemp2')[0].hidden,
  620. \ getbufinfo('Xargnew1')[0].hidden,
  621. \ getbufinfo('Xargnew2')[0].hidden])
  622. set nohidden
  623. " When 'winheight' is set to a large value, :all should open only one
  624. " window.
  625. args Xargnew1 Xargnew2 Xargnew3 Xargnew4 Xargnew5
  626. %bw!
  627. set winheight=9999
  628. call assert_fails('all', 'E36:')
  629. call assert_equal([1, bufnr('Xargnew1')], [winnr('$'), winbufnr(1)])
  630. set winheight&
  631. " When 'winwidth' is set to a large value, :vert all should open only one
  632. " window.
  633. %bw!
  634. set winwidth=9999
  635. call assert_fails('vert all', 'E36:')
  636. call assert_equal([1, bufnr('Xargnew1')], [winnr('$'), winbufnr(1)])
  637. set winwidth&
  638. " empty argument list tests
  639. %bw!
  640. %argdelete
  641. call assert_equal('', execute('args'))
  642. all
  643. call assert_equal(1, winnr('$'))
  644. %argdelete
  645. %bw!
  646. endfunc
  647. " Test for deleting buffer when creating an arglist. This was accessing freed
  648. " memory
  649. func Test_crash_arglist_uaf()
  650. "%argdelete
  651. new one
  652. au BufAdd XUAFlocal :bw
  653. "call assert_fails(':arglocal XUAFlocal', 'E163:')
  654. arglocal XUAFlocal
  655. au! BufAdd
  656. bw! XUAFlocal
  657. au BufAdd XUAFlocal2 :bw
  658. new two
  659. new three
  660. arglocal
  661. argadd XUAFlocal2 Xfoobar
  662. bw! XUAFlocal2
  663. bw! two
  664. au! BufAdd
  665. endfunc
  666. " vim: shiftwidth=2 sts=2 expandtab