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 73" this was causing a crash 74func Test_linebreak_with_list_and_tabs() 75 set linebreak list listchars=tab:⇤\ ⇥ tabstop=100 76 new 77 call setline(1, "\t\t\ttext") 78 redraw 79 bwipe! 80 set nolinebreak nolist listchars&vim tabstop=8 81endfunc 82 83func Test_linebreak_with_nolist() 84 call s:test_windows('setl nolist') 85 call setline(1, "\t*mask = nil;") 86 redraw! 87 let lines = s:screen_lines([1, 4], winwidth(0)) 88 let expect = [ 89\ " *mask = nil; ", 90\ "~ ", 91\ "~ ", 92\ "~ ", 93\ ] 94 call s:compare_lines(expect, lines) 95 call s:close_windows() 96endfunc 97 98func Test_list_and_concealing1() 99 call s:test_windows('setl list listchars=tab:>- cole=1') 100 call setline(1, [ 101\ "#define ABCDE\t\t1", 102\ "#define ABCDEF\t\t1", 103\ "#define ABCDEFG\t\t1", 104\ "#define ABCDEFGH\t1", 105\ "#define MSG_MODE_FILE\t\t\t1", 106\ "#define MSG_MODE_CONSOLE\t\t2", 107\ "#define MSG_MODE_FILE_AND_CONSOLE\t3", 108\ "#define MSG_MODE_FILE_THEN_CONSOLE\t4", 109\ ]) 110 vert resize 40 111 syn match Conceal conceal cchar=>'AB\|MSG_MODE' 112 redraw! 113 let lines = s:screen_lines([1, 7], winwidth(0)) 114 let expect = [ 115\ "#define ABCDE>-->---1 ", 116\ "#define >CDEF>-->---1 ", 117\ "#define >CDEFG>->---1 ", 118\ "#define >CDEFGH>----1 ", 119\ "#define >_FILE>--------->--->---1 ", 120\ "#define >_CONSOLE>---------->---2 ", 121\ "#define >_FILE_AND_CONSOLE>---------3 ", 122\ ] 123 call s:compare_lines(expect, lines) 124 call s:close_windows() 125endfunc 126 127func Test_list_and_concealing2() 128 call s:test_windows('setl nowrap ts=2 list listchars=tab:>- cole=2 concealcursor=n') 129 call setline(1, "bbeeeeee\t\t;\tsome text") 130 vert resize 40 131 syn clear 132 syn match meaning /;\s*\zs.*/ 133 syn match hasword /^\x\{8}/ contains=word 134 syn match word /\<\x\{8}\>/ contains=beginword,endword contained 135 syn match beginword /\<\x\x/ contained conceal 136 syn match endword /\x\{6}\>/ contained 137 hi meaning guibg=blue 138 hi beginword guibg=green 139 hi endword guibg=red 140 redraw! 141 let lines = s:screen_lines([1, 1], winwidth(0)) 142 let expect = [ 143\ "eeeeee>--->-;>some text ", 144\ ] 145 call s:compare_lines(expect, lines) 146 call s:close_windows() 147endfunc 148 149func Test_screenattr_for_comment() 150 call s:test_windows("setl ft=c ts=7 list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6") 151 call setline(1, " /*\t\t and some more */") 152 norm! gg0 153 syntax on 154 hi SpecialKey term=underline ctermfg=red guifg=red 155 redraw! 156 let line = getline(1) 157 let attr = s:screen_attr(1, [1, 6]) 158 call assert_notequal(attr[0], attr[1]) 159 call assert_notequal(attr[1], attr[3]) 160 call assert_notequal(attr[3], attr[5]) 161 call s:close_windows() 162endfunc 163 164func Test_visual_block_and_selection_exclusive() 165 call s:test_windows('setl selection=exclusive') 166 call setline(1, "long line: " . repeat("foobar ", 40) . "TARGETÃ' at end") 167 exe "norm! $3B\<C-v>eAx\<Esc>" 168 let lines = s:screen_lines([1, 10], winwidth(0)) 169 let expect = [ 170\ "+foobar foobar ", 171\ "+foobar foobar ", 172\ "+foobar foobar ", 173\ "+foobar foobar ", 174\ "+foobar foobar ", 175\ "+foobar foobar ", 176\ "+foobar foobar ", 177\ "+foobar foobar ", 178\ "+foobar foobar ", 179\ "+foobar TARGETÃx' ", 180\ ] 181 call s:compare_lines(expect, lines) 182 call s:close_windows() 183endfunc 184 185func Test_multibyte_sign_and_colorcolumn() 186 call s:test_windows("setl nolinebreak cc=3 list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6") 187 call setline(1, ["", "a b c", "a b c"]) 188 exe "sign define foo text=\uff0b" 189 exe "sign place 1 name=foo line=2 buffer=" . bufnr('%') 190 redraw! 191 norm! ggj0 192 let signwidth = strdisplaywidth("\uff0b") 193 let attr1 = s:screen_attr(2, [1, 3], signwidth) 194 let attr2 = s:screen_attr(3, [1, 3], signwidth) 195 call assert_equal(attr1[0], attr2[0]) 196 call assert_equal(attr1[1], attr2[1]) 197 call assert_equal(attr1[2], attr2[2]) 198 let lines = s:screen_lines([1, 3], winwidth(0)) 199 let expect = [ 200\ " ¶ ", 201\ "+a b c¶ ", 202\ " a b c¶ ", 203\ ] 204 call s:compare_lines(expect, lines) 205 call s:close_windows() 206endfunc 207 208func Test_colorcolumn_priority() 209 call s:test_windows('setl cc=4 cuc hls') 210 call setline(1, ["xxyy", ""]) 211 norm! gg 212 exe "normal! /xxyy\<CR>" 213 norm! G 214 redraw! 215 let line_attr = s:screen_attr(1, [1, &cc]) 216 " Search wins over CursorColumn 217 call assert_equal(line_attr[1], line_attr[0]) 218 " Search wins over Colorcolumn 219 call assert_equal(line_attr[2], line_attr[3]) 220 call s:close_windows('setl hls&vim') 221endfunc 222 223func Test_illegal_byte_and_breakat() 224 call s:test_windows("setl sbr= brk+=<") 225 vert resize 18 226 call setline(1, repeat("\x80", 6)) 227 redraw! 228 let lines = s:screen_lines([1, 2], winwidth(0)) 229 let expect = [ 230\ "<80><80><80><80><8", 231\ "0><80> ", 232\ ] 233 call s:compare_lines(expect, lines) 234 call s:close_windows('setl brk&vim') 235endfunc 236 237func Test_multibyte_wrap_and_breakat() 238 call s:test_windows("setl sbr= brk+=>") 239 call setline(1, repeat('a', 17) . repeat('あ', 2)) 240 redraw! 241 let lines = s:screen_lines([1, 2], winwidth(0)) 242 let expect = [ 243\ "aaaaaaaaaaaaaaaaaあ>", 244\ "あ ", 245\ ] 246 call s:compare_lines(expect, lines) 247 call s:close_windows('setl brk&vim') 248endfunc 249 250func Test_chinese_char_on_wrap_column() 251 call s:test_windows("setl nolbr wrap sbr=") 252 syntax off 253 call setline(1, [ 254\ 'aaaaaaaaaaaaaaaaaaa中'. 255\ 'aaaaaaaaaaaaaaaaa中'. 256\ 'aaaaaaaaaaaaaaaaa中'. 257\ 'aaaaaaaaaaaaaaaaa中'. 258\ 'aaaaaaaaaaaaaaaaa中'. 259\ 'aaaaaaaaaaaaaaaaa中'. 260\ 'aaaaaaaaaaaaaaaaa中'. 261\ 'aaaaaaaaaaaaaaaaa中'. 262\ 'aaaaaaaaaaaaaaaaa中'. 263\ 'aaaaaaaaaaaaaaaaa中'. 264\ 'hello']) 265 call cursor(1,1) 266 norm! $ 267 redraw! 268 let expect=[ 269\ '中aaaaaaaaaaaaaaaaa>', 270\ '中aaaaaaaaaaaaaaaaa>', 271\ '中aaaaaaaaaaaaaaaaa>', 272\ '中aaaaaaaaaaaaaaaaa>', 273\ '中aaaaaaaaaaaaaaaaa>', 274\ '中aaaaaaaaaaaaaaaaa>', 275\ '中aaaaaaaaaaaaaaaaa>', 276\ '中aaaaaaaaaaaaaaaaa>', 277\ '中aaaaaaaaaaaaaaaaa>', 278\ '中hello '] 279 let lines = s:screen_lines([1, 10], winwidth(0)) 280 call s:compare_lines(expect, lines) 281 call s:close_windows() 282endfunc 283 284" vim: shiftwidth=2 sts=2 expandtab 285