1- function ! StatuslineWithCaughtError ()
1+ " Test 'statusline'
2+ "
3+ " Not tested yet:
4+ " %a
5+ " %N
6+ " %T
7+ " %X
8+ " %*
9+
10+ source view_util.vim
11+
12+ func s: get_statusline ()
13+ return ScreenLines (&lines - 1 , &columns )[0 ]
14+ endfunc
15+
16+ func StatuslineWithCaughtError ()
217 let s: func_in_statusline_called = 1
318 try
419 call eval (' unknown expression' )
520 catch
621 endtry
722 return ' '
8- endfunction
23+ endfunc
924
10- function ! StatuslineWithError ()
25+ func StatuslineWithError ()
1126 let s: func_in_statusline_called = 1
1227 call eval (' unknown expression' )
1328 return ' '
14- endfunction
29+ endfunc
1530
16- function ! Test_caught_error_in_statusline ()
31+ " Function used to display syntax group.
32+ func SyntaxItem ()
33+ return synIDattr (synID (line (" ." ),col (" ." ),1 )," name" )
34+ endfunc
35+
36+ func Test_caught_error_in_statusline ()
1737 let s: func_in_statusline_called = 0
1838 set laststatus = 2
1939 let statusline = ' %{StatuslineWithCaughtError()}'
@@ -22,9 +42,9 @@ function! Test_caught_error_in_statusline()
2242 call assert_true (s: func_in_statusline_called )
2343 call assert_equal (statusline , &statusline )
2444 set statusline =
25- endfunction
45+ endfunc
2646
27- function ! Test_statusline_will_be_disabled_with_error ()
47+ func Test_statusline_will_be_disabled_with_error ()
2848 let s: func_in_statusline_called = 0
2949 set laststatus = 2
3050 let statusline = ' %{StatuslineWithError()}'
@@ -36,4 +56,219 @@ function! Test_statusline_will_be_disabled_with_error()
3656 call assert_true (s: func_in_statusline_called )
3757 call assert_equal (' ' , &statusline )
3858 set statusline =
39- endfunction
59+ endfunc
60+
61+ func Test_statusline ()
62+ new Xstatusline
63+ only
64+ set laststatus = 2
65+ set splitbelow
66+ call setline (1 , range (1 , 200 ))
67+
68+ " %b: Value of character under cursor.
69+ " %B: As above, in hexadecimal.
70+ call cursor (180 , 2 )
71+ set statusline = % b ,% B
72+ call assert_match (' ^56,38\s*$' , s: get_statusline ())
73+
74+ " %o: Byte number in file of byte under cursor, first byte is 1.
75+ " %O: As above, in hexadecimal.
76+ set statusline = % o ,% O
77+ set fileformat = dos
78+ call assert_match (' ^789,315\s*$' , s: get_statusline ())
79+ set fileformat = mac
80+ call assert_match (' ^610,262\s*$' , s: get_statusline ())
81+ set fileformat = unix
82+ call assert_match (' ^610,262\s*$' , s: get_statusline ())
83+ set fileformat &
84+
85+ " %f: Path to the file in the buffer, as typed or relative to current dir.
86+ set statusline = % f
87+ call assert_match (' ^Xstatusline\s*$' , s: get_statusline ())
88+
89+ " %F: Full path to the file in the buffer.
90+ set statusline = % F
91+ call assert_match (' /testdir/Xstatusline\s*$' , s: get_statusline ())
92+
93+ " %h: Help buffer flag, text is "[help]".
94+ " %H: Help buffer flag, text is ",HLP".
95+ set statusline = % h ,% H
96+ call assert_match (' ^,\s*$' , s: get_statusline ())
97+ help
98+ call assert_match (' ^\[Help\],HLP\s*$' , s: get_statusline ())
99+ helpclose
100+
101+ " %k: Value of "b:keymap_name" or 'keymap'
102+ " when :lmap mappings are being used: <keymap>"
103+ set statusline = % k
104+ if has (' keymap' )
105+ set keymap = esperanto
106+ call assert_match (' ^<Eo>\s*$' , s: get_statusline ())
107+ set keymap &
108+ else
109+ call assert_match (' ^\s*$' , s: get_statusline ())
110+ endif
111+
112+ " %l: Line number.
113+ " %L: Number of line in buffer.
114+ " %c: Column number.
115+ set statusline = % l /% L,% c
116+ call assert_match (' ^180/200,2\s*$' , s: get_statusline ())
117+
118+ " %m: Modified flag, text is "[+]", "[-]" if 'modifiable' is off.
119+ " %M: Modified flag, text is ",+" or ",-".
120+ set statusline = % m % M
121+ call assert_match (' ^\[+\],+\s*$' , s: get_statusline ())
122+ set nomodifiable
123+ call assert_match (' ^\[+-\],+-\s*$' , s: get_statusline ())
124+ write
125+ call assert_match (' ^\[-\],-\s*$' , s: get_statusline ())
126+ set modifiable &
127+ call assert_match (' ^\s*$' , s: get_statusline ())
128+
129+ " %n: Buffer number.
130+ set statusline = % n
131+ call assert_match (' ^' .bufnr (' %' ).' \s*$' , s: get_statusline ())
132+
133+ " %p: Percentage through file in lines as in CTRL-G.
134+ " %P: Percentage through file of displayed window.
135+ set statusline = % p ,% P
136+ 0
137+ call assert_match (' ^0,Top\s*$' , s: get_statusline ())
138+ norm G
139+ call assert_match (' ^100,Bot\s*$' , s: get_statusline ())
140+ 180
141+ " Don't check the exact percentage as it depends on the window size
142+ call assert_match (' ^90,\(Top\|Bot\|\d\+%\)\s*$' , s: get_statusline ())
143+
144+ " %q: "[Quickfix List]", "[Location List]" or empty.
145+ set statusline = % q
146+ call assert_match (' ^\s*$' , s: get_statusline ())
147+ copen
148+ call assert_match (' ^\[Quickfix List\]\s*$' , s: get_statusline ())
149+ cclose
150+ lexpr getline (1 , 2 )
151+ lopen
152+ call assert_match (' ^\[Location List\]\s*$' , s: get_statusline ())
153+ lclose
154+
155+ " %r: Readonly flag, text is "[RO]".
156+ " %R: Readonly flag, text is ",RO".
157+ set statusline = % r ,% R
158+ call assert_match (' ^,\s*$' , s: get_statusline ())
159+ help
160+ call assert_match (' ^\[RO\],RO\s*$' , s: get_statusline ())
161+ helpclose
162+
163+ " %t: File name (tail) of file in the buffer.
164+ set statusline = % t
165+ call assert_match (' ^Xstatusline\s*$' , s: get_statusline ())
166+
167+ " %v: Virtual column number.
168+ " %V: Virtual column number as -{num}. Not displayed if equal to 'c'.
169+ call cursor (180 , 2 )
170+ set statusline = % v ,% V
171+ call assert_match (' ^2,\s*$' , s: get_statusline ())
172+ set virtualedit = all
173+ norm 10 |
174+ call assert_match (' ^10,-10\s*$' , s: get_statusline ())
175+ set virtualedit &
176+
177+ " %w: Preview window flag, text is "[Preview]".
178+ " %W: Preview window flag, text is ",PRV".
179+ set statusline = % w % W
180+ call assert_match (' ^\s*$' , s: get_statusline ())
181+ pedit
182+ wincmd j
183+ call assert_match (' ^\[Preview\],PRV\s*$' , s: get_statusline ())
184+ pclose
185+
186+ " %y: Type of file in the buffer, e.g., "[vim]". See 'filetype'.
187+ " %Y: Type of file in the buffer, e.g., ",VIM". See 'filetype'.
188+ set statusline = % y \ % Y
189+ call assert_match (' ^\s*$' , s: get_statusline ())
190+ setfiletype vim
191+ call assert_match (' ^\[vim\] VIM\s*$' , s: get_statusline ())
192+
193+ " %=: Separation point between left and right aligned items.
194+ set statusline = foo% = bar
195+ call assert_match (' ^foo\s\+bar\s*$' , s: get_statusline ())
196+
197+ " Test min/max width, leading zeroes, left/right justify.
198+ set statusline = % 04 B
199+ call cursor (180 , 2 )
200+ call assert_match (' ^0038\s*$' , s: get_statusline ())
201+ set statusline = #% 4 B#
202+ call assert_match (' ^# 38#\s*$' , s: get_statusline ())
203+ set statusline = #% -4 B#
204+ call assert_match (' ^#38 #\s*$' , s: get_statusline ())
205+ set statusline = % .6 f
206+ call assert_match (' ^<sline\s*$' , s: get_statusline ())
207+
208+ " %<: Where to truncate.
209+ exe ' set statusline=a%<b' . repeat (' c' , 1000 ) . ' d'
210+ call assert_match (' ^a<c*d$' , s: get_statusline ())
211+ exe ' set statusline=a' . repeat (' b' , 1000 ) . ' %<c'
212+ call assert_match (' ^ab*>$' , s: get_statusline ())
213+
214+ " %{: Evaluate expression between '%{' and '}' and substitute result.
215+ syntax on
216+ set statusline = % {SyntaxItem ()}
217+ call assert_match (' ^vimNumber\s*$' , s: get_statusline ())
218+ s /^/ " /
219+ call assert_match (' ^vimLineComment\s*$' , s: get_statusline ())
220+ syntax off
221+
222+ " %(: Start of item group.
223+ set statusline = ab % (cd % q % )de
224+ call assert_match (' ^abde\s*$' , s: get_statusline ())
225+ copen
226+ call assert_match (' ^abcd\[Quickfix List\1]de\s*$' , s: get_statusline ())
227+ cclose
228+
229+ " %#: Set highlight group. The name must follow and then a # again.
230+ set statusline = ab % #Todo #cd % #Error #ef
231+ call assert_match (' ^abcdef\s*$' , s: get_statusline ())
232+ let sa1= screenattr (&lines - 1 , 1 )
233+ let sa2= screenattr (&lines - 1 , 3 )
234+ let sa3= screenattr (&lines - 1 , 5 )
235+ call assert_notequal (sa1, sa2)
236+ call assert_notequal (sa1, sa3)
237+ call assert_notequal (sa2, sa3)
238+ call assert_equal (sa1, screenattr (&lines - 1 , 2 ))
239+ call assert_equal (sa2, screenattr (&lines - 1 , 4 ))
240+ call assert_equal (sa3, screenattr (&lines - 1 , 6 ))
241+ call assert_equal (sa3, screenattr (&lines - 1 , 7 ))
242+
243+ " %*: Set highlight group to User{N}
244+ set statusline = a % 1 * b % 0 * c
245+ call assert_match (' ^abc\s*$' , s: get_statusline ())
246+ let sa1= screenattr (&lines - 1 , 1 )
247+ let sa2= screenattr (&lines - 1 , 2 )
248+ let sa3= screenattr (&lines - 1 , 3 )
249+ call assert_equal (sa1, sa3)
250+ call assert_notequal (sa1, sa2)
251+
252+ " %%: a percent sign.
253+ set statusline = 10 %%
254+ call assert_match (' ^10%\s*$' , s: get_statusline ())
255+
256+ " %!: evaluated expression is used as the option value
257+ set statusline = % ! 2 * 3 + 1
258+ call assert_match (' 7\s*$' , s: get_statusline ())
259+
260+ " Check statusline in current and non-current window
261+ " with the 'fillchars' option.
262+ set fillchars = stl :^,stlnc:= ,vert :\| ,fold :- ,diff :-
263+ vsplit
264+ set statusline = x % = y
265+ call assert_match (' ^x^\+y^x=\+y$' , s: get_statusline ())
266+ set fillchars &
267+ close
268+
269+ % bw !
270+ call delete (' Xstatusline' )
271+ set statusline &
272+ set laststatus &
273+ set splitbelow &
274+ endfunc
0 commit comments