blob: 22fd78cdefcc39263181cbd0708e25e19be8c984 [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())
Yegappan Lakshmanan3ec78f92023-02-11 11:15:25 +0000234 set statusline=foo%=bar%=baz
235 call assert_match('^foo\s\+bar\s\+baz\s*$', s:get_statusline())
236 set statusline=foo%=bar%=baz%=qux
237 call assert_match('^foo\s\+bar\s\+baz\s\+qux\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100238
239 " Test min/max width, leading zeroes, left/right justify.
240 set statusline=%04B
Bram Moolenaar316c1672019-04-14 13:23:40 +0200241 call cursor(9000, 1)
242 call assert_match('^0039\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100243 set statusline=#%4B#
Bram Moolenaar316c1672019-04-14 13:23:40 +0200244 call assert_match('^# 39#\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100245 set statusline=#%-4B#
Bram Moolenaar316c1672019-04-14 13:23:40 +0200246 call assert_match('^#39 #\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100247 set statusline=%.6f
248 call assert_match('^<sline\s*$', s:get_statusline())
249
250 " %<: Where to truncate.
Bram Moolenaar316c1672019-04-14 13:23:40 +0200251 " First check with when %< should not truncate with many columns
252 exe 'set statusline=a%<b' . repeat('c', &columns - 3) . 'd'
253 call assert_match('^abc\+d$', s:get_statusline())
254 exe 'set statusline=a' . repeat('b', &columns - 2) . '%<c'
255 call assert_match('^ab\+c$', s:get_statusline())
256 " Then check when %< should truncate when there with too few columns.
257 exe 'set statusline=a%<b' . repeat('c', &columns - 2) . 'd'
258 call assert_match('^a<c\+d$', s:get_statusline())
259 exe 'set statusline=a' . repeat('b', &columns - 1) . '%<c'
260 call assert_match('^ab\+>$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100261
262 "%{: Evaluate expression between '%{' and '}' and substitute result.
263 syntax on
Bram Moolenaar1c6fd1e2019-05-23 22:11:59 +0200264 let s:expected_curbuf = string(bufnr(''))
265 let s:expected_curwin = string(win_getid())
Bram Moolenaar300af822017-03-06 20:28:10 +0100266 set statusline=%{SyntaxItem()}
267 call assert_match('^vimNumber\s*$', s:get_statusline())
268 s/^/"/
269 call assert_match('^vimLineComment\s*$', s:get_statusline())
270 syntax off
271
Dominique Pelle81b573d2022-03-22 21:14:55 +0000272 "%{%expr%}: evaluates expressions present in result of expr
shadmansaleh30e3de22021-05-15 17:23:28 +0200273 func! Inner_eval()
274 return '%n some other text'
275 endfunc
276 func! Outer_eval()
277 return 'some text %{%Inner_eval()%}'
278 endfunc
279 set statusline=%{%Outer_eval()%}
280 call assert_match('^some text ' . bufnr() . ' some other text\s*$', s:get_statusline())
281 delfunc Inner_eval
282 delfunc Outer_eval
283
284 "%{%expr%}: Doesn't get stuck in recursion
285 func! Recurse_eval()
286 return '%{%Recurse_eval()%}'
287 endfunc
288 set statusline=%{%Recurse_eval()%}
289 call assert_match('^%{%Recurse_eval()%}\s*$', s:get_statusline())
290 delfunc Recurse_eval
291
Bram Moolenaar300af822017-03-06 20:28:10 +0100292 "%(: Start of item group.
293 set statusline=ab%(cd%q%)de
294 call assert_match('^abde\s*$', s:get_statusline())
295 copen
Bram Moolenaar1ef9bbe2017-06-17 20:08:20 +0200296 call assert_match('^abcd\[Quickfix List]de\s*$', s:get_statusline())
Bram Moolenaar300af822017-03-06 20:28:10 +0100297 cclose
298
299 " %#: Set highlight group. The name must follow and then a # again.
300 set statusline=ab%#Todo#cd%#Error#ef
301 call assert_match('^abcdef\s*$', s:get_statusline())
302 let sa1=screenattr(&lines - 1, 1)
303 let sa2=screenattr(&lines - 1, 3)
304 let sa3=screenattr(&lines - 1, 5)
305 call assert_notequal(sa1, sa2)
306 call assert_notequal(sa1, sa3)
307 call assert_notequal(sa2, sa3)
308 call assert_equal(sa1, screenattr(&lines - 1, 2))
309 call assert_equal(sa2, screenattr(&lines - 1, 4))
310 call assert_equal(sa3, screenattr(&lines - 1, 6))
311 call assert_equal(sa3, screenattr(&lines - 1, 7))
312
313 " %*: Set highlight group to User{N}
314 set statusline=a%1*b%0*c
315 call assert_match('^abc\s*$', s:get_statusline())
316 let sa1=screenattr(&lines - 1, 1)
317 let sa2=screenattr(&lines - 1, 2)
318 let sa3=screenattr(&lines - 1, 3)
319 call assert_equal(sa1, sa3)
320 call assert_notequal(sa1, sa2)
321
Bram Moolenaar6b89dbb2017-10-22 14:22:16 +0200322 " An empty group that contains highlight changes
323 let g:a = ''
324 set statusline=ab%(cd%1*%{g:a}%*%)de
325 call assert_match('^abde\s*$', s:get_statusline())
326 let sa1=screenattr(&lines - 1, 1)
327 let sa2=screenattr(&lines - 1, 4)
328 call assert_equal(sa1, sa2)
329 let g:a = 'X'
330 call assert_match('^abcdXde\s*$', s:get_statusline())
331 let sa1=screenattr(&lines - 1, 1)
332 let sa2=screenattr(&lines - 1, 5)
333 let sa3=screenattr(&lines - 1, 7)
334 call assert_equal(sa1, sa3)
335 call assert_notequal(sa1, sa2)
336
337 let g:a = ''
338 set statusline=ab%1*%(cd%*%{g:a}%1*%)de
339 call assert_match('^abde\s*$', s:get_statusline())
340 let sa1=screenattr(&lines - 1, 1)
341 let sa2=screenattr(&lines - 1, 4)
342 call assert_notequal(sa1, sa2)
343 let g:a = 'X'
344 call assert_match('^abcdXde\s*$', s:get_statusline())
345 let sa1=screenattr(&lines - 1, 1)
346 let sa2=screenattr(&lines - 1, 3)
347 let sa3=screenattr(&lines - 1, 5)
348 let sa4=screenattr(&lines - 1, 7)
349 call assert_notequal(sa1, sa2)
350 call assert_equal(sa1, sa3)
351 call assert_equal(sa2, sa4)
352
353 " An empty group that contains highlight changes and doesn't reset them
354 let g:a = ''
355 set statusline=ab%(cd%1*%{g:a}%)de
356 call assert_match('^abcdde\s*$', s:get_statusline())
357 let sa1=screenattr(&lines - 1, 1)
358 let sa2=screenattr(&lines - 1, 5)
359 call assert_notequal(sa1, sa2)
360 let g:a = 'X'
361 call assert_match('^abcdXde\s*$', s:get_statusline())
362 let sa1=screenattr(&lines - 1, 1)
363 let sa2=screenattr(&lines - 1, 5)
364 let sa3=screenattr(&lines - 1, 7)
365 call assert_notequal(sa1, sa2)
366 call assert_equal(sa2, sa3)
367
368 let g:a = ''
369 set statusline=ab%1*%(cd%*%{g:a}%)de
370 call assert_match('^abcdde\s*$', s:get_statusline())
371 let sa1=screenattr(&lines - 1, 1)
372 let sa2=screenattr(&lines - 1, 3)
373 let sa3=screenattr(&lines - 1, 5)
374 call assert_notequal(sa1, sa2)
375 call assert_equal(sa1, sa3)
376 let g:a = 'X'
377 call assert_match('^abcdXde\s*$', s:get_statusline())
378 let sa1=screenattr(&lines - 1, 1)
379 let sa2=screenattr(&lines - 1, 3)
380 let sa3=screenattr(&lines - 1, 5)
381 let sa4=screenattr(&lines - 1, 7)
382 call assert_notequal(sa1, sa2)
383 call assert_equal(sa1, sa3)
384 call assert_equal(sa1, sa4)
385
Bram Moolenaar235dddf2017-10-26 18:21:24 +0200386 let g:a = ''
387 set statusline=%#Error#{%(\ %{g:a}\ %)}
388 call assert_match('^{}\s*$', s:get_statusline())
389 let g:a = 'X'
390 call assert_match('^{ X }\s*$', s:get_statusline())
391
Bram Moolenaar300af822017-03-06 20:28:10 +0100392 " %%: a percent sign.
393 set statusline=10%%
394 call assert_match('^10%\s*$', s:get_statusline())
395
396 " %!: evaluated expression is used as the option value
397 set statusline=%!2*3+1
398 call assert_match('7\s*$', s:get_statusline())
399
Bram Moolenaar1c6fd1e2019-05-23 22:11:59 +0200400 func GetNested()
401 call assert_equal(string(win_getid()), g:actual_curwin)
402 call assert_equal(string(bufnr('')), g:actual_curbuf)
403 return 'nested'
404 endfunc
405 func GetStatusLine()
406 call assert_equal(win_getid(), g:statusline_winid)
407 return 'the %{GetNested()} line'
408 endfunc
409 set statusline=%!GetStatusLine()
410 call assert_match('the nested line', s:get_statusline())
411 call assert_false(exists('g:actual_curwin'))
412 call assert_false(exists('g:actual_curbuf'))
413 call assert_false(exists('g:statusline_winid'))
414 delfunc GetNested
415 delfunc GetStatusLine
416
Bram Moolenaar8133cc62020-10-26 21:05:27 +0100417 " Test statusline works with 80+ items
418 function! StatusLabel()
419 redrawstatus
Bram Moolenaar94722c52023-01-28 19:19:03 +0000420 return '[label]'
Bram Moolenaar8133cc62020-10-26 21:05:27 +0100421 endfunc
422 let statusline = '%{StatusLabel()}'
423 for i in range(150)
424 let statusline .= '%#TabLine' . (i % 2 == 0 ? 'Fill' : 'Sel') . '#' . string(i)[0]
425 endfor
426 let &statusline = statusline
427 redrawstatus
428 set statusline&
429 delfunc StatusLabel
430
431
Bram Moolenaar300af822017-03-06 20:28:10 +0100432 " Check statusline in current and non-current window
433 " with the 'fillchars' option.
434 set fillchars=stl:^,stlnc:=,vert:\|,fold:-,diff:-
435 vsplit
436 set statusline=x%=y
437 call assert_match('^x^\+y^x=\+y$', s:get_statusline())
438 set fillchars&
439 close
440
441 %bw!
442 call delete('Xstatusline')
443 set statusline&
Bram Moolenaar300af822017-03-06 20:28:10 +0100444 set splitbelow&
445endfunc
Bram Moolenaardee50a52019-11-30 15:05:22 +0100446
Bram Moolenaar7b17eb42023-01-04 14:31:49 +0000447func Test_statusline_trailing_percent_zero()
448 " this was causing illegal memory access
449 set laststatus=2 stl=%!%0
450 call assert_fails('redraw', 'E15: Invalid expression: "%0"')
451 set laststatus& stl&
452endfunc
453
Bram Moolenaardee50a52019-11-30 15:05:22 +0100454func Test_statusline_visual()
455 func CallWordcount()
456 call wordcount()
457 endfunc
458 new x1
459 setl statusline=count=%{CallWordcount()}
460 " buffer must not be empty
461 call setline(1, 'hello')
462
463 " window with more lines than x1
464 new x2
465 call setline(1, range(10))
466 $
467 " Visual mode in line below liast line in x1 should not give ml_get error
468 call feedkeys("\<C-V>", "xt")
469 redraw
470
471 delfunc CallWordcount
472 bwipe! x1
473 bwipe! x2
474endfunc
Bram Moolenaardbe5d362020-02-08 18:35:31 +0100475
476func Test_statusline_removed_group()
477 CheckScreendump
478
479 let lines =<< trim END
480 scriptencoding utf-8
481 set laststatus=2
482 let &statusline = '%#StatColorHi2#%(✓%#StatColorHi2#%) Q≡'
483 END
Bram Moolenaar56564962022-10-10 22:39:42 +0100484 call writefile(lines, 'XTest_statusline', 'D')
Bram Moolenaardbe5d362020-02-08 18:35:31 +0100485
486 let buf = RunVimInTerminal('-S XTest_statusline', {'rows': 10, 'cols': 50})
Bram Moolenaardbe5d362020-02-08 18:35:31 +0100487 call VerifyScreenDump(buf, 'Test_statusline_1', {})
488
489 " clean up
490 call StopVimInTerminal(buf)
Bram Moolenaardbe5d362020-02-08 18:35:31 +0100491endfunc
Bram Moolenaar832adf92020-06-25 19:01:36 +0200492
Bram Moolenaarce0b7572021-04-01 18:47:14 +0200493func Test_statusline_using_mode()
494 CheckScreendump
495
496 let lines =<< trim END
Bram Moolenaard8db8382021-04-08 18:27:53 +0200497 setlocal statusline=-%{mode()}-
498 split
499 setlocal statusline=+%{mode()}+
Bram Moolenaarce0b7572021-04-01 18:47:14 +0200500 END
Bram Moolenaar56564962022-10-10 22:39:42 +0100501 call writefile(lines, 'XTest_statusline', 'D')
Bram Moolenaarce0b7572021-04-01 18:47:14 +0200502
Bram Moolenaard8db8382021-04-08 18:27:53 +0200503 let buf = RunVimInTerminal('-S XTest_statusline', {'rows': 7, 'cols': 50})
Bram Moolenaarce0b7572021-04-01 18:47:14 +0200504 call VerifyScreenDump(buf, 'Test_statusline_mode_1', {})
505
506 call term_sendkeys(buf, ":")
507 call VerifyScreenDump(buf, 'Test_statusline_mode_2', {})
508
509 " clean up
Bram Moolenaard8db8382021-04-08 18:27:53 +0200510 call term_sendkeys(buf, "close\<CR>")
Bram Moolenaarce0b7572021-04-01 18:47:14 +0200511 call StopVimInTerminal(buf)
Bram Moolenaarce0b7572021-04-01 18:47:14 +0200512endfunc
513
Bram Moolenaar668008b2020-10-01 19:06:35 +0200514func Test_statusline_after_split_vsplit()
515 only
516
517 " Make the status line of each window show the window number.
518 set ls=2 stl=%{winnr()}
519
520 split | redraw
521 vsplit | redraw
522
523 " The status line of the third window should read '3' here.
524 call assert_equal('3', nr2char(screenchar(&lines - 1, 1)))
525
526 only
527 set ls& stl&
528endfunc
529
Bram Moolenaar008bff92021-03-04 21:55:58 +0100530" Test using a multibyte character for 'stl' and 'stlnc' items in 'fillchars'
531" with a custom 'statusline'
532func Test_statusline_mbyte_fillchar()
533 only
Bram Moolenaar008bff92021-03-04 21:55:58 +0100534 set fillchars=vert:\|,fold:-,stl:━,stlnc:═
535 set statusline=a%=b
536 call assert_match('^a\+━\+b$', s:get_statusline())
537 vnew
538 call assert_match('^a\+━\+b━a\+═\+b$', s:get_statusline())
539 wincmd w
540 call assert_match('^a\+═\+b═a\+━\+b$', s:get_statusline())
zeertzjqbb404f52022-07-23 06:25:29 +0100541 set statusline& fillchars&
Bram Moolenaar008bff92021-03-04 21:55:58 +0100542 %bw!
543endfunc
Bram Moolenaar668008b2020-10-01 19:06:35 +0200544
Bram Moolenaar826bfe42021-10-08 18:39:28 +0100545" Used to write beyond allocated memory. This assumes MAXPATHL is 4096 bytes.
546func Test_statusline_verylong_filename()
547 let fname = repeat('x', 4090)
548 exe "new " .. fname
549 set buftype=help
550 set previewwindow
551 redraw
552 bwipe!
553endfunc
554
LemonBoy57ff5262022-05-09 21:03:47 +0100555func Test_statusline_highlight_truncate()
556 CheckScreendump
557
558 let lines =<< trim END
559 set laststatus=2
560 hi! link User1 Directory
561 hi! link User2 ErrorMsg
562 set statusline=%.5(%1*ABC%2*DEF%1*GHI%)
563 END
Bram Moolenaar56564962022-10-10 22:39:42 +0100564 call writefile(lines, 'XTest_statusline', 'D')
LemonBoy57ff5262022-05-09 21:03:47 +0100565
566 let buf = RunVimInTerminal('-S XTest_statusline', {'rows': 6})
567 call VerifyScreenDump(buf, 'Test_statusline_hl', {})
568
569 call StopVimInTerminal(buf)
LemonBoy57ff5262022-05-09 21:03:47 +0100570endfunc
571
Luuk van Baalba936f62022-12-15 13:15:39 +0000572func Test_statusline_showcmd()
573 CheckScreendump
574
575 let lines =<< trim END
zeertzjq378e6c02023-01-14 11:46:49 +0000576 func MyStatusLine()
577 return '%S'
578 endfunc
579
Luuk van Baalba936f62022-12-15 13:15:39 +0000580 set laststatus=2
zeertzjq378e6c02023-01-14 11:46:49 +0000581 set statusline=%!MyStatusLine()
Luuk van Baalba936f62022-12-15 13:15:39 +0000582 set showcmdloc=statusline
583 call setline(1, ['a', 'b', 'c'])
zeertzjq378e6c02023-01-14 11:46:49 +0000584 set foldopen+=jump
585 1,2fold
586 3
Luuk van Baalba936f62022-12-15 13:15:39 +0000587 END
588 call writefile(lines, 'XTest_statusline', 'D')
589
590 let buf = RunVimInTerminal('-S XTest_statusline', {'rows': 6})
zeertzjq378e6c02023-01-14 11:46:49 +0000591
592 call term_sendkeys(buf, "g")
Luuk van Baalba936f62022-12-15 13:15:39 +0000593 call VerifyScreenDump(buf, 'Test_statusline_showcmd_1', {})
594
zeertzjq378e6c02023-01-14 11:46:49 +0000595 " typing "gg" should open the fold
596 call term_sendkeys(buf, "g")
Luuk van Baalba936f62022-12-15 13:15:39 +0000597 call VerifyScreenDump(buf, 'Test_statusline_showcmd_2', {})
598
zeertzjq378e6c02023-01-14 11:46:49 +0000599 call term_sendkeys(buf, "\<C-V>Gl")
Luuk van Baalba936f62022-12-15 13:15:39 +0000600 call VerifyScreenDump(buf, 'Test_statusline_showcmd_3', {})
zeertzjq378e6c02023-01-14 11:46:49 +0000601
602 call term_sendkeys(buf, "\<Esc>1234")
603 call VerifyScreenDump(buf, 'Test_statusline_showcmd_4', {})
604
605 call term_sendkeys(buf, "\<Esc>:set statusline=\<CR>")
606 call term_sendkeys(buf, ":\<CR>")
607 call term_sendkeys(buf, "1234")
608 call VerifyScreenDump(buf, 'Test_statusline_showcmd_5', {})
609
610 call StopVimInTerminal(buf)
Luuk van Baalba936f62022-12-15 13:15:39 +0000611endfunc
612
Christian Brabandt6a650bf2023-11-08 21:23:29 +0100613func Test_statusline_highlight_group_cleared()
614 CheckScreendump
615
616 " the laststatus option is there to prevent
617 " the code-style test from complaining about
618 " trailing whitespace
619 let lines =<< trim END
620 set fillchars=stl:\ ,stlnc:\ laststatus=2
621 split
622 hi clear StatusLine
623 hi clear StatusLineNC
624 END
625 call writefile(lines, 'XTest_statusline_stl', 'D')
626
627 let buf = RunVimInTerminal('-S XTest_statusline_stl', {})
628
629 call VerifyScreenDump(buf, 'Test_statusline_stl_1', {})
630
631 call StopVimInTerminal(buf)
632endfunc
633
Bram Moolenaar832adf92020-06-25 19:01:36 +0200634" vim: shiftwidth=2 sts=2 expandtab