summaryrefslogtreecommitdiffstats
path: root/src/testdir/test_listlbr_utf8.vim
blob: 313ff30cc41cda435b9ac429a900638c8e741cb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
" Test for linebreak and list option in utf-8 mode

set encoding=utf-8
scriptencoding utf-8

source check.vim
CheckOption linebreak
CheckFeature conceal
CheckFeature signs

source view_util.vim
source screendump.vim

func s:screen_lines(lnum, width) abort
  return ScreenLines(a:lnum, a:width)
endfunc

func s:compare_lines(expect, actual)
  call assert_equal(a:expect, a:actual)
endfunc

func s:screen_attr(lnum, chars, ...) abort
  let line = getline(a:lnum)
  let attr = []
  let prefix = get(a:000, 0, 0)
  for i in range(a:chars[0], a:chars[1])
    let scol = strdisplaywidth(strcharpart(line, 0, i-1)) + 1
    let attr += [screenattr(a:lnum, scol + prefix)]
  endfor
  return attr
endfunc

func s:test_windows(...)
  call NewWindow(10, 20)
  setl ts=4 sw=4 sts=4 linebreak sbr=+ wrap
  exe get(a:000, 0, '')
endfunc

func s:close_windows(...)
  call CloseWindow()
  exe get(a:000, 0, '')
endfunc

func Test_linebreak_with_fancy_listchars()
  call s:test_windows("setl list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6")
  call setline(1, "\tabcdef hijklmn\tpqrstuvwxyz\u00a01060ABCDEFGHIJKLMNOP ")
  redraw!
  let lines = s:screen_lines([1, 4], winwidth(0))
  let expect = [
\ "▕———abcdef          ",
\ "+hijklmn▕———        ",
\ "+pqrstuvwxyz␣1060ABC",
\ "+DEFGHIJKLMNOPˑ¶    ",
\ ]
  call s:compare_lines(expect, lines)
  call s:close_windows()
endfunc

func Test_nolinebreak_with_list()
  call s:test_windows("setl nolinebreak list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6")
  call setline(1, "\tabcdef hijklmn\tpqrstuvwxyz\u00a01060ABCDEFGHIJKLMNOP ")
  redraw!
  let lines = s:screen_lines([1, 4], winwidth(0))
  let expect = [
\ "▕———abcdef hijklmn▕—",
\ "+pqrstuvwxyz␣1060ABC",
\ "+DEFGHIJKLMNOPˑ¶    ",
\ "~                   ",
\ ]
  call s:compare_lines(expect, lines)
  call s:close_windows()
endfunc

" this was causing a crash
func Test_linebreak_with_list_and_tabs()
  set linebreak list listchars=tab:⇤\ ⇥ tabstop=100
  new
  call setline(1, "\t\t\ttext")
  redraw
  bwipe!
  set nolinebreak nolist listchars&vim tabstop=8
endfunc

func Test_linebreak_with_nolist()
  call s:test_windows('setl nolist')
  call setline(1, "\t*mask = nil;")
  redraw!
  let lines = s:screen_lines([1, 4], winwidth(0))
  let expect = [
\ "    *mask = nil;    ",
\ "~                   ",
\ "~                   ",
\ "~                   ",
\ ]
  call s:compare_lines(expect, lines)
  call s:close_windows()
endfunc

func Test_list_and_concealing1()
  call s:test_windows('setl list listchars=tab:>- cole=1')
  call setline(1, [
\ "#define ABCDE\t\t1",
\ "#define ABCDEF\t\t1",
\ "#define ABCDEFG\t\t1",
\ "#define ABCDEFGH\t1",
\ "#define MSG_MODE_FILE\t\t\t1",
\ "#define MSG_MODE_CONSOLE\t\t2",
\ "#define MSG_MODE_FILE_AND_CONSOLE\t3",
\ "#define MSG_MODE_FILE_THEN_CONSOLE\t4",
\ ])
  vert resize 40
  syn match Conceal conceal cchar=>'AB\|MSG_MODE'
  redraw!
  let lines = s:screen_lines([1, 7], winwidth(0))
  let expect = [
\ "#define ABCDE>-->---1                   ",
\ "#define >CDEF>-->---1                   ",
\ "#define >CDEFG>->---1                   ",
\ "#define >CDEFGH>----1                   ",
\ "#define >_FILE>--------->--->---1       ",
\ "#define >_CONSOLE>---------->---2       ",
\ "#define >_FILE_AND_CONSOLE>---------3   ",
\ ]
  call s:compare_lines(expect, lines)
  call s:close_windows()
endfunc

func Test_list_and_concealing2()
  call s:test_windows('setl nowrap ts=2 list listchars=tab:>- cole=2 concealcursor=n')
  call setline(1, "bbeeeeee\t\t;\tsome text")
  vert resize 40
  syn clear
  syn match meaning    /;\s*\zs.*/
  syn match hasword    /^\x\{8}/    contains=word
  syn match word       /\<\x\{8}\>/ contains=beginword,endword contained
  syn match beginword  /\<\x\x/     contained conceal
  syn match endword    /\x\{6}\>/   contained
  hi meaning   guibg=blue
  hi beginword guibg=green
  hi endword   guibg=red
  redraw!
  let lines = s:screen_lines([1, 1], winwidth(0))
  let expect = [
\ "eeeeee>--->-;>some text                 ",
\ ]
  call s:compare_lines(expect, lines)
  call s:close_windows()
