xref: /vim-8.2.3635/src/testdir/test_tabline.vim (revision 6d91bcb4)
1" Test for tabline
2
3source shared.vim
4
5func TablineWithCaughtError()
6  let s:func_in_tabline_called = 1
7  try
8    call eval('unknown expression')
9  catch
10  endtry
11  return ''
12endfunc
13
14func TablineWithError()
15  let s:func_in_tabline_called = 1
16  call eval('unknown expression')
17  return ''
18endfunc
19
20func Test_caught_error_in_tabline()
21  if has('gui')
22    set guioptions-=e
23  endif
24  let showtabline_save = &showtabline
25  set showtabline=2
26  let s:func_in_tabline_called = 0
27  let tabline = '%{TablineWithCaughtError()}'
28  let &tabline = tabline
29  redraw!
30  call assert_true(s:func_in_tabline_called)
31  call assert_equal(tabline, &tabline)
32  set tabline=
33  let &showtabline = showtabline_save
34endfunc
35
36func Test_tabline_will_be_disabled_with_error()
37  if has('gui')
38    set guioptions-=e
39  endif
40  let showtabline_save = &showtabline
41  set showtabline=2
42  let s:func_in_tabline_called = 0
43  let tabline = '%{TablineWithError()}'
44  try
45    let &tabline = tabline
46    redraw!
47  catch
48  endtry
49  call assert_true(s:func_in_tabline_called)
50  call assert_equal('', &tabline)
51  set tabline=
52  let &showtabline = showtabline_save
53endfunc
54
55func Test_redrawtabline()
56  if has('gui')
57    set guioptions-=e
58  endif
59  let showtabline_save = &showtabline
60  set showtabline=2
61  set tabline=%{bufnr('$')}
62  edit Xtabline1
63  edit Xtabline2
64  redraw
65  call assert_match(bufnr('$') . '', Screenline(1))
66  au BufAdd * redrawtabline
67  badd Xtabline3
68  call assert_match(bufnr('$') . '', Screenline(1))
69
70  set tabline=
71  let &showtabline = showtabline_save
72  au! Bufadd
73endfunc
74
75" Test for the "%T" and "%X" flags in the 'tabline' option
76func MyTabLine()
77  let s = ''
78  for i in range(tabpagenr('$'))
79    " set the tab page number (for mouse clicks)
80    let s .= '%' . (i + 1) . 'T'
81
82    " the label is made by MyTabLabel()
83    let s .= ' %{MyTabLabel(' . (i + 1) . ')} '
84  endfor
85
86  " after the last tab fill with TabLineFill and reset tab page nr
87  let s .= '%T'
88
89  " right-align the label to close the current tab page
90  if tabpagenr('$') > 1
91    let s .= '%=%Xclose'
92  endif
93
94  return s
95endfunc
96
97func MyTabLabel(n)
98  let buflist = tabpagebuflist(a:n)
99  let winnr = tabpagewinnr(a:n)
100  return bufname(buflist[winnr - 1])
101endfunc
102
103func Test_tabline_flags()
104  if has('gui')
105    set guioptions-=e
106  endif
107  set tabline=%!MyTabLine()
108  edit Xtabline1
109  tabnew Xtabline2
110  redrawtabline
111  call assert_match('^ Xtabline1  Xtabline2\s\+close$', Screenline(1))
112  set tabline=
113  %bw!
114endfunc
115
116function EmptyTabname()
117  return ""
118endfunction
119
120function MakeTabLine() abort
121  let titles = map(range(1, tabpagenr('$')), '"%( %" . v:val . "T%{EmptyTabname()}%T %)"')
122  let sep = 'あ'
123  let tabpages = join(titles, sep)
124  return tabpages .. sep .. '%=%999X X'
125endfunction
126
127func Test_tabline_empty_group()
128  " this was reading invalid memory
129  set tabline=%!MakeTabLine()
130  tabnew
131  redraw!
132
133  tabclose
134  set tabline=
135endfunc
136
137
138
139" vim: shiftwidth=2 sts=2 expandtab
140