tabclose_spec.lua 3.3 KB

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