blob: 73c3bee2a7f62dfc37dcb1d43a91d242eac1bfdf [file] [log] [blame]
Bram Moolenaar300af822017-03-06 20:28:10 +01001" Test 'statusline'
2"
3" Not tested yet:
Bram Moolenaar300af822017-03-06 20:28:10 +01004" %N
Bram Moolenaar300af822017-03-06 20:28:10 +01005
6source view_util.vim
Bram Moolenaar5a4c3082019-12-01 15:23:11 +01007source check.vim
Bram Moolenaardbe5d362020-02-08 18:35:31 +01008source screendump.vim
Bram Moolenaar300af822017-03-06 20:28:10 +01009
zeertzjqbb404f52022-07-23 06:25:29 +010010func SetUp()
11 set laststatus=2
12endfunc
13
14func TearDown()
15 set laststatus&
16endfunc
17
Bram Moolenaar300af822017-03-06 20:28:10 +010018func s:get_statusline()
19 return ScreenLines(&lines - 1, &columns)[0]
20endfunc
21
22func StatuslineWithCaughtError()
Bram Moolenaara742e082016-04-05 21:10:38 +020023 let s:func_in_statusline_called = 1
24 try
25 call eval('unknown expression')
26 catch
27 endtry
28 return ''
Bram Moolenaar300af822017-03-06 20:28:10 +010029endfunc
Bram Moolenaara742e082016-04-05 21:10:38 +020030
Bram Moolenaar300af822017-03-06 20:28:10 +010031func StatuslineWithError()
Bram Moolenaara742e082016-04-05 21:10:38 +020032 let s:func_in_statusline_called = 1
33 call eval('unknown expression')
34 return ''
Bram Moolenaar300af822017-03-06 20:28:10 +010035endfunc
Bram Moolenaara742e082016-04-05 21:10:38 +020036
Bram Moolenaar300af822017-03-06 20:28:10 +010037" Function used to display syntax group.
38func SyntaxItem()
Bram Moolenaar1c6fd1e2019-05-23 22:11:59 +020039 call assert_equal(s:expected_curbuf, g:actual_curbuf)
40 call assert_equal(s:expected_curwin, g:actual_curwin)
41 return synIDattr(synID(line("."), col("."),1), "name")
Bram Moolenaar300af822017-03-06 20:28:10 +010042endfunc
43
44func Test_caught_error_in_statusline()
Bram Moolenaara742e082016-04-05 21:10:38 +020045 let s:func_in_statusline_called = 0
Bram Moolenaara742e082016-04-05 21:10:38 +020046 let statusline = '%{StatuslineWithCaughtError()}'
47 let &statusline = statusline
48 redrawstatus
49 call assert_true(s:func_in_statusline_called)
50 call assert_equal(statusline, &statusline)
51 set statusline=
Bram Moolenaar300af822017-03-06 20:28:10 +010052endfunc
Bram Moolenaara742e082016-04-05 21:10:38 +020053
Bram Moolenaar300af822017-03-06 20:28:10 +010054func Test_statusline_will_be_disabled_with_error()
Bram Moolenaara742e082016-04-05 21:10:38 +020055 let s:func_in_statusline_called = 0
Bram Moolenaara742e082016-04-05 21:10:38 +020056 let statusline = '%{StatuslineWithError()}'
57 try
58 let &statusline = statusline
59 redrawstatus
60 catch
61 endtry
62 call assert_true(s:func_in_statusline_called)
63 call assert_equal('', &statusline)
64 set statusline=
Bram Moolenaar300af822017-03-06 20:28:10 +010065endfunc
66
67func Test_statusline()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +010068 CheckFeature quickfix
69
Bram Moolenaar4014e2c2020-06-23 20:00:50 +020070 " %a: Argument list ({current} of {max})
71 set statusline=%a
72 call assert_match('^\s*$', s:get_statusline())
73 arglocal a1 a2
74 rewind
75 call assert_match('^ (1 of 2)\s*$', s:get_statusline())
76 next
77 call assert_match('^ (2 of 2)\s*$', s:get_statusline())
78 e Xstatusline
79 call assert_match('^ ((2) of 2)\s*$', s:get_statusline())
80
Bram Moolenaar300af822017-03-06 20:28:10 +010081 only
Bram Moolenaar300af822017-03-06 20:28:10 +010082 set splitbelow
Bram Moolenaar316c1672019-04-14 13:23:40 +020083 call setline(1, range(1, 10000))
Bram Moolenaar300af822017-03-06 20:28:10 +010084
85 " %b: Value of character under cursor.
86 " %B: As above, in hexadecimal.
Bram Moolenaar316c1672019-04-14 13:23:40 +020087 call cursor(9000, 1)
Bram Moolenaar300af822017-03-06 20:28:10 +010088 set statusline=%b,%B
Bram Moolenaar316c1672019-04-14 13:23:40 +020089 call assert_match('^57,39\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +010090
91 " %o: Byte number in file of byte under cursor, first byte is 1.
92 " %O: As above, in hexadecimal.
93 set statusline=%o,%O
94 set fileformat=dos
Bram Moolenaar316c1672019-04-14 13:23:40 +020095 call assert_match('^52888,CE98\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +010096 set fileformat=mac
Bram Moolenaar316c1672019-04-14 13:23:40 +020097 call assert_match('^43889,AB71\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +010098 set fileformat=unix
Bram Moolenaar316c1672019-04-14 13:23:40 +020099 call assert_match('^43889,AB71\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100100 set fileformat&
101
102 " %f: Path to the file in the buffer, as typed or relative to current dir.
103 set statusline=%f
104 call assert_match('^Xstatusline\s*$', s:get_statusline())
105
106 " %F: Full path to the file in the buffer.
107 set statusline=%F
108 call assert_match('/testdir/Xstatusline\s*$', s:get_statusline())
109
Bram Moolenaar832adf92020-06-25 19:01:36 +0200110 " Test for min and max width with %(. For some reason, if this test is moved
111 " after the below test for the help buffer flag, then the code to truncate
112 " the string is not executed.
113 set statusline=%015(%f%)
114 call assert_match('^ Xstatusline\s*$', s:get_statusline())
115 set statusline=%.6(%f%)
116 call assert_match('^<sline\s*$', s:get_statusline())
117 set statusline=%14f
118 call assert_match('^ Xstatusline\s*$', s:get_statusline())
119 set statusline=%.4L
120 call assert_match('^10>3\s*$', s:get_statusline())
121
Bram Moolenaar300af822017-03-06 20:28:10 +0100122 " %h: Help buffer flag, text is "[help]".
123 " %H: Help buffer flag, text is ",HLP".
124 set statusline=%h,%H
125 call assert_match('^,\s*$', s:get_statusline())
126 help
127 call assert_match('^\[Help\],HLP\s*$', s:get_statusline())
128 helpclose
129
130 " %k: Value of "b:keymap_name" or 'keymap'
131 " when :lmap mappings are being used: <keymap>"
132 set statusline=%k
133 if has('keymap')
134 set keymap=esperanto
135 call assert_match('^<Eo>\s*$', s:get_statusline())
136 set keymap&
137 else
138 call assert_match('^\s*$', s:get_statusline())
139 endif
140
141 " %l: Line number.
142 " %L: Number of line in buffer.
143 " %c: Column number.
144 set statusline=%l/%L,%c
Bram Moolenaar316c1672019-04-14 13:23:40 +0200145 call assert_match('^9000/10000,1\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100146
147 " %m: Modified flag, text is "[+]", "[-]" if 'modifiable' is off.
148 " %M: Modified flag, text is ",+" or ",-".
149 set statusline=%m%M
150 call assert_match('^\[+\],+\s*$', s:get_statusline())
151 set nomodifiable
152 call assert_match('^\[+-\],+-\s*$', s:get_statusline())
153 write
154 call assert_match('^\[-\],-\s*$', s:get_statusline())
155 set modifiable&
156 call assert_match('^\s*$', s:get_statusline())
157
158 " %n: Buffer number.
159 set statusline=%n
160 call assert_match('^'.bufnr('%').'\s*$', s:get_statusline())
161
162 " %p: Percentage through file in lines as in CTRL-G.
163 " %P: Percentage through file of displayed window.
164 set statusline=%p,%P
165 0
166 call assert_match('^0,Top\s*$', s:get_statusline())
167 norm G
168 call assert_match('^100,Bot\s*$', s:get_statusline())
Bram Moolenaar316c1672019-04-14 13:23:40 +0200169 9000
Bram Moolenaar300af822017-03-06 20:28:10 +0100170 " Don't check the exact percentage as it depends on the window size
171 call assert_match('^90,\(Top\|Bot\|\d\+%\)\s*$', s:get_statusline())
172
173 " %q: "[Quickfix List]", "[Location List]" or empty.
174 set statusline=%q
175 call assert_match('^\s*$', s:get_statusline())
176 copen
177 call assert_match('^\[Quickfix List\]\s*$', s:get_statusline())
178 cclose
179 lexpr getline(1, 2)
180 lopen
181 call assert_match('^\[Location List\]\s*$', s:get_statusline())
182 lclose
183
184 " %r: Readonly flag, text is "[RO]".
185 " %R: Readonly flag, text is ",RO".
186 set statusline=%r,%R
187 call assert_match('^,\s*$', s:get_statusline())
188 help
189 call assert_match('^\[RO\],RO\s*$', s:get_statusline())
190 helpclose
191
192 " %t: File name (tail) of file in the buffer.
193 set statusline=%t
194 call assert_match('^Xstatusline\s*$', s:get_statusline())
195
196 " %v: Virtual column number.
197 " %V: Virtual column number as -{num}. Not displayed if equal to 'c'.
Bram Moolenaar316c1672019-04-14 13:23:40 +0200198 call cursor(9000, 2)
Bram Moolenaar300af822017-03-06 20:28:10 +0100199 set statusline=%v,%V
200 call assert_match('^2,\s*$', s:get_statusline())
201 set virtualedit=all
202 norm 10|
203 call assert_match('^10,-10\s*$', s:get_statusline())
zeertzjq0f112052022-01-14 20:11:38 +0000204 set list
205 call assert_match('^10,-10\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100206 set virtualedit&
zeertzjq0f112052022-01-14 20:11:38 +0000207 exe "norm A\<Tab>\<Tab>a\<Esc>"
208 " In list mode a <Tab> is shown as "^I", which is 2-wide.
209 call assert_match('^9,-9\s*$', s:get_statusline())
210 set list&
211 " Now the second <Tab> ends at the 16th screen column.
212 call assert_match('^17,-17\s*$', s:get_statusline())
213 undo
Bram Moolenaar300af822017-03-06 20:28:10 +0100214
215 " %w: Preview window flag, text is "[Preview]".
216 " %W: Preview window flag, text is ",PRV".
217 set statusline=%w%W
218 call assert_match('^\s*$', s:get_statusline())
219 pedit
220 wincmd j
221 call assert_match('^\[Preview\],PRV\s*$', s:get_statusline())
222 pclose
Yinzuo Jianga2a2fe82024-12-16 21:22:09 +0100223 pbuffer
224 wincmd j
225 call assert_match('^\[Preview\],PRV\s*$', s:get_statusline())
226 pclose
Bram Moolenaar300af822017-03-06 20:28:10 +0100227
228 " %y: Type of file in the buffer, e.g., "[vim]". See 'filetype'.
229 " %Y: Type of file in the buffer, e.g., ",VIM". See 'filetype'.
230 set statusline=%y\ %Y
231 call assert_match('^\s*$', s:get_statusline())
232 setfiletype vim
233 call assert_match('^\[vim\] VIM\s*$', s:get_statusline())
234
235 " %=: Separation point between left and right aligned items.
236 set statusline=foo%=bar
237 call assert_match('^foo\s\+bar\s*$', s:get_statusline())
Yegappan Lakshmanan3ec78f92023-02-11 11:15:25 +0000238 set statusline=foo%=bar%=baz
239 call assert_match('^foo\s\+bar\s\+baz\s*$', s:get_statusline())
240 set statusline=foo%=bar%=baz%=qux
241 call assert_match('^foo\s\+bar\s\+baz\s\+qux\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100242
243 " Test min/max width, leading zeroes, left/right justify.
244 set statusline=%04B
Bram Moolenaar316c1672019-04-14 13:23:40 +0200245 call cursor(9000, 1)
246 call assert_match('^0039\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100247 set statusline=#%4B#
Bram Moolenaar316c1672019-04-14 13:23:40 +0200248 call assert_match('^# 39#\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100249 set statusline=#%-4B#
Bram Moolenaar316c1672019-04-14 13:23:40 +0200250 call assert_match('^#39 #\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100251 set statusline=%.6f
252 call assert_match('^<sline\s*$', s:get_statusline())
253
254 " %<: Where to truncate.
Bram Moolenaar316c1672019-04-14 13:23:40 +0200255 " First check with when %< should not truncate with many columns
256 exe 'set statusline=a%<b' . repeat('c', &columns - 3) . 'd'
257 call assert_match('^abc\+d$', s:get_statusline())
258 exe 'set statusline=a' . repeat('b', &columns - 2) . '%<c'
259 call assert_match('^ab\+c$', s:get_statusline())
260 " Then check when %< should truncate when there with too few columns.
261 exe 'set statusline=a%<b' . repeat('c', &columns - 2) . 'd'
262 call assert_match('^a<c\+d$', s:get_statusline())
263 exe 'set statusline=a' . repeat('b', &columns - 1) . '%<c'
264 call assert_match('^ab\+>$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100265
266 "%{: Evaluate expression between '%{' and '}' and substitute result.
267 syntax on
Bram Moolenaar1c6fd1e2019-05-23 22:11:59 +0200268 let s:expected_curbuf = string(bufnr(''))
269 let s:expected_curwin = string(win_getid())
Bram Moolenaar300af822017-03-06 20:28:10 +0100270 set statusline=%{SyntaxItem()}
271 call assert_match('^vimNumber\s*$', s:get_statusline())
272 s/^/"/
273 call assert_match('^vimLineComment\s*$', s:get_statusline())
274 syntax off
275
Dominique Pelle81b573d2022-03-22 21:14:55 +0000276 "%{%expr%}: evaluates expressions present in result of expr
shadmansaleh30e3de22021-05-15 17:23:28 +0200277 func! Inner_eval()
278 return '%n some other text'
279 endfunc
280 func! Outer_eval()
281 return 'some text %{%Inner_eval()%}'
282 endfunc
283 set statusline=%{%Outer_eval()%}
284 call assert_match('^some text ' . bufnr() . ' some other text\s*$', s:get_statusline())
285 delfunc Inner_eval
286 delfunc Outer_eval
287
288 "%{%expr%}: Doesn't get stuck in recursion
289 func! Recurse_eval()
290 return '%{%Recurse_eval()%}'
291 endfunc
292 set statusline=%{%Recurse_eval()%}
293 call assert_match('^%{%Recurse_eval()%}\s*$', s:get_statusline())
294 delfunc Recurse_eval
295
Bram Moolenaar300af822017-03-06 20:28:10 +0100296 "%(: Start of item group.
297 set statusline=ab%(cd%q%)de
298 call assert_match('^abde\s*$', s:get_statusline())
299 copen
Bram Moolenaar1ef9bbe2017-06-17 20:08:20 +0200300 call assert_match('^abcd\[Quickfix List]de\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100301 cclose
302
303 " %#: Set highlight group. The name must follow and then a # again.
304 set statusline=ab%#Todo#cd%#Error#ef
305 call assert_match('^abcdef\s*$', s:get_statusline())
306 let sa1=screenattr(&lines - 1, 1)
307 let sa2=screenattr(&lines - 1, 3)
308 let sa3=screenattr(&lines - 1, 5)
309 call assert_notequal(sa1, sa2)
310 call assert_notequal(sa1, sa3)
311 call assert_notequal(sa2, sa3)
312 call assert_equal(sa1, screenattr(&lines - 1, 2))
313 call assert_equal(sa2, screenattr(&lines - 1, 4))
314 call assert_equal(sa3, screenattr(&lines - 1, 6))
315 call assert_equal(sa3, screenattr(&lines - 1, 7))
316
317 " %*: Set highlight group to User{N}
318 set statusline=a%1*b%0*c
319 call assert_match('^abc\s*$', s:get_statusline())
320 let sa1=screenattr(&lines - 1, 1)
321 let sa2=screenattr(&lines - 1, 2)
322 let sa3=screenattr(&lines - 1, 3)
323 call assert_equal(sa1, sa3)
324 call assert_notequal(sa1, sa2)
325
Bram Moolenaar6b89dbb2017-10-22 14:22:16 +0200326 " An empty group that contains highlight changes
327 let g:a = ''
328 set statusline=ab%(cd%1*%{g:a}%*%)de
329 call assert_match('^abde\s*$', s:get_statusline())
330 let sa1=screenattr(&lines - 1, 1)
331 let sa2=screenattr(&lines - 1, 4)
332 call assert_equal(sa1, sa2)
333 let g:a = 'X'
334 call assert_match('^abcdXde\s*$', s:get_statusline())
335 let sa1=screenattr(&lines - 1, 1)
336 let sa2=screenattr(&lines - 1, 5)
337 let sa3=screenattr(&lines - 1, 7)
338 call assert_equal(sa1, sa3)
339 call assert_notequal(sa1, sa2)
340
341 let g:a = ''
342 set statusline=ab%1*%(cd%*%{g:a}%1*%)de
343 call assert_match('^abde\s*$', s:get_statusline())
344 let sa1=screenattr(&lines - 1, 1)
345 let sa2=screenattr(&lines - 1, 4)
346 call assert_notequal(sa1, sa2)
347 let g:a = 'X'
348 call assert_match('^abcdXde\s*$', s:get_statusline())
349 let sa1=screenattr(&lines - 1, 1)
350 let sa2=screenattr(&lines - 1, 3)
351 let sa3=screenattr(&lines - 1, 5)
352 let sa4=screenattr(&lines - 1, 7)
353 call assert_notequal(sa1, sa2)
354 call assert_equal(sa1, sa3)
355 call assert_equal(sa2, sa4)
356
357 " An empty group that contains highlight changes and doesn't reset them
358 let g:a = ''
359 set statusline=ab%(cd%1*%{g:a}%)de
360 call assert_match('^abcdde\s*$', s:get_statusline())
361 let sa1=screenattr(&lines - 1, 1)
362 let sa2=screenattr(&lines - 1, 5)
363 call assert_notequal(sa1, sa2)
364 let g:a = 'X'
365 call assert_match('^abcdXde\s*$', s:get_statusline())
366 let sa1=screenattr(&lines - 1, 1)
367 let sa2=screenattr(&lines - 1, 5)
368 let sa3=screenattr(&lines - 1, 7)
369 call assert_notequal(sa1, sa2)
370 call assert_equal(sa2, sa3)
371
372 let g:a = ''
373 set statusline=ab%1*%(cd%*%{g:a}%)de
374 call assert_match('^abcdde\s*$', s:get_statusline())
375 let sa1=screenattr(&lines - 1, 1)
376 let sa2=screenattr(&lines - 1, 3)
377 let sa3=screenattr(&lines - 1, 5)
378 call assert_notequal(sa1, sa2)
379 call assert_equal(sa1, sa3)
380 let g:a = 'X'
381 call assert_match('^abcdXde\s*$', s:get_statusline())
382 let sa1=screenattr(&lines - 1, 1)
383 let sa2=screenattr(&lines - 1, 3)
384 let sa3=screenattr(&lines - 1, 5)
385 let sa4=screenattr(&lines - 1, 7)
386 call assert_notequal(sa1, sa2)
387 call assert_equal(sa1, sa3)
388 call assert_equal(sa1, sa4)
389
Bram Moolenaar235dddf2017-10-26 18:21:24 +0200390 let g:a = ''
391 set statusline=%#Error#{%(\ %{g:a}\ %)}
392 call assert_match('^{}\s*$', s:get_statusline())
393 let g:a = 'X'
394 call assert_match('^{ X }\s*$', s:get_statusline())
395
Bram Moolenaar300af822017-03-06 20:28:10 +0100396 " %%: a percent sign.
397 set statusline=10%%
398 call assert_match('^10%\s*$', s:get_statusline())
399
400 " %!: evaluated expression is used as the option value
401 set statusline=%!2*3+1
402 call assert_match('7\s*$', s:get_statusline())
403
Bram Moolenaar1c6fd1e2019-05-23 22:11:59 +0200404 func GetNested()
405 call assert_equal(string(win_getid()), g:actual_curwin)
406 call assert_equal(string(bufnr('')), g:actual_curbuf)
407 return 'nested'
408 endfunc
409 func GetStatusLine()
410 call assert_equal(win_getid(), g:statusline_winid)
411 return 'the %{GetNested()} line'
412 endfunc
413 set statusline=%!GetStatusLine()
414 call assert_match('the nested line', s:get_statusline())
415 call assert_false(exists('g:actual_curwin'))
416 call assert_false(exists('g:actual_curbuf'))
417 call assert_false(exists('g:statusline_winid'))
418 delfunc GetNested
419 delfunc GetStatusLine
420
Bram Moolenaar8133cc62020-10-26 21:05:27 +0100421 " Test statusline works with 80+ items
422 function! StatusLabel()
423 redrawstatus
Bram Moolenaar94722c52023-01-28 19:19:03 +0000424 return '[label]'
Bram Moolenaar8133cc62020-10-26 21:05:27 +0100425 endfunc
426 let statusline = '%{StatusLabel()}'
427 for i in range(150)
428 let statusline .= '%#TabLine' . (i % 2 == 0 ? 'Fill' : 'Sel') . '#' . string(i)[0]
429 endfor
430 let &statusline = statusline
431 redrawstatus
432 set statusline&
433 delfunc StatusLabel
434
435
Bram Moolenaar300af822017-03-06 20:28:10 +0100436 " Check statusline in current and non-current window
437 " with the 'fillchars' option.
438 set fillchars=stl:^,stlnc:=,vert:\|,fold:-,diff:-
439 vsplit
440 set statusline=x%=y
441 call assert_match('^x^\+y^x=\+y$', s:get_statusline())
442 set fillchars&
443 close
444
445 %bw!
446 call delete('Xstatusline')
447 set statusline&
Bram Moolenaar300af822017-03-06 20:28:10 +0100448 set splitbelow&
449endfunc
Bram Moolenaardee50a52019-11-30 15:05:22 +0100450
Bram Moolenaar7b17eb42023-01-04 14:31:49 +0000451func Test_statusline_trailing_percent_zero()
452 " this was causing illegal memory access
453 set laststatus=2 stl=%!%0
454 call assert_fails('redraw', 'E15: Invalid expression: "%0"')
455 set laststatus& stl&
456endfunc
457
Bram Moolenaardee50a52019-11-30 15:05:22 +0100458func Test_statusline_visual()
459 func CallWordcount()
460 call wordcount()
461 endfunc
462 new x1
463 setl statusline=count=%{CallWordcount()}
464 " buffer must not be empty
465 call setline(1, 'hello')
466
467 " window with more lines than x1
468 new x2
469 call setline(1, range(10))
470 $
471 " Visual mode in line below liast line in x1 should not give ml_get error
472 call feedkeys("\<C-V>", "xt")
473 redraw
474
475 delfunc CallWordcount
476 bwipe! x1
477 bwipe! x2
478endfunc
Bram Moolenaardbe5d362020-02-08 18:35:31 +0100479
480func Test_statusline_removed_group()
481 CheckScreendump
482
483 let lines =<< trim END
484 scriptencoding utf-8
485 set laststatus=2
486 let &statusline = '%#StatColorHi2#%(✓%#StatColorHi2#%) Q≡'
487 END
Bram Moolenaar56564962022-10-10 22:39:42 +0100488 call writefile(lines, 'XTest_statusline', 'D')
Bram Moolenaardbe5d362020-02-08 18:35:31 +0100489
490 let buf = RunVimInTerminal('-S XTest_statusline', {'rows': 10, 'cols': 50})
Bram Moolenaardbe5d362020-02-08 18:35:31 +0100491 call VerifyScreenDump(buf, 'Test_statusline_1', {})
492
493 " clean up
494 call StopVimInTerminal(buf)
Bram Moolenaardbe5d362020-02-08 18:35:31 +0100495endfunc
Bram Moolenaar832adf92020-06-25 19:01:36 +0200496
Bram Moolenaarce0b7572021-04-01 18:47:14 +0200497func Test_statusline_using_mode()
498 CheckScreendump
499
500 let lines =<< trim END
Bram Moolenaard8db8382021-04-08 18:27:53 +0200501 setlocal statusline=-%{mode()}-
502 split
503 setlocal statusline=+%{mode()}+
Bram Moolenaarce0b7572021-04-01 18:47:14 +0200504 END
Bram Moolenaar56564962022-10-10 22:39:42 +0100505 call writefile(lines, 'XTest_statusline', 'D')
Bram Moolenaarce0b7572021-04-01 18:47:14 +0200506
Bram Moolenaard8db8382021-04-08 18:27:53 +0200507 let buf = RunVimInTerminal('-S XTest_statusline', {'rows': 7, 'cols': 50})
Bram Moolenaarce0b7572021-04-01 18:47:14 +0200508 call VerifyScreenDump(buf, 'Test_statusline_mode_1', {})
509
510 call term_sendkeys(buf, ":")
511 call VerifyScreenDump(buf, 'Test_statusline_mode_2', {})
512
513 " clean up
Bram Moolenaard8db8382021-04-08 18:27:53 +0200514 call term_sendkeys(buf, "close\<CR>")
Bram Moolenaarce0b7572021-04-01 18:47:14 +0200515 call StopVimInTerminal(buf)
Bram Moolenaarce0b7572021-04-01 18:47:14 +0200516endfunc
517
Bram Moolenaar668008b2020-10-01 19:06:35 +0200518func Test_statusline_after_split_vsplit()
519 only
520
521 " Make the status line of each window show the window number.
522 set ls=2 stl=%{winnr()}
523
524 split | redraw
525 vsplit | redraw
526
527 " The status line of the third window should read '3' here.
528 call assert_equal('3', nr2char(screenchar(&lines - 1, 1)))
529
530 only
531 set ls& stl&
532endfunc
533
Bram Moolenaar008bff92021-03-04 21:55:58 +0100534" Test using a multibyte character for 'stl' and 'stlnc' items in 'fillchars'
535" with a custom 'statusline'
536func Test_statusline_mbyte_fillchar()
537 only
Bram Moolenaar008bff92021-03-04 21:55:58 +0100538 set fillchars=vert:\|,fold:-,stl:━,stlnc:═
539 set statusline=a%=b
540 call assert_match('^a\+━\+b$', s:get_statusline())
541 vnew
542 call assert_match('^a\+━\+b━a\+═\+b$', s:get_statusline())
543 wincmd w
544 call assert_match('^a\+═\+b═a\+━\+b$', s:get_statusline())
zeertzjqbb404f52022-07-23 06:25:29 +0100545 set statusline& fillchars&
Bram Moolenaar008bff92021-03-04 21:55:58 +0100546 %bw!
547endfunc
Bram Moolenaar668008b2020-10-01 19:06:35 +0200548
Bram Moolenaar826bfe42021-10-08 18:39:28 +0100549" Used to write beyond allocated memory. This assumes MAXPATHL is 4096 bytes.
550func Test_statusline_verylong_filename()
551 let fname = repeat('x', 4090)
552 exe "new " .. fname
553 set buftype=help
554 set previewwindow
555 redraw
556 bwipe!
557endfunc
558
LemonBoy57ff5262022-05-09 21:03:47 +0100559func Test_statusline_highlight_truncate()
560 CheckScreendump
561
562 let lines =<< trim END
563 set laststatus=2
564 hi! link User1 Directory
565 hi! link User2 ErrorMsg
566 set statusline=%.5(%1*ABC%2*DEF%1*GHI%)
567 END
Bram Moolenaar56564962022-10-10 22:39:42 +0100568 call writefile(lines, 'XTest_statusline', 'D')
LemonBoy57ff5262022-05-09 21:03:47 +0100569
570 let buf = RunVimInTerminal('-S XTest_statusline', {'rows': 6})
571 call VerifyScreenDump(buf, 'Test_statusline_hl', {})
572
573 call StopVimInTerminal(buf)
LemonBoy57ff5262022-05-09 21:03:47 +0100574endfunc
575
Luuk van Baalba936f62022-12-15 13:15:39 +0000576func Test_statusline_showcmd()
577 CheckScreendump
578
579 let lines =<< trim END
zeertzjq378e6c02023-01-14 11:46:49 +0000580 func MyStatusLine()
581 return '%S'
582 endfunc
583
Luuk van Baalba936f62022-12-15 13:15:39 +0000584 set laststatus=2
zeertzjq378e6c02023-01-14 11:46:49 +0000585 set statusline=%!MyStatusLine()
Luuk van Baalba936f62022-12-15 13:15:39 +0000586 set showcmdloc=statusline
587 call setline(1, ['a', 'b', 'c'])
zeertzjq378e6c02023-01-14 11:46:49 +0000588 set foldopen+=jump
589 1,2fold
590 3
Luuk van Baalba936f62022-12-15 13:15:39 +0000591 END
592 call writefile(lines, 'XTest_statusline', 'D')
593
594 let buf = RunVimInTerminal('-S XTest_statusline', {'rows': 6})
zeertzjq378e6c02023-01-14 11:46:49 +0000595
596 call term_sendkeys(buf, "g")
Luuk van Baalba936f62022-12-15 13:15:39 +0000597 call VerifyScreenDump(buf, 'Test_statusline_showcmd_1', {})
598
zeertzjq378e6c02023-01-14 11:46:49 +0000599 " typing "gg" should open the fold
600 call term_sendkeys(buf, "g")
Luuk van Baalba936f62022-12-15 13:15:39 +0000601 call VerifyScreenDump(buf, 'Test_statusline_showcmd_2', {})
602
zeertzjq378e6c02023-01-14 11:46:49 +0000603 call term_sendkeys(buf, "\<C-V>Gl")
Luuk van Baalba936f62022-12-15 13:15:39 +0000604 call VerifyScreenDump(buf, 'Test_statusline_showcmd_3', {})
zeertzjq378e6c02023-01-14 11:46:49 +0000605
606 call term_sendkeys(buf, "\<Esc>1234")
607 call VerifyScreenDump(buf, 'Test_statusline_showcmd_4', {})
608
609 call term_sendkeys(buf, "\<Esc>:set statusline=\<CR>")
610 call term_sendkeys(buf, ":\<CR>")
611 call term_sendkeys(buf, "1234")
612 call VerifyScreenDump(buf, 'Test_statusline_showcmd_5', {})
613
614 call StopVimInTerminal(buf)
Luuk van Baalba936f62022-12-15 13:15:39 +0000615endfunc
616
Christian Brabandt6a650bf2023-11-08 21:23:29 +0100617func Test_statusline_highlight_group_cleared()
618 CheckScreendump
619
620 " the laststatus option is there to prevent
621 " the code-style test from complaining about
622 " trailing whitespace
623 let lines =<< trim END
624 set fillchars=stl:\ ,stlnc:\ laststatus=2
625 split
626 hi clear StatusLine
627 hi clear StatusLineNC
628 END
629 call writefile(lines, 'XTest_statusline_stl', 'D')
630
631 let buf = RunVimInTerminal('-S XTest_statusline_stl', {})
632
633 call VerifyScreenDump(buf, 'Test_statusline_stl_1', {})
634
635 call StopVimInTerminal(buf)
636endfunc
637
Bram Moolenaar832adf92020-06-25 19:01:36 +0200638" vim: shiftwidth=2 sts=2 expandtab