blob: 23613bfed37b9813642fb970b603e7758eaf4f0b [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
223
224 " %y: Type of file in the buffer, e.g., "[vim]". See 'filetype'.
225 " %Y: Type of file in the buffer, e.g., ",VIM". See 'filetype'.
226 set statusline=%y\ %Y
227 call assert_match('^\s*$', s:get_statusline())
228 setfiletype vim
229 call assert_match('^\[vim\] VIM\s*$', s:get_statusline())
230
231 " %=: Separation point between left and right aligned items.
232 set statusline=foo%=bar
233 call assert_match('^foo\s\+bar\s*$', s:get_statusline())
234
235 " Test min/max width, leading zeroes, left/right justify.
236 set statusline=%04B
Bram Moolenaar316c1672019-04-14 13:23:40 +0200237 call cursor(9000, 1)
238 call assert_match('^0039\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100239 set statusline=#%4B#
Bram Moolenaar316c1672019-04-14 13:23:40 +0200240 call assert_match('^# 39#\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100241 set statusline=#%-4B#
Bram Moolenaar316c1672019-04-14 13:23:40 +0200242 call assert_match('^#39 #\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100243 set statusline=%.6f
244 call assert_match('^<sline\s*$', s:get_statusline())
245
246 " %<: Where to truncate.
Bram Moolenaar316c1672019-04-14 13:23:40 +0200247 " First check with when %< should not truncate with many columns
248 exe 'set statusline=a%<b' . repeat('c', &columns - 3) . 'd'
249 call assert_match('^abc\+d$', s:get_statusline())
250 exe 'set statusline=a' . repeat('b', &columns - 2) . '%<c'
251 call assert_match('^ab\+c$', s:get_statusline())
252 " Then check when %< should truncate when there with too few columns.
253 exe 'set statusline=a%<b' . repeat('c', &columns - 2) . 'd'
254 call assert_match('^a<c\+d$', s:get_statusline())
255 exe 'set statusline=a' . repeat('b', &columns - 1) . '%<c'
256 call assert_match('^ab\+>$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100257
258 "%{: Evaluate expression between '%{' and '}' and substitute result.
259 syntax on
Bram Moolenaar1c6fd1e2019-05-23 22:11:59 +0200260 let s:expected_curbuf = string(bufnr(''))
261 let s:expected_curwin = string(win_getid())
Bram Moolenaar300af822017-03-06 20:28:10 +0100262 set statusline=%{SyntaxItem()}
263 call assert_match('^vimNumber\s*$', s:get_statusline())
264 s/^/"/
265 call assert_match('^vimLineComment\s*$', s:get_statusline())
266 syntax off
267
Dominique Pelle81b573d2022-03-22 21:14:55 +0000268 "%{%expr%}: evaluates expressions present in result of expr
shadmansaleh30e3de22021-05-15 17:23:28 +0200269 func! Inner_eval()
270 return '%n some other text'
271 endfunc
272 func! Outer_eval()
273 return 'some text %{%Inner_eval()%}'
274 endfunc
275 set statusline=%{%Outer_eval()%}
276 call assert_match('^some text ' . bufnr() . ' some other text\s*$', s:get_statusline())
277 delfunc Inner_eval
278 delfunc Outer_eval
279
280 "%{%expr%}: Doesn't get stuck in recursion
281 func! Recurse_eval()
282 return '%{%Recurse_eval()%}'
283 endfunc
284 set statusline=%{%Recurse_eval()%}
285 call assert_match('^%{%Recurse_eval()%}\s*$', s:get_statusline())
286 delfunc Recurse_eval
287
Bram Moolenaar300af822017-03-06 20:28:10 +0100288 "%(: Start of item group.
289 set statusline=ab%(cd%q%)de
290 call assert_match('^abde\s*$', s:get_statusline())
291 copen
Bram Moolenaar1ef9bbe2017-06-17 20:08:20 +0200292 call assert_match('^abcd\[Quickfix List]de\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100293 cclose
294
295 " %#: Set highlight group. The name must follow and then a # again.
296 set statusline=ab%#Todo#cd%#Error#ef
297 call assert_match('^abcdef\s*$', s:get_statusline())
298 let sa1=screenattr(&lines - 1, 1)
299 let sa2=screenattr(&lines - 1, 3)
300 let sa3=screenattr(&lines - 1, 5)
301 call assert_notequal(sa1, sa2)
302 call assert_notequal(sa1, sa3)
303 call assert_notequal(sa2, sa3)
304 call assert_equal(sa1, screenattr(&lines - 1, 2))
305 call assert_equal(sa2, screenattr(&lines - 1, 4))
306 call assert_equal(sa3, screenattr(&lines - 1, 6))
307 call assert_equal(sa3, screenattr(&lines - 1, 7))
308
309 " %*: Set highlight group to User{N}
310 set statusline=a%1*b%0*c
311 call assert_match('^abc\s*$', s:get_statusline())
312 let sa1=screenattr(&lines - 1, 1)
313 let sa2=screenattr(&lines - 1, 2)
314 let sa3=screenattr(&lines - 1, 3)
315 call assert_equal(sa1, sa3)
316 call assert_notequal(sa1, sa2)
317
Bram Moolenaar6b89dbb2017-10-22 14:22:16 +0200318 " An empty group that contains highlight changes
319 let g:a = ''
320 set statusline=ab%(cd%1*%{g:a}%*%)de
321 call assert_match('^abde\s*$', s:get_statusline())
322 let sa1=screenattr(&lines - 1, 1)
323 let sa2=screenattr(&lines - 1, 4)
324 call assert_equal(sa1, sa2)
325 let g:a = 'X'
326 call assert_match('^abcdXde\s*$', s:get_statusline())
327 let sa1=screenattr(&lines - 1, 1)
328 let sa2=screenattr(&lines - 1, 5)
329 let sa3=screenattr(&lines - 1, 7)
330 call assert_equal(sa1, sa3)
331 call assert_notequal(sa1, sa2)
332
333 let g:a = ''
334 set statusline=ab%1*%(cd%*%{g:a}%1*%)de
335 call assert_match('^abde\s*$', s:get_statusline())
336 let sa1=screenattr(&lines - 1, 1)
337 let sa2=screenattr(&lines - 1, 4)
338 call assert_notequal(sa1, sa2)
339 let g:a = 'X'
340 call assert_match('^abcdXde\s*$', s:get_statusline())
341 let sa1=screenattr(&lines - 1, 1)
342 let sa2=screenattr(&lines - 1, 3)
343 let sa3=screenattr(&lines - 1, 5)
344 let sa4=screenattr(&lines - 1, 7)
345 call assert_notequal(sa1, sa2)
346 call assert_equal(sa1, sa3)
347 call assert_equal(sa2, sa4)
348
349 " An empty group that contains highlight changes and doesn't reset them
350 let g:a = ''
351 set statusline=ab%(cd%1*%{g:a}%)de
352 call assert_match('^abcdde\s*$', s:get_statusline())
353 let sa1=screenattr(&lines - 1, 1)
354 let sa2=screenattr(&lines - 1, 5)
355 call assert_notequal(sa1, sa2)
356 let g:a = 'X'
357 call assert_match('^abcdXde\s*$', s:get_statusline())
358 let sa1=screenattr(&lines - 1, 1)
359 let sa2=screenattr(&lines - 1, 5)
360 let sa3=screenattr(&lines - 1, 7)
361 call assert_notequal(sa1, sa2)
362 call assert_equal(sa2, sa3)
363
364 let g:a = ''
365 set statusline=ab%1*%(cd%*%{g:a}%)de
366 call assert_match('^abcdde\s*$', s:get_statusline())
367 let sa1=screenattr(&lines - 1, 1)
368 let sa2=screenattr(&lines - 1, 3)
369 let sa3=screenattr(&lines - 1, 5)
370 call assert_notequal(sa1, sa2)
371 call assert_equal(sa1, sa3)
372 let g:a = 'X'
373 call assert_match('^abcdXde\s*$', s:get_statusline())
374 let sa1=screenattr(&lines - 1, 1)
375 let sa2=screenattr(&lines - 1, 3)
376 let sa3=screenattr(&lines - 1, 5)
377 let sa4=screenattr(&lines - 1, 7)
378 call assert_notequal(sa1, sa2)
379 call assert_equal(sa1, sa3)
380 call assert_equal(sa1, sa4)
381
Bram Moolenaar235dddf2017-10-26 18:21:24 +0200382 let g:a = ''
383 set statusline=%#Error#{%(\ %{g:a}\ %)}
384 call assert_match('^{}\s*$', s:get_statusline())
385 let g:a = 'X'
386 call assert_match('^{ X }\s*$', s:get_statusline())
387
Bram Moolenaar300af822017-03-06 20:28:10 +0100388 " %%: a percent sign.
389 set statusline=10%%
390 call assert_match('^10%\s*$', s:get_statusline())
391
392 " %!: evaluated expression is used as the option value
393 set statusline=%!2*3+1
394 call assert_match('7\s*$', s:get_statusline())
395
Bram Moolenaar1c6fd1e2019-05-23 22:11:59 +0200396 func GetNested()
397 call assert_equal(string(win_getid()), g:actual_curwin)
398 call assert_equal(string(bufnr('')), g:actual_curbuf)
399 return 'nested'
400 endfunc
401 func GetStatusLine()
402 call assert_equal(win_getid(), g:statusline_winid)
403 return 'the %{GetNested()} line'
404 endfunc
405 set statusline=%!GetStatusLine()
406 call assert_match('the nested line', s:get_statusline())
407 call assert_false(exists('g:actual_curwin'))
408 call assert_false(exists('g:actual_curbuf'))
409 call assert_false(exists('g:statusline_winid'))
410 delfunc GetNested
411 delfunc GetStatusLine
412
Bram Moolenaar8133cc62020-10-26 21:05:27 +0100413 " Test statusline works with 80+ items
414 function! StatusLabel()
415 redrawstatus
416 return '[label]'
417 endfunc
418 let statusline = '%{StatusLabel()}'
419 for i in range(150)
420 let statusline .= '%#TabLine' . (i % 2 == 0 ? 'Fill' : 'Sel') . '#' . string(i)[0]
421 endfor
422 let &statusline = statusline
423 redrawstatus
424 set statusline&
425 delfunc StatusLabel
426
427
Bram Moolenaar300af822017-03-06 20:28:10 +0100428 " Check statusline in current and non-current window
429 " with the 'fillchars' option.
430 set fillchars=stl:^,stlnc:=,vert:\|,fold:-,diff:-
431 vsplit
432 set statusline=x%=y
433 call assert_match('^x^\+y^x=\+y$', s:get_statusline())
434 set fillchars&
435 close
436
437 %bw!
438 call delete('Xstatusline')
439 set statusline&
Bram Moolenaar300af822017-03-06 20:28:10 +0100440 set splitbelow&
441endfunc
Bram Moolenaardee50a52019-11-30 15:05:22 +0100442
Bram Moolenaar7b17eb42023-01-04 14:31:49 +0000443func Test_statusline_trailing_percent_zero()
444 " this was causing illegal memory access
445 set laststatus=2 stl=%!%0
446 call assert_fails('redraw', 'E15: Invalid expression: "%0"')
447 set laststatus& stl&
448endfunc
449
Bram Moolenaardee50a52019-11-30 15:05:22 +0100450func Test_statusline_visual()
451 func CallWordcount()
452 call wordcount()
453 endfunc
454 new x1
455 setl statusline=count=%{CallWordcount()}
456 " buffer must not be empty
457 call setline(1, 'hello')
458
459 " window with more lines than x1
460 new x2
461 call setline(1, range(10))
462 $
463 " Visual mode in line below liast line in x1 should not give ml_get error
464 call feedkeys("\<C-V>", "xt")
465 redraw
466
467 delfunc CallWordcount
468 bwipe! x1
469 bwipe! x2
470endfunc
Bram Moolenaardbe5d362020-02-08 18:35:31 +0100471
472func Test_statusline_removed_group()
473 CheckScreendump
474
475 let lines =<< trim END
476 scriptencoding utf-8
477 set laststatus=2
478 let &statusline = '%#StatColorHi2#%(✓%#StatColorHi2#%) Q≡'
479 END
Bram Moolenaar56564962022-10-10 22:39:42 +0100480 call writefile(lines, 'XTest_statusline', 'D')
Bram Moolenaardbe5d362020-02-08 18:35:31 +0100481
482 let buf = RunVimInTerminal('-S XTest_statusline', {'rows': 10, 'cols': 50})
Bram Moolenaardbe5d362020-02-08 18:35:31 +0100483 call VerifyScreenDump(buf, 'Test_statusline_1', {})
484
485 " clean up
486 call StopVimInTerminal(buf)
Bram Moolenaardbe5d362020-02-08 18:35:31 +0100487endfunc
Bram Moolenaar832adf92020-06-25 19:01:36 +0200488
Bram Moolenaarce0b7572021-04-01 18:47:14 +0200489func Test_statusline_using_mode()
490 CheckScreendump
491
492 let lines =<< trim END
Bram Moolenaard8db8382021-04-08 18:27:53 +0200493 setlocal statusline=-%{mode()}-
494 split
495 setlocal statusline=+%{mode()}+
Bram Moolenaarce0b7572021-04-01 18:47:14 +0200496 END
Bram Moolenaar56564962022-10-10 22:39:42 +0100497 call writefile(lines, 'XTest_statusline', 'D')
Bram Moolenaarce0b7572021-04-01 18:47:14 +0200498
Bram Moolenaard8db8382021-04-08 18:27:53 +0200499 let buf = RunVimInTerminal('-S XTest_statusline', {'rows': 7, 'cols': 50})
Bram Moolenaarce0b7572021-04-01 18:47:14 +0200500 call VerifyScreenDump(buf, 'Test_statusline_mode_1', {})
501
502 call term_sendkeys(buf, ":")
503 call VerifyScreenDump(buf, 'Test_statusline_mode_2', {})
504
505 " clean up
Bram Moolenaard8db8382021-04-08 18:27:53 +0200506 call term_sendkeys(buf, "close\<CR>")
Bram Moolenaarce0b7572021-04-01 18:47:14 +0200507 call StopVimInTerminal(buf)
Bram Moolenaarce0b7572021-04-01 18:47:14 +0200508endfunc
509
Bram Moolenaar668008b2020-10-01 19:06:35 +0200510func Test_statusline_after_split_vsplit()
511 only
512
513 " Make the status line of each window show the window number.
514 set ls=2 stl=%{winnr()}
515
516 split | redraw
517 vsplit | redraw
518
519 " The status line of the third window should read '3' here.
520 call assert_equal('3', nr2char(screenchar(&lines - 1, 1)))
521
522 only
523 set ls& stl&
524endfunc
525
Bram Moolenaar008bff92021-03-04 21:55:58 +0100526" Test using a multibyte character for 'stl' and 'stlnc' items in 'fillchars'
527" with a custom 'statusline'
528func Test_statusline_mbyte_fillchar()
529 only
Bram Moolenaar008bff92021-03-04 21:55:58 +0100530 set fillchars=vert:\|,fold:-,stl:━,stlnc:═
531 set statusline=a%=b
532 call assert_match('^a\+━\+b$', s:get_statusline())
533 vnew
534 call assert_match('^a\+━\+b━a\+═\+b$', s:get_statusline())
535 wincmd w
536 call assert_match('^a\+═\+b═a\+━\+b$', s:get_statusline())
zeertzjqbb404f52022-07-23 06:25:29 +0100537 set statusline& fillchars&
Bram Moolenaar008bff92021-03-04 21:55:58 +0100538 %bw!
539endfunc
Bram Moolenaar668008b2020-10-01 19:06:35 +0200540
Bram Moolenaar826bfe42021-10-08 18:39:28 +0100541" Used to write beyond allocated memory. This assumes MAXPATHL is 4096 bytes.
542func Test_statusline_verylong_filename()
543 let fname = repeat('x', 4090)
544 exe "new " .. fname
545 set buftype=help
546 set previewwindow
547 redraw
548 bwipe!
549endfunc
550
LemonBoy57ff5262022-05-09 21:03:47 +0100551func Test_statusline_highlight_truncate()
552 CheckScreendump
553
554 let lines =<< trim END
555 set laststatus=2
556 hi! link User1 Directory
557 hi! link User2 ErrorMsg
558 set statusline=%.5(%1*ABC%2*DEF%1*GHI%)
559 END
Bram Moolenaar56564962022-10-10 22:39:42 +0100560 call writefile(lines, 'XTest_statusline', 'D')
LemonBoy57ff5262022-05-09 21:03:47 +0100561
562 let buf = RunVimInTerminal('-S XTest_statusline', {'rows': 6})
563 call VerifyScreenDump(buf, 'Test_statusline_hl', {})
564
565 call StopVimInTerminal(buf)
LemonBoy57ff5262022-05-09 21:03:47 +0100566endfunc
567
Luuk van Baalba936f62022-12-15 13:15:39 +0000568func Test_statusline_showcmd()
569 CheckScreendump
570
571 let lines =<< trim END
572 set laststatus=2
573 set statusline=%S
574 set showcmdloc=statusline
575 call setline(1, ['a', 'b', 'c'])
576 END
577 call writefile(lines, 'XTest_statusline', 'D')
578
579 let buf = RunVimInTerminal('-S XTest_statusline', {'rows': 6})
580 call feedkeys("\<C-V>Gl", "xt")
581 call VerifyScreenDump(buf, 'Test_statusline_showcmd_1', {})
582
583 call feedkeys("\<Esc>1234", "xt")
584 call VerifyScreenDump(buf, 'Test_statusline_showcmd_2', {})
585
586 call feedkeys("\<Esc>:set statusline=\<CR>:\<CR>1234", "xt")
587 call VerifyScreenDump(buf, 'Test_statusline_showcmd_3', {})
588endfunc
589
Bram Moolenaar832adf92020-06-25 19:01:36 +0200590" vim: shiftwidth=2 sts=2 expandtab