test_statusline.vim (22164B)
1 " Test 'statusline' 2 " 3 " Not tested yet: 4 " %N 5 6 source view_util.vim 7 source check.vim 8 source term_util.vim 9 10 func SetUp() 11 set laststatus=2 12 endfunc 13 14 func TearDown() 15 set laststatus& 16 endfunc 17 18 func s:get_statusline() 19 if has('gui_running') 20 redraw! 21 sleep 1m 22 endif 23 return ScreenLines(&lines - 1, &columns)[0] 24 endfunc 25 26 func StatuslineWithCaughtError() 27 let s:func_in_statusline_called = 1 28 try 29 call eval('unknown expression') 30 catch 31 endtry 32 return '' 33 endfunc 34 35 func StatuslineWithError() 36 let s:func_in_statusline_called = 1 37 call eval('unknown expression') 38 return '' 39 endfunc 40 41 " Function used to display syntax group. 42 func SyntaxItem() 43 call assert_equal(s:expected_curbuf, g:actual_curbuf) 44 call assert_equal(s:expected_curwin, g:actual_curwin) 45 return synIDattr(synID(line("."), col("."),1), "name") 46 endfunc 47 48 func Test_caught_error_in_statusline() 49 let s:func_in_statusline_called = 0 50 let statusline = '%{StatuslineWithCaughtError()}' 51 let &statusline = statusline 52 redrawstatus 53 call assert_true(s:func_in_statusline_called) 54 call assert_equal(statusline, &statusline) 55 set statusline= 56 endfunc 57 58 func Test_statusline_will_be_disabled_with_error() 59 let s:func_in_statusline_called = 0 60 let statusline = '%{StatuslineWithError()}' 61 try 62 let &statusline = statusline 63 redrawstatus 64 catch 65 endtry 66 call assert_true(s:func_in_statusline_called) 67 " Nvim: resets to default value instead. 68 " call assert_equal('', &statusline) 69 call assert_equal(nvim_get_option_info2('statusline', {}).default, &statusline) 70 set statusline= 71 endfunc 72 73 func Test_statusline() 74 CheckFeature quickfix 75 76 " %a: Argument list ({current} of {max}) 77 set statusline=%a 78 call assert_match('^\s*$', s:get_statusline()) 79 arglocal a1 a2 80 rewind 81 call assert_match('^ (1 of 2)\s*$', s:get_statusline()) 82 next 83 call assert_match('^ (2 of 2)\s*$', s:get_statusline()) 84 e Xstatusline 85 call assert_match('^ ((2) of 2)\s*$', s:get_statusline()) 86 87 only 88 set splitbelow 89 call setline(1, range(1, 10000)) 90 91 " %b: Value of character under cursor. 92 " %B: As above, in hexadecimal. 93 call cursor(9000, 1) 94 set statusline=%b,%B 95 call assert_match('^57,39\s*$', s:get_statusline()) 96 97 " %o: Byte number in file of byte under cursor, first byte is 1. 98 " %O: As above, in hexadecimal. 99 set statusline=%o,%O 100 set fileformat=dos 101 call assert_match('^52888,CE98\s*$', s:get_statusline()) 102 set fileformat=mac 103 call assert_match('^43889,AB71\s*$', s:get_statusline()) 104 set fileformat=unix 105 call assert_match('^43889,AB71\s*$', s:get_statusline()) 106 set fileformat& 107 108 " %f: Path to the file in the buffer, as typed or relative to current dir. 109 set statusline=%f 110 call assert_match('^Xstatusline\s*$', s:get_statusline()) 111 112 " %F: Full path to the file in the buffer. 113 set statusline=%F 114 call assert_match('/testdir/Xstatusline\s*$', s:get_statusline()) 115 116 " Test for min and max width with %(. For some reason, if this test is moved 117 " after the below test for the help buffer flag, then the code to truncate 118 " the string is not executed. 119 set statusline=%015(%f%) 120 call assert_match('^ Xstatusline\s*$', s:get_statusline()) 121 set statusline=%.6(%f%) 122 call assert_match('^<sline\s*$', s:get_statusline()) 123 set statusline=%14f 124 call assert_match('^ Xstatusline\s*$', s:get_statusline()) 125 set statusline=%.4L 126 call assert_match('^10>3\s*$', s:get_statusline()) 127 128 " %h: Help buffer flag, text is "[help]". 129 " %H: Help buffer flag, text is ",HLP". 130 set statusline=%h,%H 131 call assert_match('^,\s*$', s:get_statusline()) 132 help 133 call assert_match('^\[Help\],HLP\s*$', s:get_statusline()) 134 helpclose 135 136 " %k: Value of "b:keymap_name" or 'keymap' 137 " when :lmap mappings are being used: <keymap>" 138 set statusline=%k 139 if has('keymap') 140 set keymap=esperanto 141 call assert_match('^<Eo>\s*$', s:get_statusline()) 142 set keymap& 143 else 144 call assert_match('^\s*$', s:get_statusline()) 145 endif 146 147 " %l: Line number. 148 " %L: Number of line in buffer. 149 " %c: Column number. 150 set statusline=%l/%L,%c 151 call assert_match('^9000/10000,1\s*$', s:get_statusline()) 152 153 " %m: Modified flag, text is "[+]", "[-]" if 'modifiable' is off. 154 " %M: Modified flag, text is ",+" or ",-". 155 set statusline=%m%M 156 call assert_match('^\[+\],+\s*$', s:get_statusline()) 157 set nomodifiable 158 call assert_match('^\[+-\],+-\s*$', s:get_statusline()) 159 write 160 call assert_match('^\[-\],-\s*$', s:get_statusline()) 161 set modifiable& 162 call assert_match('^\s*$', s:get_statusline()) 163 164 " %n: Buffer number. 165 set statusline=%n 166 call assert_match('^'.bufnr('%').'\s*$', s:get_statusline()) 167 168 " %p: Percentage through file in lines as in CTRL-G. 169 " %P: Percentage through file of displayed window. 170 set statusline=%p,%P 171 0 172 call assert_match('^0,Top\s*$', s:get_statusline()) 173 norm G 174 call assert_match('^100,Bot\s*$', s:get_statusline()) 175 " The exact percentage depends on the window height, so create a window with 176 " known height. 177 9000 | botright 10split | setlocal scrolloff=0 | normal! zb 178 call assert_match('^90,89%\s*$', s:get_statusline()) 179 normal! zt 180 call assert_match('^90,90%\s*$', s:get_statusline()) 181 " %P should result in a string with 3 in length when not translated. 182 normal! 500zb 183 call assert_match('^5, 4%\s*$', s:get_statusline()) 184 close 185 186 " %q: "[Quickfix List]", "[Location List]" or empty. 187 set statusline=%q 188 call assert_match('^\s*$', s:get_statusline()) 189 copen 190 call assert_match('^\[Quickfix List\]\s*$', s:get_statusline()) 191 cclose 192 lexpr getline(1, 2) 193 lopen 194 call assert_match('^\[Location List\]\s*$', s:get_statusline()) 195 lclose 196 197 " %r: Readonly flag, text is "[RO]". 198 " %R: Readonly flag, text is ",RO". 199 set statusline=%r,%R 200 call assert_match('^,\s*$', s:get_statusline()) 201 help 202 call assert_match('^\[RO\],RO\s*$', s:get_statusline()) 203 helpclose 204 205 " %t: File name (tail) of file in the buffer. 206 set statusline=%t 207 call assert_match('^Xstatusline\s*$', s:get_statusline()) 208 209 " %v: Virtual column number. 210 " %V: Virtual column number as -{num}. Not displayed if equal to 'c'. 211 call cursor(9000, 2) 212 set statusline=%v,%V 213 call assert_match('^2,\s*$', s:get_statusline()) 214 set virtualedit=all 215 norm 10| 216 call assert_match('^10,-10\s*$', s:get_statusline()) 217 set list 218 call assert_match('^10,-10\s*$', s:get_statusline()) 219 set virtualedit& 220 exe "norm A\<Tab>\<Tab>a\<Esc>" 221 " In list mode a <Tab> is shown as "^I", which is 2-wide. 222 call assert_match('^9,-9\s*$', s:get_statusline()) 223 set list& 224 " Now the second <Tab> ends at the 16th screen column. 225 call assert_match('^17,-17\s*$', s:get_statusline()) 226 undo 227 228 " %w: Preview window flag, text is "[Preview]". 229 " %W: Preview window flag, text is ",PRV". 230 set statusline=%w%W 231 call assert_match('^\s*$', s:get_statusline()) 232 pedit 233 wincmd j 234 call assert_match('^\[Preview\],PRV\s*$', s:get_statusline()) 235 pclose 236 pbuffer 237 wincmd j 238 call assert_match('^\[Preview\],PRV\s*$', s:get_statusline()) 239 pclose 240 241 " %y: Type of file in the buffer, e.g., "[vim]". See 'filetype'. 242 " %Y: Type of file in the buffer, e.g., ",VIM". See 'filetype'. 243 set statusline=%y\ %Y 244 call assert_match('^\s*$', s:get_statusline()) 245 setfiletype vim 246 call assert_match('^\[vim\] VIM\s*$', s:get_statusline()) 247 248 " %=: Separation point between left and right aligned items. 249 set statusline=foo%=bar 250 call assert_match('^foo\s\+bar\s*$', s:get_statusline()) 251 set statusline=foo%=bar%=baz 252 call assert_match('^foo\s\+bar\s\+baz\s*$', s:get_statusline()) 253 set statusline=foo%=bar%=baz%=qux 254 call assert_match('^foo\s\+bar\s\+baz\s\+qux\s*$', s:get_statusline()) 255 256 " Test min/max width, leading zeroes, left/right justify. 257 set statusline=%04B 258 call cursor(9000, 1) 259 call assert_match('^0039\s*$', s:get_statusline()) 260 set statusline=#%4B# 261 call assert_match('^# 39#\s*$', s:get_statusline()) 262 set statusline=#%-4B# 263 call assert_match('^#39 #\s*$', s:get_statusline()) 264 set statusline=%.6f 265 call assert_match('^<sline\s*$', s:get_statusline()) 266 267 " %<: Where to truncate. 268 " First check with when %< should not truncate with many columns 269 exe 'set statusline=a%<b' . repeat('c', &columns - 3) . 'd' 270 call assert_match('^abc\+d$', s:get_statusline()) 271 exe 'set statusline=a' . repeat('b', &columns - 2) . '%<c' 272 call assert_match('^ab\+c$', s:get_statusline()) 273 " Then check when %< should truncate when there with too few columns. 274 exe 'set statusline=a%<b' . repeat('c', &columns - 2) . 'd' 275 call assert_match('^a<c\+d$', s:get_statusline()) 276 exe 'set statusline=a' . repeat('b', &columns - 1) . '%<c' 277 call assert_match('^ab\+>$', s:get_statusline()) 278 279 "%{: Evaluate expression between '%{' and '}' and substitute result. 280 syntax on 281 let s:expected_curbuf = string(bufnr('')) 282 let s:expected_curwin = string(win_getid()) 283 set statusline=%{SyntaxItem()} 284 call assert_match('^vimNumber\s*$', s:get_statusline()) 285 s/^/"/ 286 call assert_match('^vimLineComment\s*$', s:get_statusline()) 287 syntax off 288 289 "%{%expr%}: evaluates expressions present in result of expr 290 func! Inner_eval() 291 return '%n some other text' 292 endfunc 293 func! Outer_eval() 294 return 'some text %{%Inner_eval()%}' 295 endfunc 296 set statusline=%{%Outer_eval()%} 297 call assert_match('^some text ' . bufnr() . ' some other text\s*$', s:get_statusline()) 298 delfunc Inner_eval 299 delfunc Outer_eval 300 301 "%{%expr%}: Doesn't get stuck in recursion 302 func! Recurse_eval() 303 return '%{%Recurse_eval()%}' 304 endfunc 305 set statusline=%{%Recurse_eval()%} 306 call assert_match('^%{%Recurse_eval()%}\s*$', s:get_statusline()) 307 delfunc Recurse_eval 308 309 "%(: Start of item group. 310 set statusline=ab%(cd%q%)de 311 call assert_match('^abde\s*$', s:get_statusline()) 312 copen 313 call assert_match('^abcd\[Quickfix List]de\s*$', s:get_statusline()) 314 cclose 315 316 " %#: Set highlight group. The name must follow and then a # again. 317 set statusline=ab%#Todo#cd%#Error#ef 318 call assert_match('^abcdef\s*$', s:get_statusline()) 319 let sa1=screenattr(&lines - 1, 1) 320 let sa2=screenattr(&lines - 1, 3) 321 let sa3=screenattr(&lines - 1, 5) 322 call assert_notequal(sa1, sa2) 323 call assert_notequal(sa1, sa3) 324 call assert_notequal(sa2, sa3) 325 call assert_equal(sa1, screenattr(&lines - 1, 2)) 326 call assert_equal(sa2, screenattr(&lines - 1, 4)) 327 call assert_equal(sa3, screenattr(&lines - 1, 6)) 328 call assert_equal(sa3, screenattr(&lines - 1, 7)) 329 330 " %*: Set highlight group to User{N} 331 " Nvim: Combined with hl-StatusLine so needs to be set. 332 hi link User1 ErrorMsg 333 set statusline=a%1*b%0*c 334 call assert_match('^abc\s*$', s:get_statusline()) 335 let sa1=screenattr(&lines - 1, 1) 336 let sa2=screenattr(&lines - 1, 2) 337 let sa3=screenattr(&lines - 1, 3) 338 call assert_equal(sa1, sa3) 339 call assert_notequal(sa1, sa2) 340 341 " An empty group that contains highlight changes 342 let g:a = '' 343 set statusline=ab%(cd%1*%{g:a}%*%)de 344 call assert_match('^abde\s*$', s:get_statusline()) 345 let sa1=screenattr(&lines - 1, 1) 346 let sa2=screenattr(&lines - 1, 4) 347 call assert_equal(sa1, sa2) 348 let g:a = 'X' 349 call assert_match('^abcdXde\s*$', s:get_statusline()) 350 let sa1=screenattr(&lines - 1, 1) 351 let sa2=screenattr(&lines - 1, 5) 352 let sa3=screenattr(&lines - 1, 7) 353 call assert_equal(sa1, sa3) 354 call assert_notequal(sa1, sa2) 355 356 let g:a = '' 357 set statusline=ab%1*%(cd%*%{g:a}%1*%)de 358 call assert_match('^abde\s*$', s:get_statusline()) 359 let sa1=screenattr(&lines - 1, 1) 360 let sa2=screenattr(&lines - 1, 4) 361 call assert_notequal(sa1, sa2) 362 let g:a = 'X' 363 call assert_match('^abcdXde\s*$', s:get_statusline()) 364 let sa1=screenattr(&lines - 1, 1) 365 let sa2=screenattr(&lines - 1, 3) 366 let sa3=screenattr(&lines - 1, 5) 367 let sa4=screenattr(&lines - 1, 7) 368 call assert_notequal(sa1, sa2) 369 call assert_equal(sa1, sa3) 370 call assert_equal(sa2, sa4) 371 372 " An empty group that contains highlight changes and doesn't reset them 373 let g:a = '' 374 set statusline=ab%(cd%1*%{g:a}%)de 375 call assert_match('^abcdde\s*$', s:get_statusline()) 376 let sa1=screenattr(&lines - 1, 1) 377 let sa2=screenattr(&lines - 1, 5) 378 call assert_notequal(sa1, sa2) 379 let g:a = 'X' 380 call assert_match('^abcdXde\s*$', s:get_statusline()) 381 let sa1=screenattr(&lines - 1, 1) 382 let sa2=screenattr(&lines - 1, 5) 383 let sa3=screenattr(&lines - 1, 7) 384 call assert_notequal(sa1, sa2) 385 call assert_equal(sa2, sa3) 386 387 let g:a = '' 388 set statusline=ab%1*%(cd%*%{g:a}%)de 389 call assert_match('^abcdde\s*$', s:get_statusline()) 390 let sa1=screenattr(&lines - 1, 1) 391 let sa2=screenattr(&lines - 1, 3) 392 let sa3=screenattr(&lines - 1, 5) 393 call assert_notequal(sa1, sa2) 394 call assert_equal(sa1, sa3) 395 let g:a = 'X' 396 call assert_match('^abcdXde\s*$', s:get_statusline()) 397 let sa1=screenattr(&lines - 1, 1) 398 let sa2=screenattr(&lines - 1, 3) 399 let sa3=screenattr(&lines - 1, 5) 400 let sa4=screenattr(&lines - 1, 7) 401 call assert_notequal(sa1, sa2) 402 call assert_equal(sa1, sa3) 403 call assert_equal(sa1, sa4) 404 405 let g:a = '' 406 set statusline=%#Error#{%(\ %{g:a}\ %)} 407 call assert_match('^{}\s*$', s:get_statusline()) 408 let g:a = 'X' 409 call assert_match('^{ X }\s*$', s:get_statusline()) 410 411 " %%: a percent sign. 412 set statusline=10%% 413 call assert_match('^10%\s*$', s:get_statusline()) 414 415 " %!: evaluated expression is used as the option value 416 set statusline=%!2*3+1 417 call assert_match('7\s*$', s:get_statusline()) 418 419 func GetNested() 420 call assert_equal(string(win_getid()), g:actual_curwin) 421 call assert_equal(string(bufnr('')), g:actual_curbuf) 422 return 'nested' 423 endfunc 424 func GetStatusLine() 425 call assert_equal(win_getid(), g:statusline_winid) 426 return 'the %{GetNested()} line' 427 endfunc 428 set statusline=%!GetStatusLine() 429 call assert_match('the nested line', s:get_statusline()) 430 call assert_false(exists('g:actual_curwin')) 431 call assert_false(exists('g:actual_curbuf')) 432 call assert_false(exists('g:statusline_winid')) 433 delfunc GetNested 434 delfunc GetStatusLine 435 436 " Test statusline works with 80+ items 437 function! StatusLabel() 438 redrawstatus 439 return '[label]' 440 endfunc 441 let statusline = '%{StatusLabel()}' 442 for i in range(150) 443 let statusline .= '%#TabLine' . (i % 2 == 0 ? 'Fill' : 'Sel') . '#' . string(i)[0] 444 endfor 445 let &statusline = statusline 446 redrawstatus 447 set statusline& 448 delfunc StatusLabel 449 450 451 " Check statusline in current and non-current window 452 " with the 'fillchars' option. 453 set fillchars=stl:^,stlnc:=,vert:\|,fold:-,diff:- 454 vsplit 455 set statusline=x%=y 456 call assert_match('^x^\+y^x=\+y$', s:get_statusline()) 457 set fillchars& 458 close 459 460 %bw! 461 call delete('Xstatusline') 462 set statusline& 463 set splitbelow& 464 endfunc 465 466 func Test_statusline_trailing_percent_zero() 467 " this was causing illegal memory access 468 set laststatus=2 stl=%!%0 469 call assert_fails('redraw', 'E15: Invalid expression: "%0"') 470 set laststatus& stl& 471 endfunc 472 473 func Test_statusline_visual() 474 func CallWordcount() 475 call wordcount() 476 endfunc 477 new x1 478 setl statusline=count=%{CallWordcount()} 479 " buffer must not be empty 480 call setline(1, 'hello') 481 482 " window with more lines than x1 483 new x2 484 call setline(1, range(10)) 485 $ 486 " Visual mode in line below liast line in x1 should not give ml_get error 487 call feedkeys("\<C-V>", "xt") 488 redraw 489 490 delfunc CallWordcount 491 bwipe! x1 492 bwipe! x2 493 endfunc 494 495 func Test_statusline_removed_group() 496 if !CanRunVimInTerminal() 497 throw 'Skipped: cannot make screendumps' 498 endif 499 500 let lines =<< trim END 501 scriptencoding utf-8 502 set laststatus=2 503 let &statusline = '%#StatColorHi2#%(✓%#StatColorHi2#%) Q≡' 504 END 505 call writefile(lines, 'XTest_statusline', 'D') 506 507 let buf = RunVimInTerminal('-S XTest_statusline', {'rows': 10, 'cols': 50}) 508 call VerifyScreenDump(buf, 'Test_statusline_1', {}) 509 510 " clean up 511 call StopVimInTerminal(buf) 512 endfunc 513 514 func Test_statusline_using_mode() 515 CheckScreendump 516 517 let lines =<< trim END 518 setlocal statusline=-%{mode()}- 519 split 520 setlocal statusline=+%{mode()}+ 521 END 522 call writefile(lines, 'XTest_statusline', 'D') 523 524 let buf = RunVimInTerminal('-S XTest_statusline', {'rows': 7, 'cols': 50}) 525 call VerifyScreenDump(buf, 'Test_statusline_mode_1', {}) 526 527 call term_sendkeys(buf, ":") 528 call VerifyScreenDump(buf, 'Test_statusline_mode_2', {}) 529 530 " clean up 531 call term_sendkeys(buf, "close\<CR>") 532 call StopVimInTerminal(buf) 533 endfunc 534 535 func Test_statusline_after_split_vsplit() 536 only 537 538 " Make the status line of each window show the window number. 539 set ls=2 stl=%{winnr()} 540 541 split | redraw 542 vsplit | redraw 543 544 " The status line of the third window should read '3' here. 545 call assert_equal('3', nr2char(screenchar(&lines - 1, 1))) 546 547 only 548 set ls& stl& 549 endfunc 550 551 " Test using a multibyte character for 'stl' and 'stlnc' items in 'fillchars' 552 " with a custom 'statusline' 553 func Test_statusline_mbyte_fillchar() 554 only 555 set fillchars=vert:\|,fold:-,stl:━,stlnc:═ 556 set statusline=a%=b 557 call assert_match('^a\+━\+b$', s:get_statusline()) 558 vnew 559 call assert_match('^a\+━\+b━a\+═\+b$', s:get_statusline()) 560 wincmd w 561 call assert_match('^a\+═\+b═a\+━\+b$', s:get_statusline()) 562 set statusline& fillchars& 563 %bw! 564 endfunc 565 566 " Used to write beyond allocated memory. This assumes MAXPATHL is 4096 bytes. 567 func Test_statusline_verylong_filename() 568 let fname = repeat('x', 4090) 569 " Nvim's swap file creation fails on Windows (E303) due to fname's length 570 " exe "new " .. fname 571 exe "noswapfile new " .. fname 572 set buftype=help 573 set previewwindow 574 redraw 575 bwipe! 576 endfunc 577 578 func Test_statusline_highlight_truncate() 579 CheckScreendump 580 581 let lines =<< trim END 582 set laststatus=2 583 hi! link User1 Directory 584 hi! link User2 ErrorMsg 585 set statusline=%.5(%1*ABC%2*DEF%1*GHI%) 586 END 587 call writefile(lines, 'XTest_statusline', 'D') 588 589 let buf = RunVimInTerminal('-S XTest_statusline', {'rows': 6}) 590 call VerifyScreenDump(buf, 'Test_statusline_hl', {}) 591 592 call StopVimInTerminal(buf) 593 endfunc 594 595 func Test_statusline_showcmd() 596 CheckScreendump 597 598 let lines =<< trim END 599 func MyStatusLine() 600 return '%S' 601 endfunc 602 603 set laststatus=2 604 set statusline=%!MyStatusLine() 605 set showcmdloc=statusline 606 call setline(1, ['a', 'b', 'c']) 607 set foldopen+=jump 608 1,2fold 609 3 610 END 611 call writefile(lines, 'XTest_statusline', 'D') 612 613 let buf = RunVimInTerminal('-S XTest_statusline', {'rows': 6}) 614 615 call term_sendkeys(buf, "g") 616 call VerifyScreenDump(buf, 'Test_statusline_showcmd_1', {}) 617 618 " typing "gg" should open the fold 619 call term_sendkeys(buf, "g") 620 call VerifyScreenDump(buf, 'Test_statusline_showcmd_2', {}) 621 622 call term_sendkeys(buf, "\<C-V>Gl") 623 call VerifyScreenDump(buf, 'Test_statusline_showcmd_3', {}) 624 625 call term_sendkeys(buf, "\<Esc>1234") 626 call VerifyScreenDump(buf, 'Test_statusline_showcmd_4', {}) 627 628 call term_sendkeys(buf, "\<Esc>:set statusline=\<CR>") 629 call term_sendkeys(buf, ":\<CR>") 630 call term_sendkeys(buf, "1234") 631 call VerifyScreenDump(buf, 'Test_statusline_showcmd_5', {}) 632 633 call StopVimInTerminal(buf) 634 endfunc 635 636 func Test_statusline_highlight_group_cleared() 637 CheckScreendump 638 639 " the laststatus option is there to prevent 640 " the code-style test from complaining about 641 " trailing whitespace 642 let lines =<< trim END 643 set fillchars=stl:\ ,stlnc:\ laststatus=2 644 split 645 hi clear StatusLine 646 hi clear StatusLineNC 647 END 648 call writefile(lines, 'XTest_statusline_stl', 'D') 649 650 let buf = RunVimInTerminal('-S XTest_statusline_stl', {}) 651 652 call VerifyScreenDump(buf, 'Test_statusline_stl_1', {}) 653 654 call StopVimInTerminal(buf) 655 endfunc 656 657 " Test for setting both global and local 'statusline' values in a sandbox 658 func Test_statusline_in_sandbox() 659 func SandboxStatusLine() 660 call writefile(['after'], 'Xsandboxstatusline_write') 661 return "status line" 662 endfunc 663 664 func Check_statusline_in_sandbox(set_cmd0, set_cmd1) 665 only 666 11new | 20vsplit 667 call setline(1, 'foo') 668 windo setlocal statusline=SomethingElse 669 wincmd t 670 setlocal statusline= 671 call writefile(['before'], 'Xsandboxstatusline_write', 'D') 672 673 exe 'sandbox' a:set_cmd0 'statusline=%!SandboxStatusLine()' 674 call assert_equal('', &l:statusline) 675 sandbox setlocal statusline=%!SandboxStatusLine() 676 call assert_fails('redrawstatus', 'E48:') 677 call assert_equal(['before'], readfile('Xsandboxstatusline_write')) 678 wincmd b 679 call assert_fails('redrawstatus!', 'E48:') 680 call assert_equal(['before'], readfile('Xsandboxstatusline_write')) 681 wincmd t 682 683 5split 684 call assert_fails('redrawstatus!', 'E48:') 685 call assert_equal(['before'], readfile('Xsandboxstatusline_write')) 686 close 687 688 setlocal statusline=%!SandboxStatusLine() | redrawstatus 689 call assert_equal('status line', Screenline(12)) 690 call assert_equal(['after'], readfile('Xsandboxstatusline_write')) 691 692 call writefile(['before'], 'Xsandboxstatusline_write') 693 setlocal statusline= 694 call assert_fails('redrawstatus', 'E48:') 695 call assert_equal(['before'], readfile('Xsandboxstatusline_write')) 696 697 5split 698 call assert_fails('redrawstatus!', 'E48:') 699 call assert_equal(['before'], readfile('Xsandboxstatusline_write')) 700 701 exe a:set_cmd1 'statusline=%!SandboxStatusLine()' | redrawstatus! 702 call assert_equal('', &l:statusline) 703 call assert_equal('status line', Screenline(6)) 704 call assert_equal('status line', Screenline(12)) 705 call assert_equal(['after'], readfile('Xsandboxstatusline_write')) 706 bwipe! 707 endfunc 708 709 set noequalalways 710 call Check_statusline_in_sandbox('setglobal', 'setglobal') 711 call Check_statusline_in_sandbox('setglobal', 'set') 712 call Check_statusline_in_sandbox('set', 'setglobal') 713 call Check_statusline_in_sandbox('set', 'set') 714 715 set equalalways& statusline& 716 delfunc SandboxStatusLine 717 delfunc Check_statusline_in_sandbox 718 endfunc 719 720 " This used to call memmove with a negative size and crash Vim 721 func Test_statusline_singlebyte_negative() 722 let [_columns, _ls, _stl, _enc] = [&columns, &ls, &stl, &enc] 723 " set encoding=latin1 724 set laststatus=2 columns=15 725 setl stl=%#ErrorMsg#abcdtàØ?}}o@`s`ÿæCú\xE%#Normal# 726 vsp 727 setl stl=%#ErrorMsg#abcdtàØ?}}o@`s`ÿæCú\xE%#Normal# 728 redraw! 729 redrawstatus 730 bw! 731 let [&columns, &ls, &stl, &enc] = [_columns, _ls, _stl, _enc] 732 endfunc 733 734 " vim: shiftwidth=2 sts=2 expandtab