Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 1 | " Test 'statusline' |
| 2 | " |
| 3 | " Not tested yet: |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 4 | " %N |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 5 | |
| 6 | source view_util.vim |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 7 | source check.vim |
Bram Moolenaar | dbe5d36 | 2020-02-08 18:35:31 +0100 | [diff] [blame] | 8 | source screendump.vim |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 9 | |
| 10 | func s:get_statusline() |
| 11 | return ScreenLines(&lines - 1, &columns)[0] |
| 12 | endfunc |
| 13 | |
| 14 | func StatuslineWithCaughtError() |
Bram Moolenaar | a742e08 | 2016-04-05 21:10:38 +0200 | [diff] [blame] | 15 | let s:func_in_statusline_called = 1 |
| 16 | try |
| 17 | call eval('unknown expression') |
| 18 | catch |
| 19 | endtry |
| 20 | return '' |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 21 | endfunc |
Bram Moolenaar | a742e08 | 2016-04-05 21:10:38 +0200 | [diff] [blame] | 22 | |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 23 | func StatuslineWithError() |
Bram Moolenaar | a742e08 | 2016-04-05 21:10:38 +0200 | [diff] [blame] | 24 | let s:func_in_statusline_called = 1 |
| 25 | call eval('unknown expression') |
| 26 | return '' |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 27 | endfunc |
Bram Moolenaar | a742e08 | 2016-04-05 21:10:38 +0200 | [diff] [blame] | 28 | |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 29 | " Function used to display syntax group. |
| 30 | func SyntaxItem() |
Bram Moolenaar | 1c6fd1e | 2019-05-23 22:11:59 +0200 | [diff] [blame] | 31 | 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 Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 34 | endfunc |
| 35 | |
| 36 | func Test_caught_error_in_statusline() |
Bram Moolenaar | a742e08 | 2016-04-05 21:10:38 +0200 | [diff] [blame] | 37 | 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 Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 45 | endfunc |
Bram Moolenaar | a742e08 | 2016-04-05 21:10:38 +0200 | [diff] [blame] | 46 | |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 47 | func Test_statusline_will_be_disabled_with_error() |
Bram Moolenaar | a742e08 | 2016-04-05 21:10:38 +0200 | [diff] [blame] | 48 | 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 Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 59 | endfunc |
| 60 | |
| 61 | func Test_statusline() |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 62 | CheckFeature quickfix |
| 63 | |
Bram Moolenaar | 4014e2c | 2020-06-23 20:00:50 +0200 | [diff] [blame] | 64 | " %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 Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 75 | only |
| 76 | set laststatus=2 |
| 77 | set splitbelow |
Bram Moolenaar | 316c167 | 2019-04-14 13:23:40 +0200 | [diff] [blame] | 78 | call setline(1, range(1, 10000)) |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 79 | |
| 80 | " %b: Value of character under cursor. |
| 81 | " %B: As above, in hexadecimal. |
Bram Moolenaar | 316c167 | 2019-04-14 13:23:40 +0200 | [diff] [blame] | 82 | call cursor(9000, 1) |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 83 | set statusline=%b,%B |
Bram Moolenaar | 316c167 | 2019-04-14 13:23:40 +0200 | [diff] [blame] | 84 | call assert_match('^57,39\s*$', s:get_statusline()) |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 85 | |
| 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 Moolenaar | 316c167 | 2019-04-14 13:23:40 +0200 | [diff] [blame] | 90 | call assert_match('^52888,CE98\s*$', s:get_statusline()) |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 91 | set fileformat=mac |
Bram Moolenaar | 316c167 | 2019-04-14 13:23:40 +0200 | [diff] [blame] | 92 | call assert_match('^43889,AB71\s*$', s:get_statusline()) |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 93 | set fileformat=unix |
Bram Moolenaar | 316c167 | 2019-04-14 13:23:40 +0200 | [diff] [blame] | 94 | call assert_match('^43889,AB71\s*$', s:get_statusline()) |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 95 | 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 Moolenaar | 832adf9 | 2020-06-25 19:01:36 +0200 | [diff] [blame] | 105 | " 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 Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 117 | " %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 Moolenaar | 316c167 | 2019-04-14 13:23:40 +0200 | [diff] [blame] | 140 | call assert_match('^9000/10000,1\s*$', s:get_statusline()) |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 141 | |
| 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 Moolenaar | 316c167 | 2019-04-14 13:23:40 +0200 | [diff] [blame] | 164 | 9000 |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 165 | " 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 Moolenaar | 316c167 | 2019-04-14 13:23:40 +0200 | [diff] [blame] | 193 | call cursor(9000, 2) |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 194 | 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()) |
zeertzjq | 0f11205 | 2022-01-14 20:11:38 +0000 | [diff] [blame] | 199 | set list |
| 200 | call assert_match('^10,-10\s*$', s:get_statusline()) |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 201 | set virtualedit& |
zeertzjq | 0f11205 | 2022-01-14 20:11:38 +0000 | [diff] [blame] | 202 | 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 Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 209 | |
| 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 Moolenaar | 316c167 | 2019-04-14 13:23:40 +0200 | [diff] [blame] | 232 | call cursor(9000, 1) |
| 233 | call assert_match('^0039\s*$', s:get_statusline()) |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 234 | set statusline=#%4B# |
Bram Moolenaar | 316c167 | 2019-04-14 13:23:40 +0200 | [diff] [blame] | 235 | call assert_match('^# 39#\s*$', s:get_statusline()) |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 236 | set statusline=#%-4B# |
Bram Moolenaar | 316c167 | 2019-04-14 13:23:40 +0200 | [diff] [blame] | 237 | call assert_match('^#39 #\s*$', s:get_statusline()) |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 238 | set statusline=%.6f |
| 239 | call assert_match('^<sline\s*$', s:get_statusline()) |
| 240 | |
| 241 | " %<: Where to truncate. |
Bram Moolenaar | 316c167 | 2019-04-14 13:23:40 +0200 | [diff] [blame] | 242 | " 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 Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 252 | |
| 253 | "%{: Evaluate expression between '%{' and '}' and substitute result. |
| 254 | syntax on |
Bram Moolenaar | 1c6fd1e | 2019-05-23 22:11:59 +0200 | [diff] [blame] | 255 | let s:expected_curbuf = string(bufnr('')) |
| 256 | let s:expected_curwin = string(win_getid()) |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 257 | 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 Pelle | 81b573d | 2022-03-22 21:14:55 +0000 | [diff] [blame] | 263 | "%{%expr%}: evaluates expressions present in result of expr |
shadmansaleh | 30e3de2 | 2021-05-15 17:23:28 +0200 | [diff] [blame] | 264 | 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 Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 283 | "%(: Start of item group. |
| 284 | set statusline=ab%(cd%q%)de |
| 285 | call assert_match('^abde\s*$', s:get_statusline()) |
| 286 | copen |
Bram Moolenaar | 1ef9bbe | 2017-06-17 20:08:20 +0200 | [diff] [blame] | 287 | call assert_match('^abcd\[Quickfix List]de\s*$', s:get_statusline()) |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 288 | 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 Moolenaar | 6b89dbb | 2017-10-22 14:22:16 +0200 | [diff] [blame] | 313 | " 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 Moolenaar | 235dddf | 2017-10-26 18:21:24 +0200 | [diff] [blame] | 377 | 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 Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 383 | " %%: 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 Moolenaar | 1c6fd1e | 2019-05-23 22:11:59 +0200 | [diff] [blame] | 391 | 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 Moolenaar | 8133cc6 | 2020-10-26 21:05:27 +0100 | [diff] [blame] | 408 | " 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 Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 423 | " 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& |
| 437 | endfunc |
Bram Moolenaar | dee50a5 | 2019-11-30 15:05:22 +0100 | [diff] [blame] | 438 | |
| 439 | func 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 |
| 459 | endfunc |
Bram Moolenaar | dbe5d36 | 2020-02-08 18:35:31 +0100 | [diff] [blame] | 460 | |
| 461 | func 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 Moolenaar | dbe5d36 | 2020-02-08 18:35:31 +0100 | [diff] [blame] | 472 | call VerifyScreenDump(buf, 'Test_statusline_1', {}) |
| 473 | |
| 474 | " clean up |
| 475 | call StopVimInTerminal(buf) |
| 476 | call delete('XTest_statusline') |
| 477 | endfunc |
Bram Moolenaar | 832adf9 | 2020-06-25 19:01:36 +0200 | [diff] [blame] | 478 | |
Bram Moolenaar | ce0b757 | 2021-04-01 18:47:14 +0200 | [diff] [blame] | 479 | func Test_statusline_using_mode() |
| 480 | CheckScreendump |
| 481 | |
| 482 | let lines =<< trim END |
Bram Moolenaar | d8db838 | 2021-04-08 18:27:53 +0200 | [diff] [blame] | 483 | setlocal statusline=-%{mode()}- |
| 484 | split |
| 485 | setlocal statusline=+%{mode()}+ |
Bram Moolenaar | ce0b757 | 2021-04-01 18:47:14 +0200 | [diff] [blame] | 486 | END |
| 487 | call writefile(lines, 'XTest_statusline') |
| 488 | |
Bram Moolenaar | d8db838 | 2021-04-08 18:27:53 +0200 | [diff] [blame] | 489 | let buf = RunVimInTerminal('-S XTest_statusline', {'rows': 7, 'cols': 50}) |
Bram Moolenaar | ce0b757 | 2021-04-01 18:47:14 +0200 | [diff] [blame] | 490 | 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 Moolenaar | d8db838 | 2021-04-08 18:27:53 +0200 | [diff] [blame] | 496 | call term_sendkeys(buf, "close\<CR>") |
Bram Moolenaar | ce0b757 | 2021-04-01 18:47:14 +0200 | [diff] [blame] | 497 | call StopVimInTerminal(buf) |
| 498 | call delete('XTest_statusline') |
| 499 | endfunc |
| 500 | |
Bram Moolenaar | 668008b | 2020-10-01 19:06:35 +0200 | [diff] [blame] | 501 | func 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& |
| 515 | endfunc |
| 516 | |
Bram Moolenaar | 008bff9 | 2021-03-04 21:55:58 +0100 | [diff] [blame] | 517 | " Test using a multibyte character for 'stl' and 'stlnc' items in 'fillchars' |
| 518 | " with a custom 'statusline' |
| 519 | func 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! |
| 531 | endfunc |
Bram Moolenaar | 668008b | 2020-10-01 19:06:35 +0200 | [diff] [blame] | 532 | |
Bram Moolenaar | 826bfe4 | 2021-10-08 18:39:28 +0100 | [diff] [blame] | 533 | " Used to write beyond allocated memory. This assumes MAXPATHL is 4096 bytes. |
| 534 | func 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! |
| 541 | endfunc |
| 542 | |
LemonBoy | 57ff526 | 2022-05-09 21:03:47 +0100 | [diff] [blame] | 543 | func 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') |
| 559 | endfunc |
| 560 | |
Bram Moolenaar | 832adf9 | 2020-06-25 19:01:36 +0200 | [diff] [blame] | 561 | " vim: shiftwidth=2 sts=2 expandtab |