1" Tests for 'conceal'. 2 3source check.vim 4CheckFeature conceal 5 6source screendump.vim 7CheckScreendump 8 9func Test_conceal_two_windows() 10 let code =<< trim [CODE] 11 let lines = ["one one one one one", "two |hidden| here", "three |hidden| three"] 12 call setline(1, lines) 13 syntax match test /|hidden|/ conceal 14 set conceallevel=2 15 set concealcursor= 16 exe "normal /here\r" 17 new 18 call setline(1, lines) 19 call setline(4, "Second window") 20 syntax match test /|hidden|/ conceal 21 set conceallevel=2 22 set concealcursor=nc 23 exe "normal /here\r" 24 [CODE] 25 26 call writefile(code, 'XTest_conceal') 27 " Check that cursor line is concealed 28 let buf = RunVimInTerminal('-S XTest_conceal', {}) 29 call VerifyScreenDump(buf, 'Test_conceal_two_windows_01', {}) 30 31 " Check that with concealed text vertical cursor movement is correct. 32 call term_sendkeys(buf, "k") 33 call VerifyScreenDump(buf, 'Test_conceal_two_windows_02', {}) 34 35 " Check that with cursor line is not concealed 36 call term_sendkeys(buf, "j") 37 call term_sendkeys(buf, ":set concealcursor=\r") 38 call VerifyScreenDump(buf, 'Test_conceal_two_windows_03', {}) 39 40 " Check that with cursor line is not concealed when moving cursor down 41 call term_sendkeys(buf, "j") 42 call VerifyScreenDump(buf, 'Test_conceal_two_windows_04', {}) 43 44 " Check that with cursor line is not concealed when switching windows 45 call term_sendkeys(buf, "\<C-W>\<C-W>") 46 call VerifyScreenDump(buf, 'Test_conceal_two_windows_05', {}) 47 48 " Check that with cursor line is only concealed in Normal mode 49 call term_sendkeys(buf, ":set concealcursor=n\r") 50 call VerifyScreenDump(buf, 'Test_conceal_two_windows_06n', {}) 51 call term_sendkeys(buf, "a") 52 call VerifyScreenDump(buf, 'Test_conceal_two_windows_06i', {}) 53 call term_sendkeys(buf, "\<Esc>/e") 54 call VerifyScreenDump(buf, 'Test_conceal_two_windows_06c', {}) 55 call term_sendkeys(buf, "\<Esc>v") 56 call VerifyScreenDump(buf, 'Test_conceal_two_windows_06v', {}) 57 call term_sendkeys(buf, "\<Esc>") 58 59 " Check that with cursor line is only concealed in Insert mode 60 call term_sendkeys(buf, ":set concealcursor=i\r") 61 call VerifyScreenDump(buf, 'Test_conceal_two_windows_07n', {}) 62 call term_sendkeys(buf, "14|a") 63 call VerifyScreenDump(buf, 'Test_conceal_two_windows_07i', {}) 64 call term_sendkeys(buf, "\<Esc>") 65 call VerifyScreenDump(buf, 'Test_conceal_two_windows_07in', {}) 66 call term_sendkeys(buf, "/e") 67 call VerifyScreenDump(buf, 'Test_conceal_two_windows_07c', {}) 68 call term_sendkeys(buf, "\<Esc>v") 69 call VerifyScreenDump(buf, 'Test_conceal_two_windows_07v', {}) 70 call term_sendkeys(buf, "\<Esc>") 71 72 " Check that with cursor line is only concealed in Command mode 73 call term_sendkeys(buf, ":set concealcursor=c\r") 74 call VerifyScreenDump(buf, 'Test_conceal_two_windows_08n', {}) 75 call term_sendkeys(buf, "a") 76 call VerifyScreenDump(buf, 'Test_conceal_two_windows_08i', {}) 77 call term_sendkeys(buf, "\<Esc>/e") 78 call VerifyScreenDump(buf, 'Test_conceal_two_windows_08c', {}) 79 call term_sendkeys(buf, "\<Esc>v") 80 call VerifyScreenDump(buf, 'Test_conceal_two_windows_08v', {}) 81 call term_sendkeys(buf, "\<Esc>") 82 83 " Check that with cursor line is only concealed in Visual mode 84 call term_sendkeys(buf, ":set concealcursor=v\r") 85 call VerifyScreenDump(buf, 'Test_conceal_two_windows_09n', {}) 86 call term_sendkeys(buf, "a") 87 call VerifyScreenDump(buf, 'Test_conceal_two_windows_09i', {}) 88 call term_sendkeys(buf, "\<Esc>/e") 89 call VerifyScreenDump(buf, 'Test_conceal_two_windows_09c', {}) 90 call term_sendkeys(buf, "\<Esc>v") 91 call VerifyScreenDump(buf, 'Test_conceal_two_windows_09v', {}) 92 call term_sendkeys(buf, "\<Esc>") 93 94 " Check moving the cursor while in insert mode. 95 call term_sendkeys(buf, ":set concealcursor=\r") 96 call term_sendkeys(buf, "a") 97 call VerifyScreenDump(buf, 'Test_conceal_two_windows_10', {}) 98 call term_sendkeys(buf, "\<Down>") 99 call VerifyScreenDump(buf, 'Test_conceal_two_windows_11', {}) 100 call term_sendkeys(buf, "\<Esc>") 101 102 " Check the "o" command 103 call VerifyScreenDump(buf, 'Test_conceal_two_windows_12', {}) 104 call term_sendkeys(buf, "o") 105 call VerifyScreenDump(buf, 'Test_conceal_two_windows_13', {}) 106 call term_sendkeys(buf, "\<Esc>") 107 108 " clean up 109 call StopVimInTerminal(buf) 110 call delete('XTest_conceal') 111endfunc 112 113func Test_conceal_with_cursorline() 114 " Opens a help window, where 'conceal' is set, switches to the other window 115 " where 'cursorline' needs to be updated when the cursor moves. 116 let code =<< trim [CODE] 117 set cursorline 118 normal othis is a test 119 new 120 call setline(1, ["one", "two", "three", "four", "five"]) 121 set ft=help 122 normal M 123 [CODE] 124 125 call writefile(code, 'XTest_conceal_cul') 126 let buf = RunVimInTerminal('-S XTest_conceal_cul', {}) 127 call VerifyScreenDump(buf, 'Test_conceal_cul_01', {}) 128 129 call term_sendkeys(buf, ":wincmd w\r") 130 call VerifyScreenDump(buf, 'Test_conceal_cul_02', {}) 131 132 call term_sendkeys(buf, "k") 133 call VerifyScreenDump(buf, 'Test_conceal_cul_03', {}) 134 135 " clean up 136 call StopVimInTerminal(buf) 137 call delete('XTest_conceal_cul') 138endfunc 139 140func Test_conceal_resize_term() 141 let code =<< trim [CODE] 142 call setline(1, '`one` `two` `three` `four` `five`, the backticks should be concealed') 143 setl cocu=n cole=3 144 syn region CommentCodeSpan matchgroup=Comment start=/`/ end=/`/ concealends 145 normal fb 146 [CODE] 147 call writefile(code, 'XTest_conceal_resize') 148 let buf = RunVimInTerminal('-S XTest_conceal_resize', {'rows': 6}) 149 call VerifyScreenDump(buf, 'Test_conceal_resize_01', {}) 150 151 call win_execute(buf->win_findbuf()[0], 'wincmd +') 152 call TermWait(buf) 153 call VerifyScreenDump(buf, 'Test_conceal_resize_02', {}) 154 155 " clean up 156 call StopVimInTerminal(buf) 157 call delete('XTest_conceal_resize') 158endfunc 159 160" Tests for correct display (cursor column position) with +conceal and 161" tabulators. Need to run this test in a separate Vim instance. Otherwise the 162" screen is not updated (lazy redraw) and the cursor position is wrong. 163func Test_conceal_cursor_pos() 164 let code =<< trim [CODE] 165 :let l = ['start:', '.concealed. text', "|concealed|\ttext"] 166 :let l += ['', "\t.concealed.\ttext", "\t|concealed|\ttext", ''] 167 :let l += [".a.\t.b.\t.c.\t.d.", "|a|\t|b|\t|c|\t|d|"] 168 :call append(0, l) 169 :call cursor(1, 1) 170 :" Conceal settings. 171 :set conceallevel=2 172 :set concealcursor=nc 173 :syntax match test /|/ conceal 174 :" Save current cursor position. Only works in <expr> mode, can't be used 175 :" with :normal because it moves the cursor to the command line. Thanks 176 :" to ZyX <[email protected]> for the idea to use an <expr> mapping. 177 :let curpos = [] 178 :nnoremap <expr> GG ":let curpos += ['".screenrow().":".screencol()."']\n" 179 :normal ztj 180 GGk 181 :" We should end up in the same column when running these commands on the 182 :" two lines. 183 :normal ft 184 GGk 185 :normal $ 186 GGk 187 :normal 0j 188 GGk 189 :normal ft 190 GGk 191 :normal $ 192 GGk 193 :normal 0j0j 194 GGk 195 :" Same for next test block. 196 :normal ft 197 GGk 198 :normal $ 199 GGk 200 :normal 0j 201 GGk 202 :normal ft 203 GGk 204 :normal $ 205 GGk 206 :normal 0j0j 207 GGk 208 :" And check W with multiple tabs and conceals in a line. 209 :normal W 210 GGk 211 :normal W 212 GGk 213 :normal W 214 GGk 215 :normal $ 216 GGk 217 :normal 0j 218 GGk 219 :normal W 220 GGk 221 :normal W 222 GGk 223 :normal W 224 GGk 225 :normal $ 226 GGk 227 :set lbr 228 :normal $ 229 GGk 230 :set list listchars=tab:>- 231 :normal 0 232 GGk 233 :normal W 234 GGk 235 :normal W 236 GGk 237 :normal W 238 GGk 239 :normal $ 240 GGk 241 :call writefile(curpos, 'Xconceal_curpos.out') 242 :q! 243 244 [CODE] 245 call writefile(code, 'XTest_conceal_curpos') 246 247 if RunVim([], [], '-s XTest_conceal_curpos') 248 call assert_equal([ 249 \ '2:1', '2:17', '2:20', '3:1', '3:17', '3:20', '5:8', '5:25', 250 \ '5:28', '6:8', '6:25', '6:28', '8:1', '8:9', '8:17', '8:25', 251 \ '8:27', '9:1', '9:9', '9:17', '9:25', '9:26', '9:26', '9:1', 252 \ '9:9', '9:17', '9:25', '9:26'], readfile('Xconceal_curpos.out')) 253 endif 254 255 call delete('Xconceal_curpos.out') 256 call delete('XTest_conceal_curpos') 257endfunc 258 259func Test_conceal_eol() 260 new! 261 setlocal concealcursor=n conceallevel=1 262 call setline(1, ["x", ""]) 263 call matchaddpos('Conceal', [[2, 1, 1]], 2, -1, {'conceal': 1}) 264 redraw! 265 266 call assert_notequal(screenchar(1, 1), screenchar(2, 2)) 267 call assert_equal(screenattr(1, 1), screenattr(1, 2)) 268 call assert_equal(screenattr(1, 2), screenattr(2, 2)) 269 call assert_equal(screenattr(2, 1), screenattr(2, 2)) 270 271 set list 272 redraw! 273 274 call assert_equal(screenattr(1, 1), screenattr(2, 2)) 275 call assert_notequal(screenattr(1, 1), screenattr(1, 2)) 276 call assert_notequal(screenattr(1, 2), screenattr(2, 1)) 277 278 set nolist 279endfunc 280 281" vim: shiftwidth=2 sts=2 expandtab 282