test_tabline.vim 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. " Test for tabline
  2. source shared.vim
  3. source view_util.vim
  4. source check.vim
  5. source screendump.vim
  6. func TablineWithCaughtError()
  7. let s:func_in_tabline_called = 1
  8. try
  9. call eval('unknown expression')
  10. catch
  11. endtry
  12. return ''
  13. endfunc
  14. func TablineWithError()
  15. let s:func_in_tabline_called = 1
  16. call eval('unknown expression')
  17. return ''
  18. endfunc
  19. func Test_caught_error_in_tabline()
  20. if has('gui')
  21. set guioptions-=e
  22. endif
  23. let showtabline_save = &showtabline
  24. set showtabline=2
  25. let s:func_in_tabline_called = 0
  26. let tabline = '%{TablineWithCaughtError()}'
  27. let &tabline = tabline
  28. redraw!
  29. call assert_true(s:func_in_tabline_called)
  30. call assert_equal(tabline, &tabline)
  31. set tabline=
  32. let &showtabline = showtabline_save
  33. endfunc
  34. func Test_tabline_will_be_disabled_with_error()
  35. if has('gui')
  36. set guioptions-=e
  37. endif
  38. let showtabline_save = &showtabline
  39. set showtabline=2
  40. let s:func_in_tabline_called = 0
  41. let tabline = '%{TablineWithError()}'
  42. try
  43. let &tabline = tabline
  44. redraw!
  45. catch
  46. endtry
  47. call assert_true(s:func_in_tabline_called)
  48. call assert_equal('', &tabline)
  49. set tabline=
  50. let &showtabline = showtabline_save
  51. endfunc
  52. func Test_redrawtabline()
  53. if has('gui')
  54. set guioptions-=e
  55. endif
  56. let showtabline_save = &showtabline
  57. set showtabline=2
  58. set tabline=%{bufnr('$')}
  59. edit Xtabline1
  60. edit Xtabline2
  61. redraw
  62. call assert_match(bufnr('$') . '', Screenline(1))
  63. au BufAdd * redrawtabline
  64. badd Xtabline3
  65. call assert_match(bufnr('$') . '', Screenline(1))
  66. set tabline=
  67. let &showtabline = showtabline_save
  68. au! Bufadd
  69. endfunc
  70. " Test for the "%T" and "%X" flags in the 'tabline' option
  71. func MyTabLine()
  72. let s = ''
  73. for i in range(tabpagenr('$'))
  74. " set the tab page number (for mouse clicks)
  75. let s .= '%' . (i + 1) . 'T'
  76. " the label is made by MyTabLabel()
  77. let s .= ' %{MyTabLabel(' . (i + 1) . ')} '
  78. endfor
  79. " after the last tab fill with TabLineFill and reset tab page nr
  80. let s .= '%T'
  81. " right-align the label to close the current tab page
  82. if tabpagenr('$') > 1
  83. let s .= '%=%Xclose'
  84. endif
  85. return s
  86. endfunc
  87. func MyTabLabel(n)
  88. let buflist = tabpagebuflist(a:n)
  89. let winnr = tabpagewinnr(a:n)
  90. return bufname(buflist[winnr - 1])
  91. endfunc
  92. func Test_tabline_flags()
  93. if has('gui')
  94. set guioptions-=e
  95. endif
  96. set tabline=%!MyTabLine()
  97. edit Xtabline1
  98. tabnew Xtabline2
  99. redrawtabline
  100. call assert_match('^ Xtabline1 Xtabline2\s\+close$', Screenline(1))
  101. set tabline=
  102. %bw!
  103. endfunc
  104. function EmptyTabname()
  105. return ""
  106. endfunction
  107. function MakeTabLine() abort
  108. let titles = map(range(1, tabpagenr('$')), '"%( %" . v:val . "T%{EmptyTabname()}%T %)"')
  109. let sep = 'あ'
  110. let tabpages = join(titles, sep)
  111. return tabpages .. sep .. '%=%999X X'
  112. endfunction
  113. func Test_tabline_empty_group()
  114. " this was reading invalid memory
  115. set tabline=%!MakeTabLine()
  116. tabnew
  117. redraw!
  118. bw!
  119. set tabline=
  120. endfunc
  121. " When there are exactly 20 tabline format items (the exact size of the
  122. " initial tabline items array), test that we don't write beyond the size
  123. " of the array.
  124. func Test_tabline_20_format_items_no_overrun()
  125. set showtabline=2
  126. let tabline = repeat('%#StatColorHi2#', 20)
  127. let &tabline = tabline
  128. redrawtabline
  129. set showtabline& tabline&
  130. endfunc
  131. func Test_mouse_click_in_tab()
  132. " This used to crash because TabPageIdxs[] was not initialized
  133. let lines =<< trim END
  134. tabnew
  135. set mouse=a
  136. exe "norm \<LeftMouse>"
  137. END
  138. call writefile(lines, 'Xclickscript')
  139. call RunVim([], [], "-e -s -S Xclickscript -c qa")
  140. call delete('Xclickscript')
  141. endfunc
  142. func Test_tabline_showcmd()
  143. CheckScreendump
  144. let lines =<< trim END
  145. func MyTabLine()
  146. return '%S'
  147. endfunc
  148. set showtabline=2
  149. set tabline=%!MyTabLine()
  150. set showcmdloc=tabline
  151. call setline(1, ['a', 'b', 'c'])
  152. set foldopen+=jump
  153. 1,2fold
  154. 3
  155. END
  156. call writefile(lines, 'XTest_tabline', 'D')
  157. let buf = RunVimInTerminal('-S XTest_tabline', {'rows': 6})
  158. call term_sendkeys(buf, "g")
  159. call VerifyScreenDump(buf, 'Test_tabline_showcmd_1', {})
  160. " typing "gg" should open the fold
  161. call term_sendkeys(buf, "g")
  162. call VerifyScreenDump(buf, 'Test_tabline_showcmd_2', {})
  163. call term_sendkeys(buf, "\<C-V>Gl")
  164. call VerifyScreenDump(buf, 'Test_tabline_showcmd_3', {})
  165. call term_sendkeys(buf, "\<Esc>1234")
  166. call VerifyScreenDump(buf, 'Test_tabline_showcmd_4', {})
  167. call term_sendkeys(buf, "\<Esc>:set tabline=\<CR>")
  168. call term_sendkeys(buf, ":\<CR>")
  169. call term_sendkeys(buf, "1234")
  170. call VerifyScreenDump(buf, 'Test_tabline_showcmd_5', {})
  171. call StopVimInTerminal(buf)
  172. endfunc
  173. func TruncTabLine()
  174. return '%1T口口%2Ta' .. repeat('b', &columns - 4) .. '%999X%#TabLine#c'
  175. endfunc
  176. " Test 'tabline' with truncated double-width label at the start.
  177. func Test_tabline_truncated_double_width()
  178. tabnew
  179. redraw
  180. call assert_match('X$', Screenline(1))
  181. let attr_TabLineFill = screenattr(1, &columns - 1)
  182. let attr_TabLine = screenattr(1, &columns)
  183. call assert_notequal(attr_TabLine, attr_TabLineFill)
  184. set tabline=%!TruncTabLine()
  185. redraw
  186. call assert_equal('<a' .. repeat('b', &columns - 4) .. 'c', Screenline(1))
  187. call assert_equal(attr_TabLineFill, screenattr(1, &columns - 2))
  188. call assert_equal(attr_TabLine, screenattr(1, &columns - 1))
  189. call assert_equal(attr_TabLine, screenattr(1, &columns))
  190. bw!
  191. set tabline=
  192. endfunc
  193. " vim: shiftwidth=2 sts=2 expandtab