blob: f2204db57e16c08bc6c167a2fb7f7634dbbc0cf2 [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()
Drew Vogelea67ba72025-05-07 22:05:17 +020019 if has('gui_running')
20 redraw!
21 sleep 1m
22 endif
Bram Moolenaar300af822017-03-06 20:28:10 +010023 return ScreenLines(&lines - 1, &columns)[0]
24endfunc
25
26func StatuslineWithCaughtError()
Bram Moolenaara742e082016-04-05 21:10:38 +020027 let s:func_in_statusline_called = 1
28 try
29 call eval('unknown expression')
30 catch
31 endtry
32 return ''
Bram Moolenaar300af822017-03-06 20:28:10 +010033endfunc
Bram Moolenaara742e082016-04-05 21:10:38 +020034
Bram Moolenaar300af822017-03-06 20:28:10 +010035func StatuslineWithError()
Bram Moolenaara742e082016-04-05 21:10:38 +020036 let s:func_in_statusline_called = 1
37 call eval('unknown expression')
38 return ''
Bram Moolenaar300af822017-03-06 20:28:10 +010039endfunc
Bram Moolenaara742e082016-04-05 21:10:38 +020040
Bram Moolenaar300af822017-03-06 20:28:10 +010041" Function used to display syntax group.
42func SyntaxItem()
Bram Moolenaar1c6fd1e2019-05-23 22:11:59 +020043 call assert_equal(s:expected_curbuf, g:actual_curbuf)
44 call assert_equal(s:expected_curwin, g:actual_curwin)
45 return synIDattr(synID(line("."), col("."),1), "name")
Bram Moolenaar300af822017-03-06 20:28:10 +010046endfunc
47
48func Test_caught_error_in_statusline()
Bram Moolenaara742e082016-04-05 21:10:38 +020049 let s:func_in_statusline_called = 0
Bram Moolenaara742e082016-04-05 21:10:38 +020050 let statusline = '%{StatuslineWithCaughtError()}'
51 let &statusline = statusline
52 redrawstatus
53 call assert_true(s:func_in_statusline_called)
54 call assert_equal(statusline, &statusline)
55 set statusline=
Bram Moolenaar300af822017-03-06 20:28:10 +010056endfunc
Bram Moolenaara742e082016-04-05 21:10:38 +020057
Bram Moolenaar300af822017-03-06 20:28:10 +010058func Test_statusline_will_be_disabled_with_error()
Bram Moolenaara742e082016-04-05 21:10:38 +020059 let s:func_in_statusline_called = 0
Bram Moolenaara742e082016-04-05 21:10:38 +020060 let statusline = '%{StatuslineWithError()}'
61 try
62 let &statusline = statusline
63 redrawstatus
64 catch
65 endtry
66 call assert_true(s:func_in_statusline_called)
67 call assert_equal('', &statusline)
68 set statusline=
Bram Moolenaar300af822017-03-06 20:28:10 +010069endfunc
70
71func Test_statusline()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +010072 CheckFeature quickfix
73
Bram Moolenaar4014e2c2020-06-23 20:00:50 +020074 " %a: Argument list ({current} of {max})
75 set statusline=%a
76 call assert_match('^\s*$', s:get_statusline())
77 arglocal a1 a2
78 rewind
79 call assert_match('^ (1 of 2)\s*$', s:get_statusline())
80 next
81 call assert_match('^ (2 of 2)\s*$', s:get_statusline())
82 e Xstatusline
83 call assert_match('^ ((2) of 2)\s*$', s:get_statusline())
84
Bram Moolenaar300af822017-03-06 20:28:10 +010085 only
Bram Moolenaar300af822017-03-06 20:28:10 +010086 set splitbelow
Bram Moolenaar316c1672019-04-14 13:23:40 +020087 call setline(1, range(1, 10000))
Bram Moolenaar300af822017-03-06 20:28:10 +010088
89 " %b: Value of character under cursor.
90 " %B: As above, in hexadecimal.
Bram Moolenaar316c1672019-04-14 13:23:40 +020091 call cursor(9000, 1)
Bram Moolenaar300af822017-03-06 20:28:10 +010092 set statusline=%b,%B
Bram Moolenaar316c1672019-04-14 13:23:40 +020093 call assert_match('^57,39\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +010094
95 " %o: Byte number in file of byte under cursor, first byte is 1.
96 " %O: As above, in hexadecimal.
97 set statusline=%o,%O
98 set fileformat=dos
Bram Moolenaar316c1672019-04-14 13:23:40 +020099 call assert_match('^52888,CE98\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100100 set fileformat=mac
Bram Moolenaar316c1672019-04-14 13:23:40 +0200101 call assert_match('^43889,AB71\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100102 set fileformat=unix
Bram Moolenaar316c1672019-04-14 13:23:40 +0200103 call assert_match('^43889,AB71\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100104 set fileformat&
105
106 " %f: Path to the file in the buffer, as typed or relative to current dir.
107 set statusline=%f
108 call assert_match('^Xstatusline\s*$', s:get_statusline())
109
110 " %F: Full path to the file in the buffer.
111 set statusline=%F
112 call assert_match('/testdir/Xstatusline\s*$', s:get_statusline())
113
Bram Moolenaar832adf92020-06-25 19:01:36 +0200114 " Test for min and max width with %(. For some reason, if this test is moved
115 " after the below test for the help buffer flag, then the code to truncate
116 " the string is not executed.
117 set statusline=%015(%f%)
118 call assert_match('^ Xstatusline\s*$', s:get_statusline())
119 set statusline=%.6(%f%)
120 call assert_match('^<sline\s*$', s:get_statusline())
121 set statusline=%14f
122 call assert_match('^ Xstatusline\s*$', s:get_statusline())
123 set statusline=%.4L
124 call assert_match('^10>3\s*$', s:get_statusline())
125
Bram Moolenaar300af822017-03-06 20:28:10 +0100126 " %h: Help buffer flag, text is "[help]".
127 " %H: Help buffer flag, text is ",HLP".
128 set statusline=%h,%H
129 call assert_match('^,\s*$', s:get_statusline())
130 help
131 call assert_match('^\[Help\],HLP\s*$', s:get_statusline())
132 helpclose
133
134 " %k: Value of "b:keymap_name" or 'keymap'
135 " when :lmap mappings are being used: <keymap>"
136 set statusline=%k
137 if has('keymap')
138 set keymap=esperanto
139 call assert_match('^<Eo>\s*$', s:get_statusline())
140 set keymap&
141 else
142 call assert_match('^\s*$', s:get_statusline())
143 endif
144
145 " %l: Line number.
146 " %L: Number of line in buffer.
147 " %c: Column number.
148 set statusline=%l/%L,%c
Bram Moolenaar316c1672019-04-14 13:23:40 +0200149 call assert_match('^9000/10000,1\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100150
151 " %m: Modified flag, text is "[+]", "[-]" if 'modifiable' is off.
152 " %M: Modified flag, text is ",+" or ",-".
153 set statusline=%m%M
154 call assert_match('^\[+\],+\s*$', s:get_statusline())
155 set nomodifiable
156 call assert_match('^\[+-\],+-\s*$', s:get_statusline())
157 write
158 call assert_match('^\[-\],-\s*$', s:get_statusline())
159 set modifiable&
160 call assert_match('^\s*$', s:get_statusline())
161
162 " %n: Buffer number.
163 set statusline=%n
164 call assert_match('^'.bufnr('%').'\s*$', s:get_statusline())
165
166 " %p: Percentage through file in lines as in CTRL-G.
167 " %P: Percentage through file of displayed window.
168 set statusline=%p,%P
169 0
170 call assert_match('^0,Top\s*$', s:get_statusline())
171 norm G
172 call assert_match('^100,Bot\s*$', s:get_statusline())
Bram Moolenaar316c1672019-04-14 13:23:40 +0200173 9000
Bram Moolenaar300af822017-03-06 20:28:10 +0100174 " Don't check the exact percentage as it depends on the window size
175 call assert_match('^90,\(Top\|Bot\|\d\+%\)\s*$', s:get_statusline())
176
177 " %q: "[Quickfix List]", "[Location List]" or empty.
178 set statusline=%q
179 call assert_match('^\s*$', s:get_statusline())
180 copen
181 call assert_match('^\[Quickfix List\]\s*$', s:get_statusline())
182 cclose
183 lexpr getline(1, 2)
184 lopen
185 call assert_match('^\[Location List\]\s*$', s:get_statusline())
186 lclose
187
188 " %r: Readonly flag, text is "[RO]".
189 " %R: Readonly flag, text is ",RO".
190 set statusline=%r,%R
191 call assert_match('^,\s*$', s:get_statusline())
192 help
193 call assert_match('^\[RO\],RO\s*$', s:get_statusline())
194 helpclose
195
196 " %t: File name (tail) of file in the buffer.
197 set statusline=%t
198 call assert_match('^Xstatusline\s*$', s:get_statusline())
199
200 " %v: Virtual column number.
201 " %V: Virtual column number as -{num}. Not displayed if equal to 'c'.
Bram Moolenaar316c1672019-04-14 13:23:40 +0200202 call cursor(9000, 2)
Bram Moolenaar300af822017-03-06 20:28:10 +0100203 set statusline=%v,%V
204 call assert_match('^2,\s*$', s:get_statusline())
205 set virtualedit=all
206 norm 10|
207 call assert_match('^10,-10\s*$', s:get_statusline())
zeertzjq0f112052022-01-14 20:11:38 +0000208 set list
209 call assert_match('^10,-10\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100210 set virtualedit&
zeertzjq0f112052022-01-14 20:11:38 +0000211 exe "norm A\<Tab>\<Tab>a\<Esc>"
212 " In list mode a <Tab> is shown as "^I", which is 2-wide.
213 call assert_match('^9,-9\s*$', s:get_statusline())
214 set list&
215 " Now the second <Tab> ends at the 16th screen column.
216 call assert_match('^17,-17\s*$', s:get_statusline())
217 undo
Bram Moolenaar300af822017-03-06 20:28:10 +0100218
219 " %w: Preview window flag, text is "[Preview]".
220 " %W: Preview window flag, text is ",PRV".
221 set statusline=%w%W
222 call assert_match('^\s*$', s:get_statusline())
223 pedit
224 wincmd j
225 call assert_match('^\[Preview\],PRV\s*$', s:get_statusline())
226 pclose
Yinzuo Jianga2a2fe82024-12-16 21:22:09 +0100227 pbuffer
228 wincmd j
229 call assert_match('^\[Preview\],PRV\s*$', s:get_statusline())
230 pclose
Bram Moolenaar300af822017-03-06 20:28:10 +0100231
232 " %y: Type of file in the buffer, e.g., "[vim]". See 'filetype'.
233 " %Y: Type of file in the buffer, e.g., ",VIM". See 'filetype'.
234 set statusline=%y\ %Y
235 call assert_match('^\s*$', s:get_statusline())
236 setfiletype vim
237 call assert_match('^\[vim\] VIM\s*$', s:get_statusline())
238
239 " %=: Separation point between left and right aligned items.
240 set statusline=foo%=bar
241 call assert_match('^foo\s\+bar\s*$', s:get_statusline())
Yegappan Lakshmanan3ec78f92023-02-11 11:15:25 +0000242 set statusline=foo%=bar%=baz
243 call assert_match('^foo\s\+bar\s\+baz\s*$', s:get_statusline())
244 set statusline=foo%=bar%=baz%=qux
245 call assert_match('^foo\s\+bar\s\+baz\s\+qux\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100246
247 " Test min/max width, leading zeroes, left/right justify.
248 set statusline=%04B
Bram Moolenaar316c1672019-04-14 13:23:40 +0200249 call cursor(9000, 1)
250 call assert_match('^0039\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100251 set statusline=#%4B#
Bram Moolenaar316c1672019-04-14 13:23:40 +0200252 call assert_match('^# 39#\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100253 set statusline=#%-4B#
Bram Moolenaar316c1672019-04-14 13:23:40 +0200254 call assert_match('^#39 #\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100255 set statusline=%.6f
256 call assert_match('^<sline\s*$', s:get_statusline())
257
258 " %<: Where to truncate.
Bram Moolenaar316c1672019-04-14 13:23:40 +0200259 " First check with when %< should not truncate with many columns
260 exe 'set statusline=a%<b' . repeat('c', &columns - 3) . 'd'
261 call assert_match('^abc\+d$', s:get_statusline())
262 exe 'set statusline=a' . repeat('b', &columns - 2) . '%<c'
263 call assert_match('^ab\+c$', s:get_statusline())
264 " Then check when %< should truncate when there with too few columns.
265 exe 'set statusline=a%<b' . repeat('c', &columns - 2) . 'd'
266 call assert_match('^a<c\+d$', s:get_statusline())
267 exe 'set statusline=a' . repeat('b', &columns - 1) . '%<c'
268 call assert_match('^ab\+>$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100269
270 "%{: Evaluate expression between '%{' and '}' and substitute result.
271 syntax on
Bram Moolenaar1c6fd1e2019-05-23 22:11:59 +0200272 let s:expected_curbuf = string(bufnr(''))
273 let s:expected_curwin = string(win_getid())
Bram Moolenaar300af822017-03-06 20:28:10 +0100274 set statusline=%{SyntaxItem()}
275 call assert_match('^vimNumber\s*$', s:get_statusline())
276 s/^/"/
277 call assert_match('^vimLineComment\s*$', s:get_statusline())
278 syntax off
279
Dominique Pelle81b573d2022-03-22 21:14:55 +0000280 "%{%expr%}: evaluates expressions present in result of expr
shadmansaleh30e3de22021-05-15 17:23:28 +0200281 func! Inner_eval()
282 return '%n some other text'
283 endfunc
284 func! Outer_eval()
285 return 'some text %{%Inner_eval()%}'
286 endfunc
287 set statusline=%{%Outer_eval()%}
288 call assert_match('^some text ' . bufnr() . ' some other text\s*$', s:get_statusline())
289 delfunc Inner_eval
290 delfunc Outer_eval
291
292 "%{%expr%}: Doesn't get stuck in recursion
293 func! Recurse_eval()
294 return '%{%Recurse_eval()%}'
295 endfunc
296 set statusline=%{%Recurse_eval()%}
297 call assert_match('^%{%Recurse_eval()%}\s*$', s:get_statusline())
298 delfunc Recurse_eval
299
Bram Moolenaar300af822017-03-06 20:28:10 +0100300 "%(: Start of item group.
301 set statusline=ab%(cd%q%)de
302 call assert_match('^abde\s*$', s:get_statusline())
303 copen
Bram Moolenaar1ef9bbe2017-06-17 20:08:20 +0200304 call assert_match('^abcd\[Quickfix List]de\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100305 cclose
306
307 " %#: Set highlight group. The name must follow and then a # again.
308 set statusline=ab%#Todo#cd%#Error#ef
309 call assert_match('^abcdef\s*$', s:get_statusline())
310 let sa1=screenattr(&lines - 1, 1)
311 let sa2=screenattr(&lines - 1, 3)
312 let sa3=screenattr(&lines - 1, 5)
313 call assert_notequal(sa1, sa2)
314 call assert_notequal(sa1, sa3)
315 call assert_notequal(sa2, sa3)
316 call assert_equal(sa1, screenattr(&lines - 1, 2))
317 call assert_equal(sa2, screenattr(&lines - 1, 4))
318 call assert_equal(sa3, screenattr(&lines - 1, 6))
319 call assert_equal(sa3, screenattr(&lines - 1, 7))
320
321 " %*: Set highlight group to User{N}
322 set statusline=a%1*b%0*c
323 call assert_match('^abc\s*$', s:get_statusline())
324 let sa1=screenattr(&lines - 1, 1)
325 let sa2=screenattr(&lines - 1, 2)
326 let sa3=screenattr(&lines - 1, 3)
327 call assert_equal(sa1, sa3)
328 call assert_notequal(sa1, sa2)
329
Bram Moolenaar6b89dbb2017-10-22 14:22:16 +0200330 " An empty group that contains highlight changes
331 let g:a = ''
332 set statusline=ab%(cd%1*%{g:a}%*%)de
333 call assert_match('^abde\s*$', s:get_statusline())
334 let sa1=screenattr(&lines - 1, 1)
335 let sa2=screenattr(&lines - 1, 4)
336 call assert_equal(sa1, sa2)
337 let g:a = 'X'
338 call assert_match('^abcdXde\s*$', s:get_statusline())
339 let sa1=screenattr(&lines - 1, 1)
340 let sa2=screenattr(&lines - 1, 5)
341 let sa3=screenattr(&lines - 1, 7)
342 call assert_equal(sa1, sa3)
343 call assert_notequal(sa1, sa2)
344
345 let g:a = ''
346 set statusline=ab%1*%(cd%*%{g:a}%1*%)de
347 call assert_match('^abde\s*$', s:get_statusline())
348 let sa1=screenattr(&lines - 1, 1)
349 let sa2=screenattr(&lines - 1, 4)
350 call assert_notequal(sa1, sa2)
351 let g:a = 'X'
352 call assert_match('^abcdXde\s*$', s:get_statusline())
353 let sa1=screenattr(&lines - 1, 1)
354 let sa2=screenattr(&lines - 1, 3)
355 let sa3=screenattr(&lines - 1, 5)
356 let sa4=screenattr(&lines - 1, 7)
357 call assert_notequal(sa1, sa2)
358 call assert_equal(sa1, sa3)
359 call assert_equal(sa2, sa4)
360
361 " An empty group that contains highlight changes and doesn't reset them
362 let g:a = ''
363 set statusline=ab%(cd%1*%{g:a}%)de
364 call assert_match('^abcdde\s*$', s:get_statusline())
365 let sa1=screenattr(&lines - 1, 1)
366 let sa2=screenattr(&lines - 1, 5)
367 call assert_notequal(sa1, sa2)
368 let g:a = 'X'
369 call assert_match('^abcdXde\s*$', s:get_statusline())
370 let sa1=screenattr(&lines - 1, 1)
371 let sa2=screenattr(&lines - 1, 5)
372 let sa3=screenattr(&lines - 1, 7)
373 call assert_notequal(sa1, sa2)
374 call assert_equal(sa2, sa3)
375
376 let g:a = ''
377 set statusline=ab%1*%(cd%*%{g:a}%)de
378 call assert_match('^abcdde\s*$', s:get_statusline())
379 let sa1=screenattr(&lines - 1, 1)
380 let sa2=screenattr(&lines - 1, 3)
381 let sa3=screenattr(&lines - 1, 5)
382 call assert_notequal(sa1, sa2)
383 call assert_equal(sa1, sa3)
384 let g:a = 'X'
385 call assert_match('^abcdXde\s*$', s:get_statusline())
386 let sa1=screenattr(&lines - 1, 1)
387 let sa2=screenattr(&lines - 1, 3)
388 let sa3=screenattr(&lines - 1, 5)
389 let sa4=screenattr(&lines - 1, 7)
390 call assert_notequal(sa1, sa2)
391 call assert_equal(sa1, sa3)
392 call assert_equal(sa1, sa4)
393
Bram Moolenaar235dddf2017-10-26 18:21:24 +0200394 let g:a = ''
395 set statusline=%#Error#{%(\ %{g:a}\ %)}
396 call assert_match('^{}\s*$', s:get_statusline())
397 let g:a = 'X'
398 call assert_match('^{ X }\s*$', s:get_statusline())
399
Bram Moolenaar300af822017-03-06 20:28:10 +0100400 " %%: a percent sign.
401 set statusline=10%%
402 call assert_match('^10%\s*$', s:get_statusline())
403
404 " %!: evaluated expression is used as the option value
405 set statusline=%!2*3+1
406 call assert_match('7\s*$', s:get_statusline())
407
Bram Moolenaar1c6fd1e2019-05-23 22:11:59 +0200408 func GetNested()
409 call assert_equal(string(win_getid()), g:actual_curwin)
410 call assert_equal(string(bufnr('')), g:actual_curbuf)
411 return 'nested'
412 endfunc
413 func GetStatusLine()
414 call assert_equal(win_getid(), g:statusline_winid)
415 return 'the %{GetNested()} line'
416 endfunc
417 set statusline=%!GetStatusLine()
418 call assert_match('the nested line', s:get_statusline())
419 call assert_false(exists('g:actual_curwin'))
420 call assert_false(exists('g:actual_curbuf'))
421 call assert_false(exists('g:statusline_winid'))
422 delfunc GetNested
423 delfunc GetStatusLine
424
Bram Moolenaar8133cc62020-10-26 21:05:27 +0100425 " Test statusline works with 80+ items
426 function! StatusLabel()
427 redrawstatus
Bram Moolenaar94722c52023-01-28 19:19:03 +0000428 return '[label]'
Bram Moolenaar8133cc62020-10-26 21:05:27 +0100429 endfunc
430 let statusline = '%{StatusLabel()}'
431 for i in range(150)
432 let statusline .= '%#TabLine' . (i % 2 == 0 ? 'Fill' : 'Sel') . '#' . string(i)[0]
433 endfor
434 let &statusline = statusline
435 redrawstatus
436 set statusline&
437 delfunc StatusLabel
438
439
Bram Moolenaar300af822017-03-06 20:28:10 +0100440 " Check statusline in current and non-current window
441 " with the 'fillchars' option.
442 set fillchars=stl:^,stlnc:=,vert:\|,fold:-,diff:-
443 vsplit
444 set statusline=x%=y
445 call assert_match('^x^\+y^x=\+y$', s:get_statusline())
446 set fillchars&
447 close
448
449 %bw!
450 call delete('Xstatusline')
451 set statusline&
Bram Moolenaar300af822017-03-06 20:28:10 +0100452 set splitbelow&
453endfunc
Bram Moolenaardee50a52019-11-30 15:05:22 +0100454
Bram Moolenaar7b17eb42023-01-04 14:31:49 +0000455func Test_statusline_trailing_percent_zero()
456 " this was causing illegal memory access
457 set laststatus=2 stl=%!%0
458 call assert_fails('redraw', 'E15: Invalid expression: "%0"')
459 set laststatus& stl&
460endfunc
461
Bram Moolenaardee50a52019-11-30 15:05:22 +0100462func Test_statusline_visual()
463 func CallWordcount()
464 call wordcount()
465 endfunc
466 new x1
467 setl statusline=count=%{CallWordcount()}
468 " buffer must not be empty
469 call setline(1, 'hello')
470
471 " window with more lines than x1
472 new x2
473 call setline(1, range(10))
474 $
475 " Visual mode in line below liast line in x1 should not give ml_get error
476 call feedkeys("\<C-V>", "xt")
477 redraw
478
479 delfunc CallWordcount
480 bwipe! x1
481 bwipe! x2
482endfunc
Bram Moolenaardbe5d362020-02-08 18:35:31 +0100483
484func Test_statusline_removed_group()
485 CheckScreendump
486
487 let lines =<< trim END
488 scriptencoding utf-8
489 set laststatus=2
490 let &statusline = '%#StatColorHi2#%(✓%#StatColorHi2#%) Q≡'
491 END
Bram Moolenaar56564962022-10-10 22:39:42 +0100492 call writefile(lines, 'XTest_statusline', 'D')
Bram Moolenaardbe5d362020-02-08 18:35:31 +0100493
494 let buf = RunVimInTerminal('-S XTest_statusline', {'rows': 10, 'cols': 50})
Bram Moolenaardbe5d362020-02-08 18:35:31 +0100495 call VerifyScreenDump(buf, 'Test_statusline_1', {})
496
497 " clean up
498 call StopVimInTerminal(buf)
Bram Moolenaardbe5d362020-02-08 18:35:31 +0100499endfunc
Bram Moolenaar832adf92020-06-25 19:01:36 +0200500
Bram Moolenaarce0b7572021-04-01 18:47:14 +0200501func Test_statusline_using_mode()
502 CheckScreendump
503
504 let lines =<< trim END
Bram Moolenaard8db8382021-04-08 18:27:53 +0200505 setlocal statusline=-%{mode()}-
506 split
507 setlocal statusline=+%{mode()}+
Bram Moolenaarce0b7572021-04-01 18:47:14 +0200508 END
Bram Moolenaar56564962022-10-10 22:39:42 +0100509 call writefile(lines, 'XTest_statusline', 'D')
Bram Moolenaarce0b7572021-04-01 18:47:14 +0200510
Bram Moolenaard8db8382021-04-08 18:27:53 +0200511 let buf = RunVimInTerminal('-S XTest_statusline', {'rows': 7, 'cols': 50})
Bram Moolenaarce0b7572021-04-01 18:47:14 +0200512 call VerifyScreenDump(buf, 'Test_statusline_mode_1', {})
513
514 call term_sendkeys(buf, ":")
515 call VerifyScreenDump(buf, 'Test_statusline_mode_2', {})
516
517 " clean up
Bram Moolenaard8db8382021-04-08 18:27:53 +0200518 call term_sendkeys(buf, "close\<CR>")
Bram Moolenaarce0b7572021-04-01 18:47:14 +0200519 call StopVimInTerminal(buf)
Bram Moolenaarce0b7572021-04-01 18:47:14 +0200520endfunc
521
Bram Moolenaar668008b2020-10-01 19:06:35 +0200522func Test_statusline_after_split_vsplit()
523 only
524
525 " Make the status line of each window show the window number.
526 set ls=2 stl=%{winnr()}
527
528 split | redraw
529 vsplit | redraw
530
531 " The status line of the third window should read '3' here.
532 call assert_equal('3', nr2char(screenchar(&lines - 1, 1)))
533
534 only
535 set ls& stl&
536endfunc
537
Bram Moolenaar008bff92021-03-04 21:55:58 +0100538" Test using a multibyte character for 'stl' and 'stlnc' items in 'fillchars'
539" with a custom 'statusline'
540func Test_statusline_mbyte_fillchar()
541 only
Bram Moolenaar008bff92021-03-04 21:55:58 +0100542 set fillchars=vert:\|,fold:-,stl:━,stlnc:═
543 set statusline=a%=b
544 call assert_match('^a\+━\+b$', s:get_statusline())
545 vnew
546 call assert_match('^a\+━\+b━a\+═\+b$', s:get_statusline())
547 wincmd w
548 call assert_match('^a\+═\+b═a\+━\+b$', s:get_statusline())
zeertzjqbb404f52022-07-23 06:25:29 +0100549 set statusline& fillchars&
Bram Moolenaar008bff92021-03-04 21:55:58 +0100550 %bw!
551endfunc
Bram Moolenaar668008b2020-10-01 19:06:35 +0200552
Bram Moolenaar826bfe42021-10-08 18:39:28 +0100553" Used to write beyond allocated memory. This assumes MAXPATHL is 4096 bytes.
554func Test_statusline_verylong_filename()
555 let fname = repeat('x', 4090)
556 exe "new " .. fname
557 set buftype=help
558 set previewwindow
559 redraw
560 bwipe!
561endfunc
562
LemonBoy57ff5262022-05-09 21:03:47 +0100563func Test_statusline_highlight_truncate()
564 CheckScreendump
565
566 let lines =<< trim END
567 set laststatus=2
568 hi! link User1 Directory
569 hi! link User2 ErrorMsg
570 set statusline=%.5(%1*ABC%2*DEF%1*GHI%)
571 END
Bram Moolenaar56564962022-10-10 22:39:42 +0100572 call writefile(lines, 'XTest_statusline', 'D')
LemonBoy57ff5262022-05-09 21:03:47 +0100573
574 let buf = RunVimInTerminal('-S XTest_statusline', {'rows': 6})
575 call VerifyScreenDump(buf, 'Test_statusline_hl', {})
576
577 call StopVimInTerminal(buf)
LemonBoy57ff5262022-05-09 21:03:47 +0100578endfunc
579
Luuk van Baalba936f62022-12-15 13:15:39 +0000580func Test_statusline_showcmd()
581 CheckScreendump
582
583 let lines =<< trim END
zeertzjq378e6c02023-01-14 11:46:49 +0000584 func MyStatusLine()
585 return '%S'
586 endfunc
587
Luuk van Baalba936f62022-12-15 13:15:39 +0000588 set laststatus=2
zeertzjq378e6c02023-01-14 11:46:49 +0000589 set statusline=%!MyStatusLine()
Luuk van Baalba936f62022-12-15 13:15:39 +0000590 set showcmdloc=statusline
591 call setline(1, ['a', 'b', 'c'])
zeertzjq378e6c02023-01-14 11:46:49 +0000592 set foldopen+=jump
593 1,2fold
594 3
Luuk van Baalba936f62022-12-15 13:15:39 +0000595 END
596 call writefile(lines, 'XTest_statusline', 'D')
597
598 let buf = RunVimInTerminal('-S XTest_statusline', {'rows': 6})
zeertzjq378e6c02023-01-14 11:46:49 +0000599
600 call term_sendkeys(buf, "g")
Luuk van Baalba936f62022-12-15 13:15:39 +0000601 call VerifyScreenDump(buf, 'Test_statusline_showcmd_1', {})
602
zeertzjq378e6c02023-01-14 11:46:49 +0000603 " typing "gg" should open the fold
604 call term_sendkeys(buf, "g")
Luuk van Baalba936f62022-12-15 13:15:39 +0000605 call VerifyScreenDump(buf, 'Test_statusline_showcmd_2', {})
606
zeertzjq378e6c02023-01-14 11:46:49 +0000607 call term_sendkeys(buf, "\<C-V>Gl")
Luuk van Baalba936f62022-12-15 13:15:39 +0000608 call VerifyScreenDump(buf, 'Test_statusline_showcmd_3', {})
zeertzjq378e6c02023-01-14 11:46:49 +0000609
610 call term_sendkeys(buf, "\<Esc>1234")
611 call VerifyScreenDump(buf, 'Test_statusline_showcmd_4', {})
612
613 call term_sendkeys(buf, "\<Esc>:set statusline=\<CR>")
614 call term_sendkeys(buf, ":\<CR>")
615 call term_sendkeys(buf, "1234")
616 call VerifyScreenDump(buf, 'Test_statusline_showcmd_5', {})
617
618 call StopVimInTerminal(buf)
Luuk van Baalba936f62022-12-15 13:15:39 +0000619endfunc
620
Christian Brabandt6a650bf2023-11-08 21:23:29 +0100621func Test_statusline_highlight_group_cleared()
622 CheckScreendump
623
624 " the laststatus option is there to prevent
625 " the code-style test from complaining about
626 " trailing whitespace
627 let lines =<< trim END
628 set fillchars=stl:\ ,stlnc:\ laststatus=2
629 split
630 hi clear StatusLine
631 hi clear StatusLineNC
632 END
633 call writefile(lines, 'XTest_statusline_stl', 'D')
634
635 let buf = RunVimInTerminal('-S XTest_statusline_stl', {})
636
637 call VerifyScreenDump(buf, 'Test_statusline_stl_1', {})
638
639 call StopVimInTerminal(buf)
640endfunc
641
Bram Moolenaar832adf92020-06-25 19:01:36 +0200642" vim: shiftwidth=2 sts=2 expandtab