robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1" Test for cursorline and cursorlineopt 2 3source check.vim 4source screendump.vim 5 6func s: screen_attr ( lnum ) abort 7return map ( range ( 1 , 8 ), 'screenattr(a:lnum, v:val)' ) 8endfunc 9 10func s: test_windows ( h , w ) abort 11call NewWindow ( a: h , a: w ) 12endfunc 13 14func s: close_windows () abort 15call CloseWindow () 16endfunc 17 18func s: new_hi () abort 19redir => save_hi 20silent ! hi CursorLineNr 21redir END 22let save_hi = join ( split ( substitute ( save_hi , '\s*xxx\s*' , ' ' , '' ), "\n" ), '' ) 23exe 'hi' save_hi 'ctermbg=0 guibg=Black' 24return save_hi 25endfunc 26 27func Test_cursorline_highlight1 () 28let save_hi = s: new_hi () 29try 30call s: test_windows ( 10 , 20 ) 31call setline ( 1 , repeat ([ 'aaaa' ], 10 )) 32redraw 33let attr01 = s: screen_attr ( 1 ) 34call assert_equal ( repeat ([ attr01 [ 0 ]], 8 ), attr01 ) 35 36setl number numberwidth = 4 37redraw 38let attr11 = s: screen_attr ( 1 ) 39call assert_equal ( repeat ([ attr11 [ 0 ]], 4 ), attr11 [ 0 : 3 ]) 40call assert_equal ( repeat ([ attr11 [ 4 ]], 4 ), attr11 [ 4 : 7 ]) 41call assert_notequal ( attr11 [ 0 ], attr11 [ 4 ]) 42 43setl cursorline 44redraw 45let attr21 = s: screen_attr ( 1 ) 46let attr22 = s: screen_attr ( 2 ) 47call assert_equal ( repeat ([ attr21 [ 0 ]], 4 ), attr21 [ 0 : 3 ]) 48call assert_equal ( repeat ([ attr21 [ 4 ]], 4 ), attr21 [ 4 : 7 ]) 49call assert_equal ( attr11 , attr22 ) 50call assert_notequal ( attr22 , attr21 ) 51 52setl nocursorline relativenumber 53redraw 54let attr31 = s: screen_attr ( 1 ) 55call assert_equal ( attr22 [ 0 : 3 ], attr31 [ 0 : 3 ]) 56call assert_equal ( attr11 [ 4 : 7 ], attr31 [ 4 : 7 ]) 57 58call s: close_windows () 59finally 60exe 'hi' save_hi 61endtry 62endfunc 63 64func Test_cursorline_highlight2 () 65CheckOption cursorlineopt 66 67let save_hi = s: new_hi () 68try 69call s: test_windows ( 10 , 20 ) 70call setline ( 1 , repeat ([ 'aaaa' ], 10 )) 71redraw 72let attr0 = s: screen_attr ( 1 ) 73call assert_equal ( repeat ([ attr0 [ 0 ]], 8 ), attr0 ) 74 75setl number 76redraw 77let attr1 = s: screen_attr ( 1 ) 78call assert_notequal ( attr0 [ 0 : 3 ], attr1 [ 0 : 3 ]) 79call assert_equal ( attr0 [ 0 : 3 ], attr1 [ 4 : 7 ]) 80 81setl cursorline cursorlineopt = both 82redraw 83let attr2 = s: screen_attr ( 1 ) 84call assert_notequal ( attr1 [ 0 : 3 ], attr2 [ 0 : 3 ]) 85call assert_notequal ( attr1 [ 4 : 7 ], attr2 [ 4 : 7 ]) 86 87setl cursorlineopt = line 88redraw 89let attr3 = s: screen_attr ( 1 ) 90call assert_equal ( attr1 [ 0 : 3 ], attr3 [ 0 : 3 ]) 91call assert_equal ( attr2 [ 4 : 7 ], attr3 [ 4 : 7 ]) 92 93setl cursorlineopt = number 94redraw 95let attr4 = s: screen_attr ( 1 ) 96call assert_equal ( attr2 [ 0 : 3 ], attr4 [ 0 : 3 ]) 97call assert_equal ( attr1 [ 4 : 7 ], attr4 [ 4 : 7 ]) 98 99setl nonumber 100redraw 101let attr5 = s: screen_attr ( 1 ) 102call assert_equal ( attr0 , attr5 ) 103 104call s: close_windows () 105finally 106exe 'hi' save_hi 107endtry 108endfunc 109 110func Test_cursorline_fold_sign_independent_of_culopt () 111" CursorLineFold/CursorLineSign follow 'cursorline', not 'cursorlineopt'. 112CheckOption cursorlineopt 113CheckFeature signs 114CheckFeature folding 115 116call s: test_windows ( 10 , 20 ) 117try 118call setline ( 1 , repeat ([ 'aaaa' ], 5 )) 119setl number numberwidth = 4 signcolumn = yesfoldcolumn = 1 120hi FoldColumn ctermbg= 1guibg = Red 121hi CursorLineFold ctermbg= 2guibg = Green 122hi SignColumn ctermbg= 3guibg = Yellow 123hi CursorLineSign ctermbg= 4guibg = Blue 124 125setl nocursorline 126redraw 127let fold_off = screenattr ( 1 , 1 ) 128let sign_off = screenattr ( 1 , 2 ) 129 130" 'cursorlineopt' is "line" only: fold/sign on the cursor line still 131" use CursorLineFold / CursorLineSign. 132setl cursorline cursorlineopt = line 133redraw 134call assert_notequal ( fold_off , screenattr ( 1 , 1 )) 135call assert_notequal ( sign_off , screenattr ( 1 , 2 )) 136call assert_equal ( fold_off , screenattr ( 2 , 1 )) 137call assert_equal ( sign_off , screenattr ( 2 , 2 )) 138 139setl cursorlineopt = number 140redraw 141call assert_notequal ( fold_off , screenattr ( 1 , 1 )) 142call assert_notequal ( sign_off , screenattr ( 1 , 2 )) 143 144setl cursorlineopt = both 145redraw 146call assert_notequal ( fold_off , screenattr ( 1 , 1 )) 147call assert_notequal ( sign_off , screenattr ( 1 , 2 )) 148finally 149setl number & numberwidth & signcolumn & foldcolumn & cursorline & cursorlineopt & 150hi clear FoldColumn 151hi clear CursorLineFold 152hi clear SignColumn 153hi clear CursorLineSign 154hi default link CursorLineFold FoldColumn 155hi default link CursorLineSign SignColumn 156call s: close_windows () 157endtry 158endfunc 159 160func Test_cursorline_screenline () 161CheckScreendump 162CheckOption cursorlineopt 163 164let filename = 'Xcursorline' 165let lines = [] 166 167let file_content =<< trim END 1681 foooooooo ar einszwei drei vier fünf sechs sieben acht un zehn elf zwöfl dreizehn v ierzehn fünfzehn 1692 foooooooo bar eins zwei drei vier fünf sechs sieben 1703 foooooooo bar eins zwei drei vier fünf sechs sieben 1714 foooooooo bar eins zwei drei vier fünf sechs sieben 172END 173let lines1 =<< trim END1 174set nocp 175set display=lastline 176set cursorlineopt=screenline cursorline nu wrap sbr=> 177hi CursorLineNr ctermfg=blue 17825vsp 179END1 180let lines2 =<< trim END2 181call cursor(1,1) 182END2 183call extend ( lines , lines1 ) 184call extend ( lines , [ "call append(0, " .. string ( file_content ) .. ')' ]) 185call extend ( lines , lines2 ) 186call writefile ( lines , filename ) 187" basic test 188let buf = RunVimInTerminal ( '-S ' . filename , #{ rows : 20 }) 189call VerifyScreenDump ( buf , 'Test_' . filename . '_1' , {}) 190call term_sendkeys ( buf , "fagj" ) 191call VerifyScreenDump ( buf , 'Test_' . filename . '_2' , {}) 192call term_sendkeys ( buf , "gj" ) 193call VerifyScreenDump ( buf , 'Test_' . filename . '_3' , {}) 194call term_sendkeys ( buf , "gj" ) 195call VerifyScreenDump ( buf , 'Test_' . filename . '_4' , {}) 196call term_sendkeys ( buf , "gj" ) 197call VerifyScreenDump ( buf , 'Test_' . filename . '_5' , {}) 198call term_sendkeys ( buf , "gj" ) 199call VerifyScreenDump ( buf , 'Test_' . filename . '_6' , {}) 200" test with set list and cursorlineopt containing number 201call term_sendkeys ( buf , "gg0" ) 202call term_sendkeys ( buf , ":set list cursorlineopt+=number listchars=space:-\<cr>" ) 203call VerifyScreenDump ( buf , 'Test_' . filename . '_7' , {}) 204call term_sendkeys ( buf , "fagj" ) 205call VerifyScreenDump ( buf , 'Test_' . filename . '_8' , {}) 206call term_sendkeys ( buf , "gj" ) 207call VerifyScreenDump ( buf , 'Test_' . filename . '_9' , {}) 208call term_sendkeys ( buf , "gj" ) 209call VerifyScreenDump ( buf , 'Test_' . filename . '_10' , {}) 210call term_sendkeys ( buf , "gj" ) 211call VerifyScreenDump ( buf , 'Test_' . filename . '_11' , {}) 212call term_sendkeys ( buf , "gj" ) 213call VerifyScreenDump ( buf , 'Test_' . filename . '_12' , {}) 214if exists ( "+foldcolumn" ) && exists ( "+signcolumn" ) && exists ( "+breakindent" ) 215" test with set foldcolumn signcolumn and breakindent 216call term_sendkeys ( buf , "gg0" ) 217call term_sendkeys ( buf , ":set breakindent foldcolumn=2 signcolumn=yes\<cr>" ) 218call VerifyScreenDump ( buf , 'Test_' . filename . '_13' , {}) 219call term_sendkeys ( buf , "fagj" ) 220call VerifyScreenDump ( buf , 'Test_' . filename . '_14' , {}) 221call term_sendkeys ( buf , "gj" ) 222call VerifyScreenDump ( buf , 'Test_' . filename . '_15' , {}) 223call term_sendkeys ( buf , "gj" ) 224call VerifyScreenDump ( buf , 'Test_' . filename . '_16' , {}) 225call term_sendkeys ( buf , "gj" ) 226call VerifyScreenDump ( buf , 'Test_' . filename . '_17' , {}) 227call term_sendkeys ( buf , "gj" ) 228call VerifyScreenDump ( buf , 'Test_' . filename . '_18' , {}) 229call term_sendkeys ( buf , ":set breakindent& foldcolumn& signcolumn&\<cr>" ) 230endif 231" showbreak should not be highlighted with CursorLine when 'number' is off 232call term_sendkeys ( buf , "gg0" ) 233call term_sendkeys ( buf , ":set list cursorlineopt=screenline listchars=space:-\<cr>" ) 234call term_sendkeys ( buf , ":set nonumber\<cr>" ) 235call VerifyScreenDump ( buf , 'Test_' . filename . '_19' , {}) 236call term_sendkeys ( buf , "fagj" ) 237call VerifyScreenDump ( buf , 'Test_' . filename . '_20' , {}) 238call term_sendkeys ( buf , "gj" ) 239call VerifyScreenDump ( buf , 'Test_' . filename . '_21' , {}) 240call term_sendkeys ( buf , "gj" ) 241call VerifyScreenDump ( buf , 'Test_' . filename . '_22' , {}) 242call term_sendkeys ( buf , "gj" ) 243call VerifyScreenDump ( buf , 'Test_' . filename . '_23' , {}) 244call term_sendkeys ( buf , "gj" ) 245call VerifyScreenDump ( buf , 'Test_' . filename . '_24' , {}) 246call term_sendkeys ( buf , ":set list& cursorlineopt& listchars&\<cr>" ) 247 248call StopVimInTerminal ( buf ) 249call delete ( filename ) 250endfunc 251 252func Test_cursorline_redraw () 253CheckScreendump 254CheckOption cursorlineopt 255 256let textlines =<< END 257When the option is a list of flags, {value} must be 258exactly as they appear in the option. Remove flags 259one by one to avoid problems. 260Also see |:set-args| above. 261 262The {option} arguments to ":set" may be repeated. For example: > 263:set ai nosi sw=3 ts=3 264If you make an error in one of the arguments, an error message will be given 265and the following arguments will be ignored. 266 267*:set-verbose* 268When 'verbose' is non-zero, displaying an option value will also tell where it 269was last set. Example: > 270:verbose set shiftwidth cindent? 271< shiftwidth=4 ~ 272Last set from modeline line 1 ~ 273cindent ~ 274Last set from /usr/local/share/vim/vim60/ftplugin/c.vim line 30 ~ 275This is only done when specific option values are requested, not for ":verbose 276set all" or ":verbose set" without an argument. 277When the option was set by hand there is no "Last set" message. 278When the option was set while executing a function, user command or 279END 280call writefile ( textlines , 'Xtextfile' ) 281 282let script =<< trim END 283set cursorline scrolloff=2 284normal 12G 285END 286call writefile ( script , 'Xscript' ) 287 288let buf = RunVimInTerminal ( '-S Xscript Xtextfile' , #{ rows : 20 , cols : 40 }) 289call VerifyScreenDump ( buf , 'Test_cursorline_redraw_1' , {}) 290call term_sendkeys ( buf , "zt" ) 291call TermWait ( buf ) 292call term_sendkeys ( buf , "\<C-U>" ) 293call VerifyScreenDump ( buf , 'Test_cursorline_redraw_2' , {}) 294 295call StopVimInTerminal ( buf ) 296call delete ( 'Xscript' ) 297call delete ( 'Xtextfile' ) 298endfunc 299 300func Test_cursorline_callback () 301CheckScreendump 302CheckFeature timers 303 304let lines =<< trim END 305call setline(1, ['aaaaa', 'bbbbb', 'ccccc', 'ddddd']) 306set cursorline 307call cursor(4, 1) 308 309func Func(timer) 310call cursor(2, 1) 311endfunc 312 313call timer_start(300, 'Func') 314END 315call writefile ( lines , 'Xcul_timer' , 'D' ) 316 317let buf = RunVimInTerminal ( '-S Xcul_timer' , #{ rows : 8 }) 318call TermWait ( buf , 310 ) 319call VerifyScreenDump ( buf , 'Test_cursorline_callback_1' , {}) 320 321call StopVimInTerminal ( buf ) 322endfunc 323 324func Test_cursorline_screenline_resize () 325CheckScreendump 326 327let lines =<< trim END 32850vnew 329call setline(1, repeat('xyz ', 30)) 330setlocal number cursorline cursorlineopt=screenline 331normal! $ 332END 333call writefile ( lines , 'Xcul_screenline_resize' , 'D' ) 334 335let buf = RunVimInTerminal ( '-S Xcul_screenline_resize' , #{ rows : 8 }) 336call VerifyScreenDump ( buf , 'Test_cursorline_screenline_resize_1' , {}) 337call term_sendkeys ( buf , ":vertical resize -4\<CR>" ) 338call VerifyScreenDump ( buf , 'Test_cursorline_screenline_resize_2' , {}) 339call term_sendkeys ( buf , ":set cpoptions+=n\<CR>" ) 340call VerifyScreenDump ( buf , 'Test_cursorline_screenline_resize_3' , {}) 341 342call StopVimInTerminal ( buf ) 343endfunc 344 345func Test_cursorline_screenline_update () 346CheckScreendump 347 348let lines =<< trim END 349func TestRetab() 350let w = winwidth(0) 351call cursor([1, w + 1, 0, w + 1]) 352call line('w0') 353retab 8 354endfunc 355 356call setline(1, repeat('xyz ', 30)) 357set cursorline cursorlineopt=screenline tabstop=8 358inoremap <F2> <Cmd>call cursor(1, 1)<CR> 359inoremap <F3> <Cmd>call TestRetab()<CR> 360END 361call writefile ( lines , 'Xcul_screenline' , 'D' ) 362 363let buf = RunVimInTerminal ( '-S Xcul_screenline' , #{ rows : 8 }) 364call term_sendkeys ( buf , "A" ) 365call VerifyScreenDump ( buf , 'Test_cursorline_screenline_1' , {}) 366call term_sendkeys ( buf , "\<F2>" ) 367call VerifyScreenDump ( buf , 'Test_cursorline_screenline_2' , {}) 368call term_sendkeys ( buf , "\<F3>" ) 369call VerifyScreenDump ( buf , 'Test_cursorline_screenline_3' , {}) 370call term_sendkeys ( buf , "\<Esc>" ) 371 372call StopVimInTerminal ( buf ) 373endfunc 374 375func Test_cursorline_screenline_zero_width () 376CheckOption foldcolumn 377 378set cursorline culopt = screenlinewinminwidth = 1 foldcolumn = 1 379" This used to crash Vim 3801 vnew |redraw 381 382bwipe ! 383set cursorline & culopt & winminwidth & foldcolumn & 384endfunc 385 386func Test_cursorline_cursorbind_horizontal_scroll () 387CheckScreendump 388 389let lines =<< trim END 390call setline(1, 'aa bb cc dd ee ff gg hh ii jj kk ll mm' .. 391\ ' nn oo pp qq rr ss tt uu vv ww xx yy zz') 392set nowrap 393" The following makes the cursor apparent on the screen dump 394set sidescroll=1 cursorcolumn 395" add empty lines, required for cursorcolumn 396call append(1, ['','','','']) 39720vsp 398windo :set cursorbind 399END 400call writefile ( lines , 'Xhor_scroll' ) 401 402let buf = RunVimInTerminal ( '-S Xhor_scroll' , #{ rows : 8 }) 403call term_sendkeys ( buf , "20l" ) 404call VerifyScreenDump ( buf , 'Test_hor_scroll_1' , {}) 405call term_sendkeys ( buf , "10l" ) 406call VerifyScreenDump ( buf , 'Test_hor_scroll_2' , {}) 407call term_sendkeys ( buf , ":windo :set cursorline\<cr>" ) 408call term_sendkeys ( buf , "0" ) 409call term_sendkeys ( buf , "20l" ) 410call VerifyScreenDump ( buf , 'Test_hor_scroll_3' , {}) 411call term_sendkeys ( buf , "10l" ) 412call VerifyScreenDump ( buf , 'Test_hor_scroll_4' , {}) 413call term_sendkeys ( buf , ":windo :set nocursorline nocursorcolumn\<cr>" ) 414call term_sendkeys ( buf , "0" ) 415call term_sendkeys ( buf , "40l" ) 416call VerifyScreenDump ( buf , 'Test_hor_scroll_5' , {}) 417 418call StopVimInTerminal ( buf ) 419call delete ( 'Xhor_scroll' ) 420endfunc 421 422 423" vim: shiftwidth=2 sts=2 expandtab