1" Test for linebreak and list option in utf-8 mode 2 3set encoding=utf-8 4scriptencoding utf-8 5 6source check.vim 7CheckOption linebreak 8CheckFeature conceal 9CheckFeature signs 10 11source view_util.vim 12 13func s:screen_lines(lnum, width) abort 14 return ScreenLines(a:lnum, a:width) 15endfunc 16 17func s:compare_lines(expect, actual) 18 call assert_equal(a:expect, a:actual) 19endfunc 20 21func s:screen_attr(lnum, chars, ...) abort 22 let line = getline(a:lnum) 23 let attr = [] 24 let prefix = get(a:000, 0, 0) 25 for i in range(a:chars[0], a:chars[1]) 26 let scol = strdisplaywidth(strcharpart(line, 0, i-1)) + 1 27 let attr += [screenattr(a:lnum, scol + prefix)] 28 endfor 29 return attr 30endfunc 31 32func s:test_windows(...) 33 call NewWindow(10, 20) 34 setl ts=4 sw=4 sts=4 linebreak sbr=+ wrap 35 exe get(a:000, 0, '') 36endfunc 37 38func s:close_windows(...) 39 call CloseWindow() 40 exe get(a:000, 0, '') 41endfunc 42 43func Test_linebreak_with_fancy_listchars() 44 call s:test_windows("setl list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6") 45 call setline(1, "\tabcdef hijklmn\tpqrstuvwxyz\u00a01060ABCDEFGHIJKLMNOP ") 46 redraw! 47 let lines = s:screen_lines([1, 4], winwidth(0)) 48 let expect = [ 49\ "▕———abcdef ", 50\ "+hijklmn▕——— ", 51\ "+pqrstuvwxyz␣1060ABC", 52\ "+DEFGHIJKLMNOPˑ¶ ", 53\ ] 54 call s:compare_lines(expect, lines) 55 call s:close_windows() 56endfunc 57 58func Test_nolinebreak_with_list() 59 call s:test_windows("setl nolinebreak list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6") 60 call setline(1, "\tabcdef hijklmn\tpqrstuvwxyz\u00a01060ABCDEFGHIJKLMNOP ") 61 redraw! 62 let lines = s:screen_lines([1, 4], winwidth(0)) 63 let expect = [ 64\ "▕———abcdef hijklmn▕—", 65\ "+pqrstuvwxyz␣1060ABC", 66\ "+DEFGHIJKLMNOPˑ¶ ", 67\ "~ ", 68\ ] 69 call s:compare_lines(expect, lines) 70 call s:close_windows() 71endfunc 72 73func Test_linebreak_with_nolist() 74 call s:test_windows('setl nolist') 75 call setline(1, "\t*mask = nil;") 76 redraw! 77 let lines = s:screen_lines([1, 4], winwidth(0)) 78 let expect = [ 79\ " *mask = nil; ", 80\ "~ ", 81\ "~ ", 82\ "~ ", 83\ ] 84 call s:compare_lines(expect, lines) 85 call s:close_windows() 86endfunc 87 88func Test_list_and_concealing1() 89 call s:test_windows('setl list listchars=tab:>- cole=1') 90 call setline(1, [ 91\ "#define ABCDE\t\t1", 92\ "#define ABCDEF\t\t1", 93\ "#define ABCDEFG\t\t1", 94\ "#define ABCDEFGH\t1", 95\ "#define MSG_MODE_FILE\t\t\t1", 96\ "#define MSG_MODE_CONSOLE\t\t2", 97\ "#define MSG_MODE_FILE_AND_CONSOLE\t3", 98\ "#define MSG_MODE_FILE_THEN_CONSOLE\t4", 99\ ]) 100 vert resize 40 101 syn match Conceal conceal cchar=>'AB\|MSG_MODE' 102 redraw! 103 let lines = s:screen_lines([1, 7], winwidth(0)) 104 let expect = [ 105\ "#define ABCDE>-->---1 ", 106\ "#define >CDEF>-->---1 ", 107\ "#define >CDEFG>->---1 ", 108\ "#define >CDEFGH>----1 ", 109\ "#define >_FILE>--------->--->---1 ", 110\ "#define >_CONSOLE>---------->---2 ", 111\ "#define >_FILE_AND_CONSOLE>---------3 ", 112\ ] 113 call s:compare_lines(expect, lines) 114 call s:close_windows() 115endfunc 116 117func Test_list_and_concealing2() 118 call s:test_windows('setl nowrap ts=2 list listchars=tab:>- cole=2 concealcursor=n') 119 call setline(1, "bbeeeeee\t\t;\tsome text") 120 vert resize 40 121 syn clear 122 syn match meaning /;\s*\zs.*/ 123 syn match hasword /^\x\{8}/ contains=word 124 syn match word /\<\x\{8}\>/ contains=beginword,endword contained 125 syn match beginword /\<\x\x/ contained conceal 126 syn match endword /\x\{6}\>/ contained 127 hi meaning guibg=blue 128 hi beginword guibg=green 129 hi endword guibg=red 130 redraw! 131 let lines = s:screen_lines([1, 1], winwidth(0)) 132 let expect = [ 133\ "eeeeee>--->-;>some text ", 134\ ] 135 call s:compare_lines(expect, lines) 136 call s:close_windows() 137endfunc 138 139func Test_screenattr_for_comment() 140 call s:test_windows("setl ft=c ts=7 list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6") 141 call setline(1, " /*\t\t and some more */") 142 norm! gg0 143 syntax on 144 hi SpecialKey term=underline ctermfg=red guifg=red 145 redraw! 146 let line = getline(1) 147 let attr = s:screen_attr(1, [1, 6]) 148 call assert_notequal(attr[0], attr[1]) 149 call assert_notequal(attr[1], attr[3]) 150 call assert_notequal(attr[3], attr[5]) 151 call s:close_windows() 152endfunc 153 154func Test_visual_block_and_selection_exclusive() 155 call s:test_windows('setl selection=exclusive') 156 call setline(1, "long line: " . repeat("foobar ", 40) . "TARGETÃ' at end") 157 exe "norm! $3B\<C-v>eAx\<Esc>" 158 let lines = s:screen_lines([1, 10], winwidth(0)) 159 let expect = [ 160\ "+foobar foobar ", 161\ "+foobar foobar ", 162\ "+foobar foobar ", 163\ "+foobar foobar ", 164\ "+foobar foobar ", 165\ "+foobar foobar ", 166\ "+foobar foobar ", 167\ "+foobar foobar ", 168\ "+foobar foobar ", 169\ "+foobar TARGETÃx' ", 170\ ] 171 call s:compare_lines(expect, lines) 172 call s:close_windows() 173endfunc 174 175func Test_multibyte_sign_and_colorcolumn() 176 call s:test_windows("setl nolinebreak cc=3 list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6") 177 call setline(1, ["", "a b c", "a b c"]) 178 exe "sign define foo text=\uff0b" 179 exe "sign place 1 name=foo line=2 buffer=" . bufnr('%') 180 redraw! 181 norm! ggj0 182 let signwidth = strdisplaywidth("\uff0b") 183 let attr1 = s:screen_attr(2, [1, 3], signwidth) 184 let attr2 = s:screen_attr(3, [1, 3], signwidth) 185 call assert_equal(attr1[0], attr2[0]) 186 call assert_equal(attr1[1], attr2[1]) 187 call assert_equal(attr1[2], attr2[2]) 188 let lines = s:screen_lines([1, 3], winwidth(0)) 189 let expect = [ 190\ " ¶ ", 191\ "+a b c¶ ", 192\ " a b c¶ ", 193\ ] 194 call s:compare_lines(expect, lines) 195 call s:close_windows() 196endfunc 197 198func Test_colorcolumn_priority() 199 call s:test_windows('setl cc=4 cuc hls') 200 call setline(1, ["xxyy", ""]) 201 norm! gg 202 exe "normal! /xxyy\<CR>" 203 norm! G 204 redraw! 205 let line_attr = s:screen_attr(1, [1, &cc]) 206 " Search wins over CursorColumn 207 call assert_equal(line_attr[1], line_attr[0]) 208 " Search wins over Colorcolumn 209 call assert_equal(line_attr[2], line_attr[3]) 210 call s:close_windows('setl hls&vim') 211endfunc 212 213func Test_illegal_byte_and_breakat() 214 call s:test_windows("setl sbr= brk+=<") 215 vert resize 18 216 call setline(1, repeat("\x80", 6)) 217 redraw! 218 let lines = s:screen_lines([1, 2], winwidth(0)) 219 let expect = [ 220\ "<80><80><80><80><8", 221\ "0><80> ", 222\ ] 223 call s:compare_lines(expect, lines) 224 call s:close_windows('setl brk&vim') 225endfunc 226 227func Test_multibyte_wrap_and_breakat() 228 call s:test_windows("setl sbr= brk+=>") 229 call setline(1, repeat('a', 17) . repeat('あ', 2)) 230 redraw! 231 let lines = s:screen_lines([1, 2], winwidth(0)) 232 let expect = [ 233\ "aaaaaaaaaaaaaaaaaあ>", 234\ "あ ", 235\ ] 236 call s:compare_lines(expect, lines) 237 call s:close_windows('setl brk&vim') 238endfunc 239 240func Test_chinese_char_on_wrap_column() 241 call s:test_windows("setl nolbr wrap sbr=") 242 syntax off 243 call setline(1, [ 244\ 'aaaaaaaaaaaaaaaaaaa中'. 245\ 'aaaaaaaaaaaaaaaaa中'. 246\ 'aaaaaaaaaaaaaaaaa中'. 247\ 'aaaaaaaaaaaaaaaaa中'. 248\ 'aaaaaaaaaaaaaaaaa中'. 249\ 'aaaaaaaaaaaaaaaaa中'. 250\ 'aaaaaaaaaaaaaaaaa中'. 251\ 'aaaaaaaaaaaaaaaaa中'. 252\ 'aaaaaaaaaaaaaaaaa中'. 253\ 'aaaaaaaaaaaaaaaaa中'. 254\ 'hello']) 255 call cursor(1,1) 256 norm! $ 257 redraw! 258 let expect=[ 259\ '中aaaaaaaaaaaaaaaaa>', 260\ '中aaaaaaaaaaaaaaaaa>', 261\ '中aaaaaaaaaaaaaaaaa>', 262\ '中aaaaaaaaaaaaaaaaa>', 263\ '中aaaaaaaaaaaaaaaaa>', 264\ '中aaaaaaaaaaaaaaaaa>', 265\ '中aaaaaaaaaaaaaaaaa>', 266\ '中aaaaaaaaaaaaaaaaa>', 267\ '中aaaaaaaaaaaaaaaaa>', 268\ '中hello '] 269 let lines = s:screen_lines([1, 10], winwidth(0)) 270 call s:compare_lines(expect, lines) 271 call s:close_windows() 272endfu 273