Bram Moolenaar | 410e98a | 2019-09-09 22:05:49 +0200 | [diff] [blame] | 1 | " Test for cursorline and cursorlineopt |
Bram Moolenaar | 017ba07 | 2019-09-14 21:01:23 +0200 | [diff] [blame^] | 2 | |
Bram Moolenaar | 410e98a | 2019-09-09 22:05:49 +0200 | [diff] [blame] | 3 | source check.vim |
Bram Moolenaar | 017ba07 | 2019-09-14 21:01:23 +0200 | [diff] [blame^] | 4 | source screendump.vim |
Bram Moolenaar | 410e98a | 2019-09-09 22:05:49 +0200 | [diff] [blame] | 5 | |
| 6 | function! s:screen_attr(lnum) abort |
| 7 | return map(range(1, 8), 'screenattr(a:lnum, v:val)') |
| 8 | endfunction |
| 9 | |
| 10 | function! s:test_windows(h, w) abort |
| 11 | call NewWindow(a:h, a:w) |
| 12 | endfunction |
| 13 | |
| 14 | function! s:close_windows() abort |
| 15 | call CloseWindow() |
| 16 | endfunction |
| 17 | |
| 18 | function! 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 | endfunction |
| 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(attr21[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 |
Bram Moolenaar | 017ba07 | 2019-09-14 21:01:23 +0200 | [diff] [blame^] | 109 | |
| 110 | func Test_cursorline_screenline() |
| 111 | CheckScreendump |
| 112 | CheckOption cursorlineopt |
| 113 | let filename='Xcursorline' |
| 114 | let lines = [] |
| 115 | |
| 116 | let file_content =<< trim END |
| 117 | 1 foooooooo ar einszwei drei vier fünf sechs sieben acht un zehn elf zwöfl dreizehn v ierzehn fünfzehn |
| 118 | 2 foooooooo bar eins zwei drei vier fünf sechs sieben |
| 119 | 3 foooooooo bar eins zwei drei vier fünf sechs sieben |
| 120 | 4 foooooooo bar eins zwei drei vier fünf sechs sieben |
| 121 | END |
| 122 | let lines1 =<< trim END1 |
| 123 | set nocp |
| 124 | set display=lastline |
| 125 | set cursorlineopt=screenline cursorline nu wrap sbr=> |
| 126 | hi CursorLineNr ctermfg=blue |
| 127 | 25vsp |
| 128 | END1 |
| 129 | let lines2 =<< trim END2 |
| 130 | call cursor(1,1) |
| 131 | END2 |
| 132 | call extend(lines, lines1) |
| 133 | call extend(lines, ["call append(0, ".. string(file_content).. ')']) |
| 134 | call extend(lines, lines2) |
| 135 | call writefile(lines, filename) |
| 136 | " basic test |
| 137 | let buf = RunVimInTerminal('-S '. filename, #{rows: 20}) |
| 138 | call term_wait(buf) |
| 139 | call VerifyScreenDump(buf, 'Test_'. filename. '_1', {}) |
| 140 | call term_sendkeys(buf, "fagj") |
| 141 | call term_wait(buf) |
| 142 | call VerifyScreenDump(buf, 'Test_'. filename. '_2', {}) |
| 143 | call term_sendkeys(buf, "gj") |
| 144 | call term_wait(buf) |
| 145 | call VerifyScreenDump(buf, 'Test_'. filename. '_3', {}) |
| 146 | call term_sendkeys(buf, "gj") |
| 147 | call term_wait(buf) |
| 148 | call VerifyScreenDump(buf, 'Test_'. filename. '_4', {}) |
| 149 | call term_sendkeys(buf, "gj") |
| 150 | call term_wait(buf) |
| 151 | call VerifyScreenDump(buf, 'Test_'. filename. '_5', {}) |
| 152 | call term_sendkeys(buf, "gj") |
| 153 | call term_wait(buf) |
| 154 | call VerifyScreenDump(buf, 'Test_'. filename. '_6', {}) |
| 155 | " test with set list and cursorlineopt containing number |
| 156 | call term_sendkeys(buf, "gg0") |
| 157 | call term_sendkeys(buf, ":set list cursorlineopt+=number listchars=space:-\<cr>") |
| 158 | call VerifyScreenDump(buf, 'Test_'. filename. '_7', {}) |
| 159 | call term_sendkeys(buf, "fagj") |
| 160 | call term_wait(buf) |
| 161 | call VerifyScreenDump(buf, 'Test_'. filename. '_8', {}) |
| 162 | call term_sendkeys(buf, "gj") |
| 163 | call term_wait(buf) |
| 164 | call VerifyScreenDump(buf, 'Test_'. filename. '_9', {}) |
| 165 | call term_sendkeys(buf, "gj") |
| 166 | call term_wait(buf) |
| 167 | call VerifyScreenDump(buf, 'Test_'. filename. '_10', {}) |
| 168 | call term_sendkeys(buf, "gj") |
| 169 | call term_wait(buf) |
| 170 | call VerifyScreenDump(buf, 'Test_'. filename. '_11', {}) |
| 171 | call term_sendkeys(buf, "gj") |
| 172 | call term_wait(buf) |
| 173 | call VerifyScreenDump(buf, 'Test_'. filename. '_12', {}) |
| 174 | if exists("+foldcolumn") && exists("+signcolumn") && exists("+breakindent") |
| 175 | " test with set foldcolumn signcoloumn and breakindent |
| 176 | call term_sendkeys(buf, "gg0") |
| 177 | call term_sendkeys(buf, ":set breakindent foldcolumn=2 signcolumn=yes\<cr>") |
| 178 | call VerifyScreenDump(buf, 'Test_'. filename. '_13', {}) |
| 179 | call term_sendkeys(buf, "fagj") |
| 180 | call term_wait(buf) |
| 181 | call VerifyScreenDump(buf, 'Test_'. filename. '_14', {}) |
| 182 | call term_sendkeys(buf, "gj") |
| 183 | call term_wait(buf) |
| 184 | call VerifyScreenDump(buf, 'Test_'. filename. '_15', {}) |
| 185 | call term_sendkeys(buf, "gj") |
| 186 | call term_wait(buf) |
| 187 | call VerifyScreenDump(buf, 'Test_'. filename. '_16', {}) |
| 188 | call term_sendkeys(buf, "gj") |
| 189 | call term_wait(buf) |
| 190 | call VerifyScreenDump(buf, 'Test_'. filename. '_17', {}) |
| 191 | call term_sendkeys(buf, "gj") |
| 192 | call term_wait(buf) |
| 193 | call VerifyScreenDump(buf, 'Test_'. filename. '_18', {}) |
| 194 | endif |
| 195 | |
| 196 | call StopVimInTerminal(buf) |
| 197 | call delete(filename) |
| 198 | endfunc |