1" Test for cursorline and cursorlineopt 2 3source check.vim 4source screendump.vim 5 6function! s:screen_attr(lnum) abort 7 return map(range(1, 8), 'screenattr(a:lnum, v:val)') 8endfunction 9 10function! s:test_windows(h, w) abort 11 call NewWindow(a:h, a:w) 12endfunction 13 14function! s:close_windows() abort 15 call CloseWindow() 16endfunction 17 18function! 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 25endfunction 26 27func 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 62endfunc 63 64func 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 108endfunc 109 110func 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 TermWait(buf) 140 call VerifyScreenDump(buf, 'Test_'. filename. '_1', {}) 141 call term_sendkeys(buf, "fagj") 142 call TermWait(buf) 143 call VerifyScreenDump(buf, 'Test_'. filename. '_2', {}) 144 call term_sendkeys(buf, "gj") 145 call TermWait(buf) 146 call VerifyScreenDump(buf, 'Test_'. filename. '_3', {}) 147 call term_sendkeys(buf, "gj") 148 call TermWait(buf) 149 call VerifyScreenDump(buf, 'Test_'. filename. '_4', {}) 150 call term_sendkeys(buf, "gj") 151 call TermWait(buf) 152 call VerifyScreenDump(buf, 'Test_'. filename. '_5', {}) 153 call term_sendkeys(buf, "gj") 154 call TermWait(buf) 155 call VerifyScreenDump(buf, 'Test_'. filename. '_6', {}) 156 " test with set list and cursorlineopt containing number 157 call term_sendkeys(buf, "gg0") 158 call term_sendkeys(buf, ":set list cursorlineopt+=number listchars=space:-\<cr>") 159 call VerifyScreenDump(buf, 'Test_'. filename. '_7', {}) 160 call term_sendkeys(buf, "fagj") 161 call TermWait(buf) 162 call VerifyScreenDump(buf, 'Test_'. filename. '_8', {}) 163 call term_sendkeys(buf, "gj") 164 call TermWait(buf) 165 call VerifyScreenDump(buf, 'Test_'. filename. '_9', {}) 166 call term_sendkeys(buf, "gj") 167 call TermWait(buf) 168 call VerifyScreenDump(buf, 'Test_'. filename. '_10', {}) 169 call term_sendkeys(buf, "gj") 170 call TermWait(buf) 171 call VerifyScreenDump(buf, 'Test_'. filename. '_11', {}) 172 call term_sendkeys(buf, "gj") 173 call TermWait(buf) 174 call VerifyScreenDump(buf, 'Test_'. filename. '_12', {}) 175 if exists("+foldcolumn") && exists("+signcolumn") && exists("+breakindent") 176 " test with set foldcolumn signcoloumn and breakindent 177 call term_sendkeys(buf, "gg0") 178 call term_sendkeys(buf, ":set breakindent foldcolumn=2 signcolumn=yes\<cr>") 179 call VerifyScreenDump(buf, 'Test_'. filename. '_13', {}) 180 call term_sendkeys(buf, "fagj") 181 call TermWait(buf) 182 call VerifyScreenDump(buf, 'Test_'. filename. '_14', {}) 183 call term_sendkeys(buf, "gj") 184 call TermWait(buf) 185 call VerifyScreenDump(buf, 'Test_'. filename. '_15', {}) 186 call term_sendkeys(buf, "gj") 187 call TermWait(buf) 188 call VerifyScreenDump(buf, 'Test_'. filename. '_16', {}) 189 call term_sendkeys(buf, "gj") 190 call TermWait(buf) 191 call VerifyScreenDump(buf, 'Test_'. filename. '_17', {}) 192 call term_sendkeys(buf, "gj") 193 call TermWait(buf) 194 call VerifyScreenDump(buf, 'Test_'. filename. '_18', {}) 195 call term_sendkeys(buf, ":set breakindent& foldcolumn& signcolumn&\<cr>") 196 endif 197 " showbreak should not be highlighted with CursorLine when 'number' is off 198 call term_sendkeys(buf, "gg0") 199 call term_sendkeys(buf, ":set list cursorlineopt=screenline listchars=space:-\<cr>") 200 call term_sendkeys(buf, ":set nonumber\<cr>") 201 call VerifyScreenDump(buf, 'Test_'. filename. '_19', {}) 202 call term_sendkeys(buf, "fagj") 203 call TermWait(buf) 204 call VerifyScreenDump(buf, 'Test_'. filename. '_20', {}) 205 call term_sendkeys(buf, "gj") 206 call TermWait(buf) 207 call VerifyScreenDump(buf, 'Test_'. filename. '_21', {}) 208 call term_sendkeys(buf, "gj") 209 call TermWait(buf) 210 call VerifyScreenDump(buf, 'Test_'. filename. '_22', {}) 211 call term_sendkeys(buf, "gj") 212 call TermWait(buf) 213 call VerifyScreenDump(buf, 'Test_'. filename. '_23', {}) 214 call term_sendkeys(buf, "gj") 215 call TermWait(buf) 216 call VerifyScreenDump(buf, 'Test_'. filename. '_24', {}) 217 call term_sendkeys(buf, ":set list& cursorlineopt& listchars&\<cr>") 218 219 call StopVimInTerminal(buf) 220 call delete(filename) 221endfunc 222 223func Test_cursorline_redraw() 224 CheckScreendump 225 CheckOption cursorlineopt 226 227 let textlines =<< END 228 When the option is a list of flags, {value} must be 229 exactly as they appear in the option. Remove flags 230 one by one to avoid problems. 231 Also see |:set-args| above. 232 233The {option} arguments to ":set" may be repeated. For example: > 234 :set ai nosi sw=3 ts=3 235If you make an error in one of the arguments, an error message will be given 236and the following arguments will be ignored. 237 238 *:set-verbose* 239When 'verbose' is non-zero, displaying an option value will also tell where it 240was last set. Example: > 241 :verbose set shiftwidth cindent? 242< shiftwidth=4 ~ 243 Last set from modeline line 1 ~ 244 cindent ~ 245 Last set from /usr/local/share/vim/vim60/ftplugin/c.vim line 30 ~ 246This is only done when specific option values are requested, not for ":verbose 247set all" or ":verbose set" without an argument. 248When the option was set by hand there is no "Last set" message. 249When the option was set while executing a function, user command or 250END 251 call writefile(textlines, 'Xtextfile') 252 253 let script =<< trim END 254 set cursorline scrolloff=2 255 normal 12G 256 END 257 call writefile(script, 'Xscript') 258 259 let buf = RunVimInTerminal('-S Xscript Xtextfile', #{rows: 20, cols: 40}) 260 call VerifyScreenDump(buf, 'Test_cursorline_redraw_1', {}) 261 call term_sendkeys(buf, "zt") 262 call TermWait(buf) 263 call term_sendkeys(buf, "\<C-U>") 264 call VerifyScreenDump(buf, 'Test_cursorline_redraw_2', {}) 265 266 call StopVimInTerminal(buf) 267 call delete('Xscript') 268 call delete('Xtextfile') 269endfunc 270 271" vim: shiftwidth=2 sts=2 expandtab 272