tabclose_spec.lua 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local clear, eq = n.clear, t.eq
  4. local api = n.api
  5. local command = n.command
  6. describe('TabClosed', function()
  7. before_each(clear)
  8. describe('au TabClosed', function()
  9. describe('with * as <afile>', function()
  10. it('matches when closing any tab', function()
  11. command(
  12. 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()'
  13. )
  14. repeat
  15. command('tabnew')
  16. until api.nvim_eval('tabpagenr()') == 6 -- current tab is now 6
  17. eq('tabclosed:6:6:5', api.nvim_exec('tabclose', true)) -- close last 6, current tab is now 5
  18. eq('tabclosed:5:5:4', api.nvim_exec('close', true)) -- close last window on tab, closes tab
  19. eq('tabclosed:2:2:3', api.nvim_exec('2tabclose', true)) -- close tab 2, current tab is now 3
  20. eq('tabclosed:1:1:2\ntabclosed:1:1:1', api.nvim_exec('tabonly', true)) -- close tabs 1 and 2
  21. end)
  22. it('is triggered when closing a window via bdelete from another tab', function()
  23. command(
  24. 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()'
  25. )
  26. command('1tabedit Xtestfile')
  27. command('1tabedit Xtestfile')
  28. command('normal! 1gt')
  29. eq({ 1, 3 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]'))
  30. eq('tabclosed:2:2:1\ntabclosed:2:2:1', api.nvim_exec('bdelete Xtestfile', true))
  31. eq({ 1, 1 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]'))
  32. end)
  33. it('is triggered when closing a window via bdelete from current tab', function()
  34. command(
  35. 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()'
  36. )
  37. command('file Xtestfile1')
  38. command('1tabedit Xtestfile2')
  39. command('1tabedit Xtestfile2')
  40. -- Only one tab is closed, and the alternate file is used for the other.
  41. eq({ 2, 3 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]'))
  42. eq('tabclosed:2:2:2', api.nvim_exec('bdelete Xtestfile2', true))
  43. eq('Xtestfile1', api.nvim_eval('bufname("")'))
  44. end)
  45. end)
  46. describe('with NR as <afile>', function()
  47. it('matches when closing a tab whose index is NR', function()
  48. command(
  49. 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()'
  50. )
  51. command('au! TabClosed 2 echom "tabclosed:match"')
  52. repeat
  53. command('tabnew')
  54. until api.nvim_eval('tabpagenr()') == 7 -- current tab is now 7
  55. -- sanity check, we shouldn't match on tabs with numbers other than 2
  56. eq('tabclosed:7:7:6', api.nvim_exec('tabclose', true))
  57. -- close tab page 2, current tab is now 5
  58. eq('tabclosed:2:2:5\ntabclosed:match', api.nvim_exec('2tabclose', true))
  59. end)
  60. end)
  61. describe('with close', function()
  62. it('is triggered', function()
  63. command(
  64. 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()'
  65. )
  66. command('tabedit Xtestfile')
  67. eq({ 2, 2 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]'))
  68. eq('tabclosed:2:2:1', api.nvim_exec('close', true))
  69. eq({ 1, 1 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]'))
  70. end)
  71. end)
  72. end)
  73. end)