| Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 1 | " Test for linebreak and list option in utf-8 mode |
| 2 | |
| 3 | set encoding=utf-8 |
| 4 | scriptencoding utf-8 |
| 5 | |
| Bram Moolenaar | b46fecd | 2019-06-15 17:58:09 +0200 | [diff] [blame] | 6 | source check.vim |
| 7 | CheckOption linebreak |
| 8 | CheckFeature conceal |
| 9 | CheckFeature signs |
| Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 10 | |
| 11 | source view_util.vim |
| 12 | |
| Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 13 | func s:screen_lines(lnum, width) abort |
| Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 14 | return ScreenLines(a:lnum, a:width) |
| Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 15 | endfunc |
| Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 16 | |
| Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 17 | func s:compare_lines(expect, actual) |
| Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 18 | call assert_equal(a:expect, a:actual) |
| Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 19 | endfunc |
| Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 20 | |
| Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 21 | func s:screen_attr(lnum, chars, ...) abort |
| Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 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 |
| Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 30 | endfunc |
| Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 31 | |
| Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 32 | func s:test_windows(...) |
| Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 33 | call NewWindow(10, 20) |
| 34 | setl ts=4 sw=4 sts=4 linebreak sbr=+ wrap |
| 35 | exe get(a:000, 0, '') |
| Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 36 | endfunc |
| Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 37 | |
| Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 38 | func s:close_windows(...) |
| Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 39 | call CloseWindow() |
| 40 | exe get(a:000, 0, '') |
| Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 41 | endfunc |
| Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 42 | |
| 43 | func 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() |
| 56 | endfunc |
| 57 | |
| 58 | func 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() |
| 71 | endfunc |
| 72 | |
| Bram Moolenaar | 89a54b4 | 2021-09-07 20:45:31 +0200 | [diff] [blame] | 73 | " this was causing a crash |
| 74 | func 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 |
| 81 | endfunc |
| 82 | |
| Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 83 | func 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() |
| 96 | endfunc |
| 97 | |
| 98 | func 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() |
| 125 | endfunc |
| 126 | |
| 127 | func 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() |
| 147 | endfunc |
| 148 | |
| 149 | func 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() |
| 162 | endfunc |
| 163 | |
| 164 | func 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 = [ |
| Bram Moolenaar | 0937b9f | 2022-10-06 21:24:34 +0100 | [diff] [blame^] | 170 | \ "+foobar foobar ", |
| Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 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() |
| 183 | endfunc |
| 184 | |
| 185 | func 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() |
| 206 | endfunc |
| Bram Moolenaar | 38632fa | 2017-02-26 19:40:59 +0100 | [diff] [blame] | 207 | |
| Bram Moolenaar | 774e5a9 | 2017-06-25 18:03:37 +0200 | [diff] [blame] | 208 | func 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') |
| 221 | endfunc |
| 222 | |
| Bram Moolenaar | 38632fa | 2017-02-26 19:40:59 +0100 | [diff] [blame] | 223 | func 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') |
| 235 | endfunc |
| 236 | |
| 237 | func 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') |
| 248 | endfunc |
| Bram Moolenaar | abc39ab | 2017-03-01 18:04:05 +0100 | [diff] [blame] | 249 | |
| 250 | func 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=[ |
| Bram Moolenaar | 0466d39 | 2022-10-03 17:07:34 +0100 | [diff] [blame] | 269 | \ '<<<aaaaaaaaaaaaaaaa>', |
| Bram Moolenaar | abc39ab | 2017-03-01 18:04:05 +0100 | [diff] [blame] | 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() |
| Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 282 | endfunc |
| 283 | |
| 284 | " vim: shiftwidth=2 sts=2 expandtab |