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