endfunc

func Test_screenattr_for_comment()
  call s:test_windows("setl ft=c ts=7 list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6")
  call setline(1, " /*\t\t and some more */")
  norm! gg0
  syntax on
  hi SpecialKey term=underline ctermfg=red guifg=red
  redraw!
  let line = getline(1)
  let attr = s:screen_attr(1, [1, 6])
  call assert_notequal(attr[0], attr[1])
  call assert_notequal(attr[1], attr[3])
  call assert_notequal(attr[3], attr[5])
  call s:close_windows()
endfunc

func Test_visual_block_and_selection_exclusive()
  call s:test_windows('setl selection=exclusive')
  call setline(1, "long line: " . repeat("foobar ", 40) . "TARGETÃ' at end")
  exe "norm! $3B\<C-v>eAx\<Esc>"
  let lines = s:screen_lines([1, 10], winwidth(0))
  let expect = [
\ "+foobar foobar      ",
\ "+foobar foobar      ",
\ "+foobar foobar      ",
\ "+foobar foobar      ",
\ "+foobar foobar      ",
\ "+foobar foobar      ",
\ "+foobar foobar      ",
\ "+foobar foobar      ",
\ "+foobar foobar      ",
\ "+foobar TARGETÃx'   ",
\ ]
  call s:compare_lines(expect, lines)
  call s:close_windows()
endfunc

func Test_multibyte_sign_and_colorcolumn()
  call s:test_windows("setl nolinebreak cc=3 list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6")
  call setline(1, ["", "a b c", "a b c"])
  exe "sign define foo text=\uff0b"
  exe "sign place 1 name=foo line=2 buffer=" . bufnr('%')
  redraw!
  norm! ggj0
  let signwidth = strdisplaywidth("\uff0b")
  let attr1 = s:screen_attr(2, [1, 3], signwidth)
  let attr2 = s:screen_attr(3, [1, 3], signwidth)
  call assert_equal(attr1[0], attr2[0])
  call assert_equal(attr1[1], attr2[1])
  call assert_equal(attr1[2], attr2[2])
  let lines = s:screen_lines([1, 3], winwidth(0))
  let expect = [
\ "  ¶                 ",
\ "+a b c¶            ",
\ "  a b c¶            ",
\ ]
  call s:compare_lines(expect, lines)
  call s:close_windows()
endfunc

func Test_colorcolumn_priority()
  call s:test_windows('setl cc=4 cuc hls')
  call setline(1, ["xxyy", ""])
  norm! gg
  exe "normal! /xxyy\<CR>"
  norm! G
  redraw!
  let line_attr = s:screen_attr(1, [1, &cc])
  " Search wins over CursorColumn
  call assert_equal(line_attr[1], line_attr[0])
  " Search wins over Colorcolumn
  call assert_equal(line_attr[2], line_attr[3])
  call s:close_windows('setl hls&vim')
endfunc

func Test_illegal_byte_and_breakat()
  call s:test_windows("setl sbr= brk+=<")
  vert resize 18
  call setline(1, repeat("\x80", 6))
  redraw!
  let lines = s:screen_lines([1, 2], winwidth(0))
  let expect = [
\ "<80><80><80><80><8",
\ "0><80>            ",
\ ]
  call s:compare_lines(expect, lines)
  call s:close_windows('setl brk&vim')
endfunc

func Test_multibyte_wrap_and_breakat()
  call s:test_windows("setl sbr= brk+=>")
  call setline(1, repeat('a', 17) . repeat('あ', 2))
  redraw!
  let lines = s:screen_lines([1, 2], winwidth(0))
  let expect = [
\ "aaaaaaaaaaaaaaaaaあ>",
\ "あ                  ",
\ ]
  call s:compare_lines(expect, lines)
  call s:close_windows('setl brk&vim')
endfunc

