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 | |
zeertzjq | bb404f5 | 2022-07-23 06:25:29 +0100 | [diff] [blame] | 10 | func SetUp() |
| 11 | set laststatus=2 |
| 12 | endfunc |
| 13 | |
| 14 | func TearDown() |
| 15 | set laststatus& |
| 16 | endfunc |
| 17 | |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 18 | func s:get_statusline() |
| 19 | return ScreenLines(&lines - 1, &columns)[0] |
| 20 | endfunc |
| 21 | |
| 22 | func StatuslineWithCaughtError() |
Bram Moolenaar | a742e08 | 2016-04-05 21:10:38 +0200 | [diff] [blame] | 23 | let s:func_in_statusline_called = 1 |
| 24 | try |
| 25 | call eval('unknown expression') |
| 26 | catch |
| 27 | endtry |
| 28 | return '' |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 29 | endfunc |
Bram Moolenaar | a742e08 | 2016-04-05 21:10:38 +0200 | [diff] [blame] | 30 | |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 31 | func StatuslineWithError() |
Bram Moolenaar | a742e08 | 2016-04-05 21:10:38 +0200 | [diff] [blame] | 32 | let s:func_in_statusline_called = 1 |
| 33 | call eval('unknown expression') |
| 34 | return '' |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 35 | endfunc |
Bram Moolenaar | a742e08 | 2016-04-05 21:10:38 +0200 | [diff] [blame] | 36 | |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 37 | " Function used to display syntax group. |
| 38 | func SyntaxItem() |
Bram Moolenaar | 1c6fd1e | 2019-05-23 22:11:59 +0200 | [diff] [blame] | 39 | 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 Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 42 | endfunc |
| 43 | |
| 44 | func Test_caught_error_in_statusline() |
Bram Moolenaar | a742e08 | 2016-04-05 21:10:38 +0200 | [diff] [blame] | 45 | let s:func_in_statusline_called = 0 |
Bram Moolenaar | a742e08 | 2016-04-05 21:10:38 +0200 | [diff] [blame] | 46 | 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 Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 52 | endfunc |
Bram Moolenaar | a742e08 | 2016-04-05 21:10:38 +0200 | [diff] [blame] | 53 | |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 54 | func Test_statusline_will_be_disabled_with_error() |
Bram Moolenaar | a742e08 | 2016-04-05 21:10:38 +0200 | [diff] [blame] | 55 | let s:func_in_statusline_called = 0 |
Bram Moolenaar | a742e08 | 2016-04-05 21:10:38 +0200 | [diff] [blame] | 56 | 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 Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 65 | endfunc |
| 66 | |
| 67 | func Test_statusline() |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 68 | CheckFeature quickfix |
| 69 | |
Bram Moolenaar | 4014e2c | 2020-06-23 20:00:50 +0200 | [diff] [blame] | 70 | " %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 Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 81 | only |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 82 | set splitbelow |
Bram Moolenaar | 316c167 | 2019-04-14 13:23:40 +0200 | [diff] [blame] | 83 | call setline(1, range(1, 10000)) |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 84 | |
| 85 | " %b: Value of character under cursor. |
| 86 | " %B: As above, in hexadecimal. |
Bram Moolenaar | 316c167 | 2019-04-14 13:23:40 +0200 | [diff] [blame] | 87 | call cursor(9000, 1) |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 88 | set statusline=%b,%B |
Bram Moolenaar | 316c167 | 2019-04-14 13:23:40 +0200 | [diff] [blame] | 89 | call assert_match('^57,39\s*$', s:get_statusline()) |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 90 | |
| 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 Moolenaar | 316c167 | 2019-04-14 13:23:40 +0200 | [diff] [blame] | 95 | call assert_match('^52888,CE98\s*$', s:get_statusline()) |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 96 | set fileformat=mac |
Bram Moolenaar | 316c167 | 2019-04-14 13:23:40 +0200 | [diff] [blame] | 97 | call assert_match('^43889,AB71\s*$', s:get_statusline()) |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 98 | set fileformat=unix |
Bram Moolenaar | 316c167 | 2019-04-14 13:23:40 +0200 | [diff] [blame] | 99 | call assert_match('^43889,AB71\s*$', s:get_statusline()) |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 100 | 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 Moolenaar | 832adf9 | 2020-06-25 19:01:36 +0200 | [diff] [blame] | 110 | " 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 Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 122 | " %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 Moolenaar | 316c167 | 2019-04-14 13:23:40 +0200 | [diff] [blame] | 145 | call assert_match('^9000/10000,1\s*$', s:get_statusline()) |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 146 | |
| 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 Moolenaar | 316c167 | 2019-04-14 13:23:40 +0200 | [diff] [blame] | 169 | 9000 |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 170 | " 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 Moolenaar | 316c167 | 2019-04-14 13:23:40 +0200 | [diff] [blame] | 198 | call cursor(9000, 2) |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 199 | 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()) |
zeertzjq | 0f11205 | 2022-01-14 20:11:38 +0000 | [diff] [blame] | 204 | set list |
| 205 | call assert_match('^10,-10\s*$', s:get_statusline()) |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 206 | set virtualedit& |
zeertzjq | 0f11205 | 2022-01-14 20:11:38 +0000 | [diff] [blame] | 207 | 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 Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 214 | |
| 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 Moolenaar | 316c167 | 2019-04-14 13:23:40 +0200 | [diff] [blame] | 237 | call cursor(9000, 1) |
| 238 | call assert_match('^0039\s*$', s:get_statusline()) |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 239 | set statusline=#%4B# |
Bram Moolenaar | 316c167 | 2019-04-14 13:23:40 +0200 | [diff] [blame] | 240 | call assert_match('^# 39#\s*$', s:get_statusline()) |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 241 | set statusline=#%-4B# |
Bram Moolenaar | 316c167 | 2019-04-14 13:23:40 +0200 | [diff] [blame] | 242 | call assert_match('^#39 #\s*$', s:get_statusline()) |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 243 | set statusline=%.6f |
| 244 | call assert_match('^<sline\s*$', s:get_statusline()) |
| 245 | |
| 246 | " %<: Where to truncate. |
Bram Moolenaar | 316c167 | 2019-04-14 13:23:40 +0200 | [diff] [blame] | 247 | " 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 Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 257 | |
| 258 | "%{: Evaluate expression between '%{' and '}' and substitute result. |
| 259 | syntax on |
Bram Moolenaar | 1c6fd1e | 2019-05-23 22:11:59 +0200 | [diff] [blame] | 260 | let s:expected_curbuf = string(bufnr('')) |
| 261 | let s:expected_curwin = string(win_getid()) |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 262 | 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 Pelle | 81b573d | 2022-03-22 21:14:55 +0000 | [diff] [blame] | 268 | "%{%expr%}: evaluates expressions present in result of expr |
shadmansaleh | 30e3de2 | 2021-05-15 17:23:28 +0200 | [diff] [blame] | 269 | 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 Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 288 | "%(: Start of item group. |
| 289 | set statusline=ab%(cd%q%)de |
| 290 | call assert_match('^abde\s*$', s:get_statusline()) |
| 291 | copen |
Bram Moolenaar | 1ef9bbe | 2017-06-17 20:08:20 +0200 | [diff] [blame] | 292 | call assert_match('^abcd\[Quickfix List]de\s*$', s:get_statusline()) |
Bram Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 293 | 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 Moolenaar | 6b89dbb | 2017-10-22 14:22:16 +0200 | [diff] [blame] | 318 | " 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 Moolenaar | 235dddf | 2017-10-26 18:21:24 +0200 | [diff] [blame] | 382 | 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 Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 388 | " %%: 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 Moolenaar | 1c6fd1e | 2019-05-23 22:11:59 +0200 | [diff] [blame] | 396 | 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 Moolenaar | 8133cc6 | 2020-10-26 21:05:27 +0100 | [diff] [blame] | 413 | " 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 Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 428 | " 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 Moolenaar | 300af82 | 2017-03-06 20:28:10 +0100 | [diff] [blame] | 440 | set splitbelow& |
| 441 | endfunc |
Bram Moolenaar | dee50a5 | 2019-11-30 15:05:22 +0100 | [diff] [blame] | 442 | |
Bram Moolenaar | 7b17eb4 | 2023-01-04 14:31:49 +0000 | [diff] [blame] | 443 | func 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& |
| 448 | endfunc |
| 449 | |
Bram Moolenaar | dee50a5 | 2019-11-30 15:05:22 +0100 | [diff] [blame] | 450 | func 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 |
| 470 | endfunc |
Bram Moolenaar | dbe5d36 | 2020-02-08 18:35:31 +0100 | [diff] [blame] | 471 | |
| 472 | func 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 Moolenaar | 5656496 | 2022-10-10 22:39:42 +0100 | [diff] [blame] | 480 | call writefile(lines, 'XTest_statusline', 'D') |
Bram Moolenaar | dbe5d36 | 2020-02-08 18:35:31 +0100 | [diff] [blame] | 481 | |
| 482 | let buf = RunVimInTerminal('-S XTest_statusline', {'rows': 10, 'cols': 50}) |
Bram Moolenaar | dbe5d36 | 2020-02-08 18:35:31 +0100 | [diff] [blame] | 483 | call VerifyScreenDump(buf, 'Test_statusline_1', {}) |
| 484 | |
| 485 | " clean up |
| 486 | call StopVimInTerminal(buf) |
Bram Moolenaar | dbe5d36 | 2020-02-08 18:35:31 +0100 | [diff] [blame] | 487 | endfunc |
Bram Moolenaar | 832adf9 | 2020-06-25 19:01:36 +0200 | [diff] [blame] | 488 | |
Bram Moolenaar | ce0b757 | 2021-04-01 18:47:14 +0200 | [diff] [blame] | 489 | func Test_statusline_using_mode() |
| 490 | CheckScreendump |
| 491 | |
| 492 | let lines =<< trim END |
Bram Moolenaar | d8db838 | 2021-04-08 18:27:53 +0200 | [diff] [blame] | 493 | setlocal statusline=-%{mode()}- |
| 494 | split |
| 495 | setlocal statusline=+%{mode()}+ |
Bram Moolenaar | ce0b757 | 2021-04-01 18:47:14 +0200 | [diff] [blame] | 496 | END |
Bram Moolenaar | 5656496 | 2022-10-10 22:39:42 +0100 | [diff] [blame] | 497 | call writefile(lines, 'XTest_statusline', 'D') |
Bram Moolenaar | ce0b757 | 2021-04-01 18:47:14 +0200 | [diff] [blame] | 498 | |
Bram Moolenaar | d8db838 | 2021-04-08 18:27:53 +0200 | [diff] [blame] | 499 | let buf = RunVimInTerminal('-S XTest_statusline', {'rows': 7, 'cols': 50}) |
Bram Moolenaar | ce0b757 | 2021-04-01 18:47:14 +0200 | [diff] [blame] | 500 | 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 Moolenaar | d8db838 | 2021-04-08 18:27:53 +0200 | [diff] [blame] | 506 | call term_sendkeys(buf, "close\<CR>") |
Bram Moolenaar | ce0b757 | 2021-04-01 18:47:14 +0200 | [diff] [blame] | 507 | call StopVimInTerminal(buf) |
Bram Moolenaar | ce0b757 | 2021-04-01 18:47:14 +0200 | [diff] [blame] | 508 | endfunc |
| 509 | |
Bram Moolenaar | 668008b | 2020-10-01 19:06:35 +0200 | [diff] [blame] | 510 | func 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& |
| 524 | endfunc |
| 525 | |
Bram Moolenaar | 008bff9 | 2021-03-04 21:55:58 +0100 | [diff] [blame] | 526 | " Test using a multibyte character for 'stl' and 'stlnc' items in 'fillchars' |
| 527 | " with a custom 'statusline' |
| 528 | func Test_statusline_mbyte_fillchar() |
| 529 | only |
Bram Moolenaar | 008bff9 | 2021-03-04 21:55:58 +0100 | [diff] [blame] | 530 | 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()) |
zeertzjq | bb404f5 | 2022-07-23 06:25:29 +0100 | [diff] [blame] | 537 | set statusline& fillchars& |
Bram Moolenaar | 008bff9 | 2021-03-04 21:55:58 +0100 | [diff] [blame] | 538 | %bw! |
| 539 | endfunc |
Bram Moolenaar | 668008b | 2020-10-01 19:06:35 +0200 | [diff] [blame] | 540 | |
Bram Moolenaar | 826bfe4 | 2021-10-08 18:39:28 +0100 | [diff] [blame] | 541 | " Used to write beyond allocated memory. This assumes MAXPATHL is 4096 bytes. |
| 542 | func 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! |
| 549 | endfunc |
| 550 | |
LemonBoy | 57ff526 | 2022-05-09 21:03:47 +0100 | [diff] [blame] | 551 | func 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 Moolenaar | 5656496 | 2022-10-10 22:39:42 +0100 | [diff] [blame] | 560 | call writefile(lines, 'XTest_statusline', 'D') |
LemonBoy | 57ff526 | 2022-05-09 21:03:47 +0100 | [diff] [blame] | 561 | |
| 562 | let buf = RunVimInTerminal('-S XTest_statusline', {'rows': 6}) |
| 563 | call VerifyScreenDump(buf, 'Test_statusline_hl', {}) |
| 564 | |
| 565 | call StopVimInTerminal(buf) |
LemonBoy | 57ff526 | 2022-05-09 21:03:47 +0100 | [diff] [blame] | 566 | endfunc |
| 567 | |
Luuk van Baal | ba936f6 | 2022-12-15 13:15:39 +0000 | [diff] [blame] | 568 | func 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', {}) |
| 588 | endfunc |
| 589 | |
Bram Moolenaar | 832adf9 | 2020-06-25 19:01:36 +0200 | [diff] [blame] | 590 | " vim: shiftwidth=2 sts=2 expandtab |