tabpage_spec.lua 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local Screen = require('test.functional.ui.screen')
  4. local clear = n.clear
  5. local command = n.command
  6. local eq = t.eq
  7. local neq = t.neq
  8. local feed = n.feed
  9. local eval = n.eval
  10. local exec = n.exec
  11. local fn = n.fn
  12. local api = n.api
  13. local curwin = n.api.nvim_get_current_win
  14. local assert_alive = n.assert_alive
  15. describe('tabpage', function()
  16. before_each(clear)
  17. it('advances to the next page via <C-W>gt', function()
  18. -- add some tabpages
  19. command('tabnew')
  20. command('tabnew')
  21. command('tabnew')
  22. eq(4, eval('tabpagenr()'))
  23. feed('<C-W>gt')
  24. eq(1, eval('tabpagenr()'))
  25. end)
  26. it('retreats to the previous page via <C-W>gT', function()
  27. -- add some tabpages
  28. command('tabnew')
  29. command('tabnew')
  30. command('tabnew')
  31. eq(4, eval('tabpagenr()'))
  32. feed('<C-W>gT')
  33. eq(3, eval('tabpagenr()'))
  34. end)
  35. it('does not crash or loop 999 times if BufWipeout autocommand switches window #17868', function()
  36. exec([[
  37. tabedit
  38. let s:window_id = win_getid()
  39. botright new
  40. setlocal bufhidden=wipe
  41. let g:win_closed = 0
  42. autocmd WinClosed * let g:win_closed += 1
  43. autocmd BufWipeout <buffer> call win_gotoid(s:window_id)
  44. tabprevious
  45. +tabclose
  46. ]])
  47. neq(999, eval('g:win_closed'))
  48. end)
  49. it('no segfault with strange WinClosed autocommand #20290', function()
  50. pcall(
  51. exec,
  52. [[
  53. set nohidden
  54. edit Xa
  55. split Xb
  56. tab split
  57. new
  58. autocmd WinClosed * tabprev | bwipe!
  59. close
  60. ]]
  61. )
  62. assert_alive()
  63. end)
  64. it('nvim_win_close and nvim_win_hide update tabline #20285', function()
  65. eq(1, #api.nvim_list_tabpages())
  66. eq({ 1, 1 }, fn.win_screenpos(0))
  67. local win1 = curwin()
  68. command('tabnew')
  69. eq(2, #api.nvim_list_tabpages())
  70. eq({ 2, 1 }, fn.win_screenpos(0))
  71. local win2 = curwin()
  72. api.nvim_win_close(win1, true)
  73. eq(win2, curwin())
  74. eq(1, #api.nvim_list_tabpages())
  75. eq({ 1, 1 }, fn.win_screenpos(0))
  76. command('tabnew')
  77. eq(2, #api.nvim_list_tabpages())
  78. eq({ 2, 1 }, fn.win_screenpos(0))
  79. local win3 = curwin()
  80. api.nvim_win_hide(win2)
  81. eq(win3, curwin())
  82. eq(1, #api.nvim_list_tabpages())
  83. eq({ 1, 1 }, fn.win_screenpos(0))
  84. end)
  85. it('switching tabpage after setting laststatus=3 #19591', function()
  86. local screen = Screen.new(40, 8)
  87. screen:add_extra_attr_ids {
  88. [100] = { bold = true, foreground = Screen.colors.Fuchsia },
  89. }
  90. command('tabnew')
  91. command('tabprev')
  92. command('set laststatus=3')
  93. command('tabnext')
  94. feed('<C-G>')
  95. screen:expect([[
  96. {24: [No Name] }{5: [No Name] }{2: }{24:X}|
  97. ^ |
  98. {1:~ }|*4
  99. {3:[No Name] }|
  100. "[No Name]" --No lines in buffer-- |
  101. ]])
  102. command('vnew')
  103. screen:expect([[
  104. {24: [No Name] }{5: }{100:2}{5: [No Name] }{2: }{24:X}|
  105. ^ │ |
  106. {1:~ }│{1:~ }|*4
  107. {3:[No Name] }|
  108. "[No Name]" --No lines in buffer-- |
  109. ]])
  110. end)
  111. it(':tabmove handles modifiers and addr', function()
  112. command('tabnew | tabnew | tabnew')
  113. eq(4, fn.nvim_tabpage_get_number(0))
  114. command(' silent :keepalt :: ::: silent! - tabmove')
  115. eq(3, fn.nvim_tabpage_get_number(0))
  116. command(' silent :keepalt :: ::: silent! -2 tabmove')
  117. eq(1, fn.nvim_tabpage_get_number(0))
  118. end)
  119. it(':tabs does not overflow IObuff with long path with comma #20850', function()
  120. api.nvim_buf_set_name(0, ('x'):rep(1024) .. ',' .. ('x'):rep(1024))
  121. command('tabs')
  122. assert_alive()
  123. end)
  124. end)