func Test_chinese_char_on_wrap_column()
  call s:test_windows("setl nolbr wrap sbr=")
  call setline(1, [
\ 'aaaaaaaaaaaaaaaaaaa中'.
\ 'aaaaaaaaaaaaaaaaa中'.
\ 'aaaaaaaaaaaaaaaaa中'.
\ 'aaaaaaaaaaaaaaaaa中'.
\ 'aaaaaaaaaaaaaaaaa中'.
\ 'aaaaaaaaaaaaaaaaa中'.
\ 'aaaaaaaaaaaaaaaaa中'.
\ 'aaaaaaaaaaaaaaaaa中'.
\ 'aaaaaaaaaaaaaaaaa中'.
\ 'aaaaaaaaaaaaaaaaa中'.
\ 'hello'])
  call cursor(1,1)
  norm! $
  redraw!
  let expect=[
\ '<<<aaaaaaaaaaaaaaaa>',
\ '中aaaaaaaaaaaaaaaaa>',
\ '中aaaaaaaaaaaaaaaaa>',
\ '中aaaaaaaaaaaaaaaaa>',
\ '中aaaaaaaaaaaaaaaaa>',
\ '中aaaaaaaaaaaaaaaaa>',
\ '中aaaaaaaaaaaaaaaaa>',
\ '中aaaaaaaaaaaaaaaaa>',
\ '中aaaaaaaaaaaaaaaaa>',
\ '中hello             ']
  let lines = s:screen_lines([1, 10], winwidth(0))
  call s:compare_lines(expect, lines)
  call assert_equal(len(expect), winline())
  call assert_equal(strwidth(trim(expect[-1], ' ', 2)), wincol())
  call s:close_windows()
endfunc

func Test_chinese_char_on_wrap_column_sbr()
  call s:test_windows("setl nolbr wrap sbr=!!!")
  call setline(1, [
\ 'aaaaaaaaaaaaaaaaaaa中'.
\ 'aaaaaaaaaaaaaa中'.
\ 'aaaaaaaaaaaaaa中'.
\ 'aaaaaaaaaaaaaa中'.
\ 'aaaaaaaaaaaaaa中'.
\ 'aaaaaaaaaaaaaa中'.
\ 'aaaaaaaaaaaaaa中'.
\ 'aaaaaaaaaaaaaa中'.
\ 'aaaaaaaaaaaaaa中'.
\ 'aaaaaaaaaaaaaa中'.
\ 'hello'])
  call cursor(1,1)
  norm! $
  redraw!
  let expect=[
\ '!!!中aaaaaaaaaaaaaa>',
\ '!!!中aaaaaaaaaaaaaa>',
\ '!!!中aaaaaaaaaaaaaa>',
\ '!!!中aaaaaaaaaaaaaa>',
\ '!!!中aaaaaaaaaaaaaa>',
\ '!!!中aaaaaaaaaaaaaa>',
\ '!!!中aaaaaaaaaaaaaa>',
\ '!!!中aaaaaaaaaaaaaa>',
\ '!!!中aaaaaaaaaaaaaa>',
\ '!!!中hello          ']
  let lines = s:screen_lines([1, 10], winwidth(0))
  call s:compare_lines(expect, lines)
  call assert_equal(len(expect), winline())
  call assert_equal(strwidth(trim(expect[-1], ' ', 2)), wincol())
  call s:close_windows()
endfunc

func Test_unprintable_char_on_wrap_column()
  call s:test_windows("setl nolbr wrap sbr=")
  call setline(1, 'aaa' .. repeat("\uFEFF", 50) .. 'bbb')
  call cursor(1,1)
  norm! $
  redraw!
  let expect=[
\ '<<<<feff><feff><feff',
\ '><feff><feff><feff><',
\ 'feff><feff><feff><fe',
\ 'ff><feff><feff><feff',
\ '><feff><feff><feff><',
\ 'feff><feff><feff><fe',
\ 'ff><feff><feff><feff',
\ '><feff><feff><feff><',
\ 'feff><feff><feff><fe',
\ 'ff>bbb              ']
  let lines = s:screen_lines([1, 10], winwidth(0))
  call s:compare_lines(expect, lines)
  call assert_equal(len(expect), winline())
  call assert_equal(strwidth(trim(expect[-1], ' ', 2)), wincol())
  setl sbr=!!
  redraw!
  let expect=[
\ '!!><feff><feff><feff',
\ '!!><feff><feff><feff',
\ '!!><feff><feff><feff',
\ '!!><feff><feff><feff',
\ '!!><feff><feff><feff',
\ '!!><feff><feff><feff',
\ '!!><feff><feff><feff',
\ '!!><feff><feff><feff',
\ '!!><feff><feff><feff',
\ '!!><feff><feff>bbb  ']
  let lines = s:screen_lines([1, 10], winwidth(0))
  call s:compare_lines(expect, lines)
  call assert_equal(len(expect), winline())
  call assert_equal(strwidth(trim(expect[-1], ' ', 2)), wincol())
  call s:close_windows()
endfunc

" Test that Visual selection is drawn correctly when 'linebreak' is set and
" selection ends before multibyte 'showbreak'.
func Test_visual_ends_before_showbreak()
  CheckScreendump

  let lines =<< trim END
      vim9script
      &wrap = true
      &linebreak = true
      &showbreak = '↪ '
      ['xxxxx ' .. 'y'->repeat(&columns - 6) .. ' zzzz']->setline(1)
      normal! wvel
  END
  call writefile(lines, 'XvisualEndsBeforeShowbreak', 'D')
  let buf = RunVimInTerminal('-S XvisualEndsBeforeShowbreak', #{rows: 6})
  call VerifyScreenDump(buf, 'Test_visual_ends_before_showbreak', {})

  call StopVimInTerminal(buf)
endfunc

" vim: shiftwidth=2 sts=2 expandtab