blob: 7c75f61a871431d5f2fbdac747e6988629f69c28 [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
10func s:get_statusline()
11 return ScreenLines(&lines - 1, &columns)[0]
12endfunc
13
14func StatuslineWithCaughtError()
Bram Moolenaara742e082016-04-05 21:10:38 +020015 let s:func_in_statusline_called = 1
16 try
17 call eval('unknown expression')
18 catch
19 endtry
20 return ''
Bram Moolenaar300af822017-03-06 20:28:10 +010021endfunc
Bram Moolenaara742e082016-04-05 21:10:38 +020022
Bram Moolenaar300af822017-03-06 20:28:10 +010023func StatuslineWithError()
Bram Moolenaara742e082016-04-05 21:10:38 +020024 let s:func_in_statusline_called = 1
25 call eval('unknown expression')
26 return ''
Bram Moolenaar300af822017-03-06 20:28:10 +010027endfunc
Bram Moolenaara742e082016-04-05 21:10:38 +020028
Bram Moolenaar300af822017-03-06 20:28:10 +010029" Function used to display syntax group.
30func SyntaxItem()
Bram Moolenaar1c6fd1e2019-05-23 22:11:59 +020031 call assert_equal(s:expected_curbuf, g:actual_curbuf)
32 call assert_equal(s:expected_curwin, g:actual_curwin)
33 return synIDattr(synID(line("."), col("."),1), "name")
Bram Moolenaar300af822017-03-06 20:28:10 +010034endfunc
35
36func Test_caught_error_in_statusline()
Bram Moolenaara742e082016-04-05 21:10:38 +020037 let s:func_in_statusline_called = 0
38 set laststatus=2
39 let statusline = '%{StatuslineWithCaughtError()}'
40 let &statusline = statusline
41 redrawstatus
42 call assert_true(s:func_in_statusline_called)
43 call assert_equal(statusline, &statusline)
44 set statusline=
Bram Moolenaar300af822017-03-06 20:28:10 +010045endfunc
Bram Moolenaara742e082016-04-05 21:10:38 +020046
Bram Moolenaar300af822017-03-06 20:28:10 +010047func Test_statusline_will_be_disabled_with_error()
Bram Moolenaara742e082016-04-05 21:10:38 +020048 let s:func_in_statusline_called = 0
49 set laststatus=2
50 let statusline = '%{StatuslineWithError()}'
51 try
52 let &statusline = statusline
53 redrawstatus
54 catch
55 endtry
56 call assert_true(s:func_in_statusline_called)
57 call assert_equal('', &statusline)
58 set statusline=
Bram Moolenaar300af822017-03-06 20:28:10 +010059endfunc
60
61func Test_statusline()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +010062 CheckFeature quickfix
63
Bram Moolenaar4014e2c2020-06-23 20:00:50 +020064 " %a: Argument list ({current} of {max})
65 set statusline=%a
66 call assert_match('^\s*$', s:get_statusline())
67 arglocal a1 a2
68 rewind
69 call assert_match('^ (1 of 2)\s*$', s:get_statusline())
70 next
71 call assert_match('^ (2 of 2)\s*$', s:get_statusline())
72 e Xstatusline
73 call assert_match('^ ((2) of 2)\s*$', s:get_statusline())
74
Bram Moolenaar300af822017-03-06 20:28:10 +010075 only
76 set laststatus=2
77 set splitbelow
Bram Moolenaar316c1672019-04-14 13:23:40 +020078 call setline(1, range(1, 10000))
Bram Moolenaar300af822017-03-06 20:28:10 +010079
80 " %b: Value of character under cursor.
81 " %B: As above, in hexadecimal.
Bram Moolenaar316c1672019-04-14 13:23:40 +020082 call cursor(9000, 1)
Bram Moolenaar300af822017-03-06 20:28:10 +010083 set statusline=%b,%B
Bram Moolenaar316c1672019-04-14 13:23:40 +020084 call assert_match('^57,39\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +010085
86 " %o: Byte number in file of byte under cursor, first byte is 1.
87 " %O: As above, in hexadecimal.
88 set statusline=%o,%O
89 set fileformat=dos
Bram Moolenaar316c1672019-04-14 13:23:40 +020090 call assert_match('^52888,CE98\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +010091 set fileformat=mac
Bram Moolenaar316c1672019-04-14 13:23:40 +020092 call assert_match('^43889,AB71\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +010093 set fileformat=unix
Bram Moolenaar316c1672019-04-14 13:23:40 +020094 call assert_match('^43889,AB71\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +010095 set fileformat&
96
97 " %f: Path to the file in the buffer, as typed or relative to current dir.
98 set statusline=%f
99 call assert_match('^Xstatusline\s*$', s:get_statusline())
100
101 " %F: Full path to the file in the buffer.
102 set statusline=%F
103 call assert_match('/testdir/Xstatusline\s*$', s:get_statusline())
104
Bram Moolenaar832adf92020-06-25 19:01:36 +0200105 " Test for min and max width with %(. For some reason, if this test is moved
106 " after the below test for the help buffer flag, then the code to truncate
107 " the string is not executed.
108 set statusline=%015(%f%)
109 call assert_match('^ Xstatusline\s*$', s:get_statusline())
110 set statusline=%.6(%f%)
111 call assert_match('^<sline\s*$', s:get_statusline())
112 set statusline=%14f
113 call assert_match('^ Xstatusline\s*$', s:get_statusline())
114 set statusline=%.4L
115 call assert_match('^10>3\s*$', s:get_statusline())
116
Bram Moolenaar300af822017-03-06 20:28:10 +0100117 " %h: Help buffer flag, text is "[help]".
118 " %H: Help buffer flag, text is ",HLP".
119 set statusline=%h,%H
120 call assert_match('^,\s*$', s:get_statusline())
121 help
122 call assert_match('^\[Help\],HLP\s*$', s:get_statusline())
123 helpclose
124
125 " %k: Value of "b:keymap_name" or 'keymap'
126 " when :lmap mappings are being used: <keymap>"
127 set statusline=%k
128 if has('keymap')
129 set keymap=esperanto
130 call assert_match('^<Eo>\s*$', s:get_statusline())
131 set keymap&
132 else
133 call assert_match('^\s*$', s:get_statusline())
134 endif
135
136 " %l: Line number.
137 " %L: Number of line in buffer.
138 " %c: Column number.
139 set statusline=%l/%L,%c
Bram Moolenaar316c1672019-04-14 13:23:40 +0200140 call assert_match('^9000/10000,1\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100141
142 " %m: Modified flag, text is "[+]", "[-]" if 'modifiable' is off.
143 " %M: Modified flag, text is ",+" or ",-".
144 set statusline=%m%M
145 call assert_match('^\[+\],+\s*$', s:get_statusline())
146 set nomodifiable
147 call assert_match('^\[+-\],+-\s*$', s:get_statusline())
148 write
149 call assert_match('^\[-\],-\s*$', s:get_statusline())
150 set modifiable&
151 call assert_match('^\s*$', s:get_statusline())
152
153 " %n: Buffer number.
154 set statusline=%n
155 call assert_match('^'.bufnr('%').'\s*$', s:get_statusline())
156
157 " %p: Percentage through file in lines as in CTRL-G.
158 " %P: Percentage through file of displayed window.
159 set statusline=%p,%P
160 0
161 call assert_match('^0,Top\s*$', s:get_statusline())
162 norm G
163 call assert_match('^100,Bot\s*$', s:get_statusline())
Bram Moolenaar316c1672019-04-14 13:23:40 +0200164 9000
Bram Moolenaar300af822017-03-06 20:28:10 +0100165 " Don't check the exact percentage as it depends on the window size
166 call assert_match('^90,\(Top\|Bot\|\d\+%\)\s*$', s:get_statusline())
167
168 " %q: "[Quickfix List]", "[Location List]" or empty.
169 set statusline=%q
170 call assert_match('^\s*$', s:get_statusline())
171 copen
172 call assert_match('^\[Quickfix List\]\s*$', s:get_statusline())
173 cclose
174 lexpr getline(1, 2)
175 lopen
176 call assert_match('^\[Location List\]\s*$', s:get_statusline())
177 lclose
178
179 " %r: Readonly flag, text is "[RO]".
180 " %R: Readonly flag, text is ",RO".
181 set statusline=%r,%R
182 call assert_match('^,\s*$', s:get_statusline())
183 help
184 call assert_match('^\[RO\],RO\s*$', s:get_statusline())
185 helpclose
186
187 " %t: File name (tail) of file in the buffer.
188 set statusline=%t
189 call assert_match('^Xstatusline\s*$', s:get_statusline())
190
191 " %v: Virtual column number.
192 " %V: Virtual column number as -{num}. Not displayed if equal to 'c'.
Bram Moolenaar316c1672019-04-14 13:23:40 +0200193 call cursor(9000, 2)
Bram Moolenaar300af822017-03-06 20:28:10 +0100194 set statusline=%v,%V
195 call assert_match('^2,\s*$', s:get_statusline())
196 set virtualedit=all
197 norm 10|
198 call assert_match('^10,-10\s*$', s:get_statusline())
zeertzjq0f112052022-01-14 20:11:38 +0000199 set list
200 call assert_match('^10,-10\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100201 set virtualedit&
zeertzjq0f112052022-01-14 20:11:38 +0000202 exe "norm A\<Tab>\<Tab>a\<Esc>"
203 " In list mode a <Tab> is shown as "^I", which is 2-wide.
204 call assert_match('^9,-9\s*$', s:get_statusline())
205 set list&
206 " Now the second <Tab> ends at the 16th screen column.
207 call assert_match('^17,-17\s*$', s:get_statusline())
208 undo
Bram Moolenaar300af822017-03-06 20:28:10 +0100209
210 " %w: Preview window flag, text is "[Preview]".
211 " %W: Preview window flag, text is ",PRV".
212 set statusline=%w%W
213 call assert_match('^\s*$', s:get_statusline())
214 pedit
215 wincmd j
216 call assert_match('^\[Preview\],PRV\s*$', s:get_statusline())
217 pclose
218
219 " %y: Type of file in the buffer, e.g., "[vim]". See 'filetype'.
220 " %Y: Type of file in the buffer, e.g., ",VIM". See 'filetype'.
221 set statusline=%y\ %Y
222 call assert_match('^\s*$', s:get_statusline())
223 setfiletype vim
224 call assert_match('^\[vim\] VIM\s*$', s:get_statusline())
225
226 " %=: Separation point between left and right aligned items.
227 set statusline=foo%=bar
228 call assert_match('^foo\s\+bar\s*$', s:get_statusline())
229
230 " Test min/max width, leading zeroes, left/right justify.
231 set statusline=%04B
Bram Moolenaar316c1672019-04-14 13:23:40 +0200232 call cursor(9000, 1)
233 call assert_match('^0039\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100234 set statusline=#%4B#
Bram Moolenaar316c1672019-04-14 13:23:40 +0200235 call assert_match('^# 39#\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100236 set statusline=#%-4B#
Bram Moolenaar316c1672019-04-14 13:23:40 +0200237 call assert_match('^#39 #\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100238 set statusline=%.6f
239 call assert_match('^<sline\s*$', s:get_statusline())
240
241 " %<: Where to truncate.
Bram Moolenaar316c1672019-04-14 13:23:40 +0200242 " First check with when %< should not truncate with many columns
243 exe 'set statusline=a%<b' . repeat('c', &columns - 3) . 'd'
244 call assert_match('^abc\+d$', s:get_statusline())
245 exe 'set statusline=a' . repeat('b', &columns - 2) . '%<c'
246 call assert_match('^ab\+c$', s:get_statusline())
247 " Then check when %< should truncate when there with too few columns.
248 exe 'set statusline=a%<b' . repeat('c', &columns - 2) . 'd'
249 call assert_match('^a<c\+d$', s:get_statusline())
250 exe 'set statusline=a' . repeat('b', &columns - 1) . '%<c'
251 call assert_match('^ab\+>$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100252
253 "%{: Evaluate expression between '%{' and '}' and substitute result.
254 syntax on
Bram Moolenaar1c6fd1e2019-05-23 22:11:59 +0200255 let s:expected_curbuf = string(bufnr(''))
256 let s:expected_curwin = string(win_getid())
Bram Moolenaar300af822017-03-06 20:28:10 +0100257 set statusline=%{SyntaxItem()}
258 call assert_match('^vimNumber\s*$', s:get_statusline())
259 s/^/"/
260 call assert_match('^vimLineComment\s*$', s:get_statusline())
261 syntax off
262
Dominique Pelle81b573d2022-03-22 21:14:55 +0000263 "%{%expr%}: evaluates expressions present in result of expr
shadmansaleh30e3de22021-05-15 17:23:28 +0200264 func! Inner_eval()
265 return '%n some other text'
266 endfunc
267 func! Outer_eval()
268 return 'some text %{%Inner_eval()%}'
269 endfunc
270 set statusline=%{%Outer_eval()%}
271 call assert_match('^some text ' . bufnr() . ' some other text\s*$', s:get_statusline())
272 delfunc Inner_eval
273 delfunc Outer_eval
274
275 "%{%expr%}: Doesn't get stuck in recursion
276 func! Recurse_eval()
277 return '%{%Recurse_eval()%}'
278 endfunc
279 set statusline=%{%Recurse_eval()%}
280 call assert_match('^%{%Recurse_eval()%}\s*$', s:get_statusline())
281 delfunc Recurse_eval
282
Bram Moolenaar300af822017-03-06 20:28:10 +0100283 "%(: Start of item group.
284 set statusline=ab%(cd%q%)de
285 call assert_match('^abde\s*$', s:get_statusline())
286 copen
Bram Moolenaar1ef9bbe2017-06-17 20:08:20 +0200287 call assert_match('^abcd\[Quickfix List]de\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100288 cclose
289
290 " %#: Set highlight group. The name must follow and then a # again.
291 set statusline=ab%#Todo#cd%#Error#ef
292 call assert_match('^abcdef\s*$', s:get_statusline())
293 let sa1=screenattr(&lines - 1, 1)
294 let sa2=screenattr(&lines - 1, 3)
295 let sa3=screenattr(&lines - 1, 5)
296 call assert_notequal(sa1, sa2)
297 call assert_notequal(sa1, sa3)
298 call assert_notequal(sa2, sa3)
299 call assert_equal(sa1, screenattr(&lines - 1, 2))
300 call assert_equal(sa2, screenattr(&lines - 1, 4))
301 call assert_equal(sa3, screenattr(&lines - 1, 6))
302 call assert_equal(sa3, screenattr(&lines - 1, 7))
303
304 " %*: Set highlight group to User{N}
305 set statusline=a%1*b%0*c
306 call assert_match('^abc\s*$', s:get_statusline())
307 let sa1=screenattr(&lines - 1, 1)
308 let sa2=screenattr(&lines - 1, 2)
309 let sa3=screenattr(&lines - 1, 3)
310 call assert_equal(sa1, sa3)
311 call assert_notequal(sa1, sa2)
312
Bram Moolenaar6b89dbb2017-10-22 14:22:16 +0200313 " An empty group that contains highlight changes
314 let g:a = ''
315 set statusline=ab%(cd%1*%{g:a}%*%)de
316 call assert_match('^abde\s*$', s:get_statusline())
317 let sa1=screenattr(&lines - 1, 1)
318 let sa2=screenattr(&lines - 1, 4)
319 call assert_equal(sa1, sa2)
320 let g:a = 'X'
321 call assert_match('^abcdXde\s*$', s:get_statusline())
322 let sa1=screenattr(&lines - 1, 1)
323 let sa2=screenattr(&lines - 1, 5)
324 let sa3=screenattr(&lines - 1, 7)
325 call assert_equal(sa1, sa3)
326 call assert_notequal(sa1, sa2)
327
328 let g:a = ''
329 set statusline=ab%1*%(cd%*%{g:a}%1*%)de
330 call assert_match('^abde\s*$', s:get_statusline())
331 let sa1=screenattr(&lines - 1, 1)
332 let sa2=screenattr(&lines - 1, 4)
333 call assert_notequal(sa1, sa2)
334 let g:a = 'X'
335 call assert_match('^abcdXde\s*$', s:get_statusline())
336 let sa1=screenattr(&lines - 1, 1)
337 let sa2=screenattr(&lines - 1, 3)
338 let sa3=screenattr(&lines - 1, 5)
339 let sa4=screenattr(&lines - 1, 7)
340 call assert_notequal(sa1, sa2)
341 call assert_equal(sa1, sa3)
342 call assert_equal(sa2, sa4)
343
344 " An empty group that contains highlight changes and doesn't reset them
345 let g:a = ''
346 set statusline=ab%(cd%1*%{g:a}%)de
347 call assert_match('^abcdde\s*$', s:get_statusline())
348 let sa1=screenattr(&lines - 1, 1)
349 let sa2=screenattr(&lines - 1, 5)
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, 5)
355 let sa3=screenattr(&lines - 1, 7)
356 call assert_notequal(sa1, sa2)
357 call assert_equal(sa2, sa3)
358
359 let g:a = ''
360 set statusline=ab%1*%(cd%*%{g:a}%)de
361 call assert_match('^abcdde\s*$', s:get_statusline())
362 let sa1=screenattr(&lines - 1, 1)
363 let sa2=screenattr(&lines - 1, 3)
364 let sa3=screenattr(&lines - 1, 5)
365 call assert_notequal(sa1, sa2)
366 call assert_equal(sa1, sa3)
367 let g:a = 'X'
368 call assert_match('^abcdXde\s*$', s:get_statusline())
369 let sa1=screenattr(&lines - 1, 1)
370 let sa2=screenattr(&lines - 1, 3)
371 let sa3=screenattr(&lines - 1, 5)
372 let sa4=screenattr(&lines - 1, 7)
373 call assert_notequal(sa1, sa2)
374 call assert_equal(sa1, sa3)
375 call assert_equal(sa1, sa4)
376
Bram Moolenaar235dddf2017-10-26 18:21:24 +0200377 let g:a = ''
378 set statusline=%#Error#{%(\ %{g:a}\ %)}
379 call assert_match('^{}\s*$', s:get_statusline())
380 let g:a = 'X'
381 call assert_match('^{ X }\s*$', s:get_statusline())
382
Bram Moolenaar300af822017-03-06 20:28:10 +0100383 " %%: a percent sign.
384 set statusline=10%%
385 call assert_match('^10%\s*$', s:get_statusline())
386
387 " %!: evaluated expression is used as the option value
388 set statusline=%!2*3+1
389 call assert_match('7\s*$', s:get_statusline())
390
Bram Moolenaar1c6fd1e2019-05-23 22:11:59 +0200391 func GetNested()
392 call assert_equal(string(win_getid()), g:actual_curwin)
393 call assert_equal(string(bufnr('')), g:actual_curbuf)
394 return 'nested'
395 endfunc
396 func GetStatusLine()
397 call assert_equal(win_getid(), g:statusline_winid)
398 return 'the %{GetNested()} line'
399 endfunc
400 set statusline=%!GetStatusLine()
401 call assert_match('the nested line', s:get_statusline())
402 call assert_false(exists('g:actual_curwin'))
403 call assert_false(exists('g:actual_curbuf'))
404 call assert_false(exists('g:statusline_winid'))
405 delfunc GetNested
406 delfunc GetStatusLine
407
Bram Moolenaar8133cc62020-10-26 21:05:27 +0100408 " Test statusline works with 80+ items
409 function! StatusLabel()
410 redrawstatus
411 return '[label]'
412 endfunc
413 let statusline = '%{StatusLabel()}'
414 for i in range(150)
415 let statusline .= '%#TabLine' . (i % 2 == 0 ? 'Fill' : 'Sel') . '#' . string(i)[0]
416 endfor
417 let &statusline = statusline
418 redrawstatus
419 set statusline&
420 delfunc StatusLabel
421
422
Bram Moolenaar300af822017-03-06 20:28:10 +0100423 " Check statusline in current and non-current window
424 " with the 'fillchars' option.
425 set fillchars=stl:^,stlnc:=,vert:\|,fold:-,diff:-
426 vsplit
427 set statusline=x%=y
428 call assert_match('^x^\+y^x=\+y$', s:get_statusline())
429 set fillchars&
430 close
431
432 %bw!
433 call delete('Xstatusline')
434 set statusline&
435 set laststatus&
436 set splitbelow&
437endfunc
Bram Moolenaardee50a52019-11-30 15:05:22 +0100438
439func Test_statusline_visual()
440 func CallWordcount()
441 call wordcount()
442 endfunc
443 new x1
444 setl statusline=count=%{CallWordcount()}
445 " buffer must not be empty
446 call setline(1, 'hello')
447
448 " window with more lines than x1
449 new x2
450 call setline(1, range(10))
451 $
452 " Visual mode in line below liast line in x1 should not give ml_get error
453 call feedkeys("\<C-V>", "xt")
454 redraw
455
456 delfunc CallWordcount
457 bwipe! x1
458 bwipe! x2
459endfunc
Bram Moolenaardbe5d362020-02-08 18:35:31 +0100460
461func Test_statusline_removed_group()
462 CheckScreendump
463
464 let lines =<< trim END
465 scriptencoding utf-8
466 set laststatus=2
467 let &statusline = '%#StatColorHi2#%(✓%#StatColorHi2#%) Q≡'
468 END
469 call writefile(lines, 'XTest_statusline')
470
471 let buf = RunVimInTerminal('-S XTest_statusline', {'rows': 10, 'cols': 50})
Bram Moolenaardbe5d362020-02-08 18:35:31 +0100472 call VerifyScreenDump(buf, 'Test_statusline_1', {})
473
474 " clean up
475 call StopVimInTerminal(buf)
476 call delete('XTest_statusline')
477endfunc
Bram Moolenaar832adf92020-06-25 19:01:36 +0200478
Bram Moolenaarce0b7572021-04-01 18:47:14 +0200479func Test_statusline_using_mode()
480 CheckScreendump
481
482 let lines =<< trim END
Bram Moolenaard8db8382021-04-08 18:27:53 +0200483 setlocal statusline=-%{mode()}-
484 split
485 setlocal statusline=+%{mode()}+
Bram Moolenaarce0b7572021-04-01 18:47:14 +0200486 END
487 call writefile(lines, 'XTest_statusline')
488
Bram Moolenaard8db8382021-04-08 18:27:53 +0200489 let buf = RunVimInTerminal('-S XTest_statusline', {'rows': 7, 'cols': 50})
Bram Moolenaarce0b7572021-04-01 18:47:14 +0200490 call VerifyScreenDump(buf, 'Test_statusline_mode_1', {})
491
492 call term_sendkeys(buf, ":")
493 call VerifyScreenDump(buf, 'Test_statusline_mode_2', {})
494
495 " clean up
Bram Moolenaard8db8382021-04-08 18:27:53 +0200496 call term_sendkeys(buf, "close\<CR>")
Bram Moolenaarce0b7572021-04-01 18:47:14 +0200497 call StopVimInTerminal(buf)
498 call delete('XTest_statusline')
499endfunc
500
Bram Moolenaar668008b2020-10-01 19:06:35 +0200501func Test_statusline_after_split_vsplit()
502 only
503
504 " Make the status line of each window show the window number.
505 set ls=2 stl=%{winnr()}
506
507 split | redraw
508 vsplit | redraw
509
510 " The status line of the third window should read '3' here.
511 call assert_equal('3', nr2char(screenchar(&lines - 1, 1)))
512
513 only
514 set ls& stl&
515endfunc
516
Bram Moolenaar008bff92021-03-04 21:55:58 +0100517" Test using a multibyte character for 'stl' and 'stlnc' items in 'fillchars'
518" with a custom 'statusline'
519func Test_statusline_mbyte_fillchar()
520 only
521 set laststatus=2
522 set fillchars=vert:\|,fold:-,stl:━,stlnc:═
523 set statusline=a%=b
524 call assert_match('^a\+━\+b$', s:get_statusline())
525 vnew
526 call assert_match('^a\+━\+b━a\+═\+b$', s:get_statusline())
527 wincmd w
528 call assert_match('^a\+═\+b═a\+━\+b$', s:get_statusline())
529 set statusline& fillchars& laststatus&
530 %bw!
531endfunc
Bram Moolenaar668008b2020-10-01 19:06:35 +0200532
Bram Moolenaar826bfe42021-10-08 18:39:28 +0100533" Used to write beyond allocated memory. This assumes MAXPATHL is 4096 bytes.
534func Test_statusline_verylong_filename()
535 let fname = repeat('x', 4090)
536 exe "new " .. fname
537 set buftype=help
538 set previewwindow
539 redraw
540 bwipe!
541endfunc
542
LemonBoy57ff5262022-05-09 21:03:47 +0100543func Test_statusline_highlight_truncate()
544 CheckScreendump
545
546 let lines =<< trim END
547 set laststatus=2
548 hi! link User1 Directory
549 hi! link User2 ErrorMsg
550 set statusline=%.5(%1*ABC%2*DEF%1*GHI%)
551 END
552 call writefile(lines, 'XTest_statusline')
553
554 let buf = RunVimInTerminal('-S XTest_statusline', {'rows': 6})
555 call VerifyScreenDump(buf, 'Test_statusline_hl', {})
556
557 call StopVimInTerminal(buf)
558 call delete('XTest_statusline')
559endfunc
560
Bram Moolenaar832adf92020-06-25 19:01:36 +0200561" vim: shiftwidth=2 sts=2 expandtab