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