1 2source shared.vim 3 4func TablineWithCaughtError() 5 let s:func_in_tabline_called = 1 6 try 7 call eval('unknown expression') 8 catch 9 endtry 10 return '' 11endfunc 12 13func TablineWithError() 14 let s:func_in_tabline_called = 1 15 call eval('unknown expression') 16 return '' 17endfunc 18 19func 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 33endfunc 34 35func Test_tabline_will_be_disabled_with_error() 36 if has('gui') 37 set guioptions-=e 38 endif 39 let showtabline_save = &showtabline 40 set showtabline=2 41 let s:func_in_tabline_called = 0 42 let tabline = '%{TablineWithError()}' 43 try 44 let &tabline = tabline 45 redraw! 46 catch 47 endtry 48 call assert_true(s:func_in_tabline_called) 49 call assert_equal('', &tabline) 50 set tabline= 51 let &showtabline = showtabline_save 52endfunc 53 54func Test_redrawtabline() 55 if has('gui') 56 set guioptions-=e 57 endif 58 let showtabline_save = &showtabline 59 set showtabline=2 60 set tabline=%{bufnr('$')} 61 edit Xtabline1 62 edit Xtabline2 63 redraw 64 call assert_match(bufnr('$') . '', Screenline(1)) 65 au BufAdd * redrawtabline 66 badd Xtabline3 67 call assert_match(bufnr('$') . '', Screenline(1)) 68 69 set tabline= 70 let &showtabline = showtabline_save 71 au! Bufadd 72endfunc 73 74" Test for the "%T" and "%X" flags in the 'tabline' option 75func MyTabLine() 76 let s = '' 77 for i in range(tabpagenr('$')) 78 " set the tab page number (for mouse clicks) 79 let s .= '%' . (i + 1) . 'T' 80 81 " the label is made by MyTabLabel() 82 let s .= ' %{MyTabLabel(' . (i + 1) . ')} ' 83 endfor 84 85 " after the last tab fill with TabLineFill and reset tab page nr 86 let s .= '%T' 87 88 " right-align the label to close the current tab page 89 if tabpagenr('$') > 1 90 let s .= '%=%Xclose' 91 endif 92 93 return s 94endfunc 95 96func MyTabLabel(n) 97 let buflist = tabpagebuflist(a:n) 98 let winnr = tabpagewinnr(a:n) 99 return bufname(buflist[winnr - 1]) 100endfunc 101 102func Test_tabline_flags() 103 if has('gui') 104 set guioptions-=e 105 endif 106 set tabline=%!MyTabLine() 107 edit Xtabline1 108 tabnew Xtabline2 109 redrawtabline 110 call assert_match('^ Xtabline1 Xtabline2\s\+close$', Screenline(1)) 111 set tabline= 112 %bw! 113endfunc 114 115" vim: shiftwidth=2 sts=2 expandtab 116