robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqvim-patch:9.2.0295: 'showcmd' shows wrong Visual block size with 'linebreak' (#38756)d10dda8a47

master
13.3 KiB456 linesraw
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
12source screendump.vim
13
14func s:screen_lines(lnum, width) abort
15  return ScreenLines(a:lnum, a:width)
16endfunc
17
18func s:compare_lines(expect, actual)
19  call assert_equal(a:expect, a:actual)
20endfunc
21
22func s:screen_attr(lnum, chars, ...) abort
23  let line = getline(a:lnum)
24  let attr = []
25  let prefix = get(a:000, 0, 0)
26  for i in range(a:chars[0], a:chars[1])
27    let scol = strdisplaywidth(strcharpart(line, 0, i-1)) + 1
28    let attr += [screenattr(a:lnum, scol + prefix)]
29  endfor
30  return attr
31endfunc
32
33func s:test_windows(...)
34  call NewWindow(10, 20)
35  setl ts=4 sw=4 sts=4 linebreak sbr=+ wrap
36  exe get(a:000, 0, '')
37endfunc
38
39func s:close_windows(...)
40  call CloseWindow()
41  exe get(a:000, 0, '')
42endfunc
43
44func Test_linebreak_with_fancy_listchars()
45  call s:test_windows("setl list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6")
46  call setline(1, "\tabcdef hijklmn\tpqrstuvwxyz\u00a01060ABCDEFGHIJKLMNOP ")
47  redraw!
48  let lines = s:screen_lines([1, 4], winwidth(0))
49  let expect = [
50\ "▕———abcdef          ",
51\ "+hijklmn▕———        ",
52\ "+pqrstuvwxyz␣1060ABC",
53\ "+DEFGHIJKLMNOPˑ¶    ",
54\ ]
55  call s:compare_lines(expect, lines)
56  call s:close_windows()
57endfunc
58
59func Test_nolinebreak_with_list()
60  call s:test_windows("setl nolinebreak list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6")
61  call setline(1, "\tabcdef hijklmn\tpqrstuvwxyz\u00a01060ABCDEFGHIJKLMNOP ")
62  redraw!
63  let lines = s:screen_lines([1, 4], winwidth(0))
64  let expect = [
65\ "▕———abcdef hijklmn▕—",
66\ "+pqrstuvwxyz␣1060ABC",
67\ "+DEFGHIJKLMNOPˑ¶    ",
68\ "~                   ",
69\ ]
70  call s:compare_lines(expect, lines)
71  call s:close_windows()
72endfunc
73
74" this was causing a crash
75func Test_linebreak_with_list_and_tabs()
76  set linebreak list listchars=tab:⇤\ ⇥ tabstop=100
77  new
78  call setline(1, "\t\t\ttext")
79  redraw
80  bwipe!
81  set nolinebreak nolist listchars&vim tabstop=8
82endfunc
83
84func Test_linebreak_with_nolist()
85  call s:test_windows('setl nolist')
86  call setline(1, "\t*mask = nil;")
87  redraw!
88  let lines = s:screen_lines([1, 4], winwidth(0))
89  let expect = [
90\ "    *mask = nil;    ",
91\ "~                   ",
92\ "~                   ",
93\ "~                   ",
94\ ]
95  call s:compare_lines(expect, lines)
96  call s:close_windows()
97endfunc
98
99func Test_list_and_concealing1()
100  call s:test_windows('setl list listchars=tab:>- cole=1')
101  call setline(1, [
102\ "#define ABCDE\t\t1",
103\ "#define ABCDEF\t\t1",
104\ "#define ABCDEFG\t\t1",
105\ "#define ABCDEFGH\t1",
106\ "#define MSG_MODE_FILE\t\t\t1",
107\ "#define MSG_MODE_CONSOLE\t\t2",
108\ "#define MSG_MODE_FILE_AND_CONSOLE\t3",
109\ "#define MSG_MODE_FILE_THEN_CONSOLE\t4",
110\ ])
111  vert resize 40
112  syn match Conceal conceal cchar=>'AB\|MSG_MODE'
113  redraw!
114  let lines = s:screen_lines([1, 7], winwidth(0))
115  let expect = [
116\ "#define ABCDE>-->---1                   ",
117\ "#define >CDEF>-->---1                   ",
118\ "#define >CDEFG>->---1                   ",
119\ "#define >CDEFGH>----1                   ",
120\ "#define >_FILE>--------->--->---1       ",
121\ "#define >_CONSOLE>---------->---2       ",
122\ "#define >_FILE_AND_CONSOLE>---------3   ",
123\ ]
124  call s:compare_lines(expect, lines)
125  call s:close_windows()
126endfunc
127
128func Test_list_and_concealing2()
129  call s:test_windows('setl nowrap ts=2 list listchars=tab:>- cole=2 concealcursor=n')
130  call setline(1, "bbeeeeee\t\t;\tsome text")
131  vert resize 40
132  syn clear
133  syn match meaning    /;\s*\zs.*/
134  syn match hasword    /^\x\{8}/    contains=word
135  syn match word       /\<\x\{8}\>/ contains=beginword,endword contained
136  syn match beginword  /\<\x\x/     contained conceal
137  syn match endword    /\x\{6}\>/   contained
138  hi meaning   guibg=blue
139  hi beginword guibg=green
140  hi endword   guibg=red
141  redraw!
142  let lines = s:screen_lines([1, 1], winwidth(0))
143  let expect = [
144\ "eeeeee>--->-;>some text                 ",
145\ ]
146  call s:compare_lines(expect, lines)
147  call s:close_windows()
148endfunc
149
150func Test_screenattr_for_comment()
151  call s:test_windows("setl ft=c ts=7 list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6")
152  call setline(1, " /*\t\t and some more */")
153  norm! gg0
154  syntax on
155  hi SpecialKey term=underline ctermfg=red guifg=red
156  redraw!
157  let line = getline(1)
158  let attr = s:screen_attr(1, [1, 6])
159  call assert_notequal(attr[0], attr[1])
160  call assert_notequal(attr[1], attr[3])
161  call assert_notequal(attr[3], attr[5])
162  call s:close_windows()
163endfunc
164
165func Test_visual_block_and_selection_exclusive()
166  call s:test_windows('setl selection=exclusive')
167  call setline(1, "long line: " . repeat("foobar ", 40) . "TARGETÃ' at end")
168  exe "norm! $3B\<C-v>eAx\<Esc>"
169  let lines = s:screen_lines([1, 10], winwidth(0))
170  let expect = [
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 foobar      ",
180\ "+foobar TARGETÃx'   ",
181\ ]
182  call s:compare_lines(expect, lines)
183  call s:close_windows()
184endfunc
185
186func Test_multibyte_sign_and_colorcolumn()
187  call s:test_windows("setl nolinebreak cc=3 list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6")
188  call setline(1, ["", "a b c", "a b c"])
189  exe "sign define foo text=\uff0b"
190  exe "sign place 1 name=foo line=2 buffer=" . bufnr('%')
191  redraw!
192  norm! ggj0
193  let signwidth = strdisplaywidth("\uff0b")
194  let attr1 = s:screen_attr(2, [1, 3], signwidth)
195  let attr2 = s:screen_attr(3, [1, 3], signwidth)
196  call assert_equal(attr1[0], attr2[0])
197  call assert_equal(attr1[1], attr2[1])
198  call assert_equal(attr1[2], attr2[2])
199  let lines = s:screen_lines([1, 3], winwidth(0))
200  let expect = [
201\ "  ¶                 ",
202\ "+a b c¶            ",
203\ "  a b c¶            ",
204\ ]
205  call s:compare_lines(expect, lines)
206  call s:close_windows()
207endfunc
208
209func Test_colorcolumn_priority()
210  call s:test_windows('setl cc=4 cuc hls')
211  call setline(1, ["xxyy", ""])
212  norm! gg
213  exe "normal! /xxyy\<CR>"
214  norm! G
215  redraw!
216  let line_attr = s:screen_attr(1, [1, &cc])
217  " Search wins over CursorColumn
218  call assert_equal(line_attr[1], line_attr[0])
219  " Search wins over Colorcolumn
220  call assert_equal(line_attr[2], line_attr[3])
221  call s:close_windows('setl hls&vim')
222endfunc
223
224func Test_illegal_byte_and_breakat()
225  call s:test_windows("setl sbr= brk+=<")
226  vert resize 18
227  call setline(1, repeat("\x80", 6))
228  redraw!
229  let lines = s:screen_lines([1, 2], winwidth(0))
230  let expect = [
231\ "<80><80><80><80><8",
232\ "0><80>            ",
233\ ]
234  call s:compare_lines(expect, lines)
235  call s:close_windows('setl brk&vim')
236endfunc
237
238func Test_multibyte_wrap_and_breakat()
239  call s:test_windows("setl sbr= brk+=>")
240  call setline(1, repeat('a', 17) . repeat('あ', 2))
241  redraw!
242  let lines = s:screen_lines([1, 2], winwidth(0))
243  let expect = [
244\ "aaaaaaaaaaaaaaaaaあ>",
245\ "あ                  ",
246\ ]
247  call s:compare_lines(expect, lines)
248  call s:close_windows('setl brk&vim')
249endfunc
250
251func Test_chinese_char_on_wrap_column()
252  call s:test_windows("setl nolbr wrap sbr=")
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\ '<<<aaaaaaaaaaaaaaaa>',
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 assert_equal(len(expect), winline())
282  call assert_equal(strwidth(trim(expect[-1], ' ', 2)), wincol())
283  norm! g0
284  call assert_equal(len(expect), winline())
285  call assert_equal(1, wincol())
286  call s:close_windows()
287endfunc
288
289func Test_chinese_char_on_wrap_column_sbr()
290  call s:test_windows("setl nolbr wrap sbr=!!!")
291  call setline(1, [
292\ 'aaaaaaaaaaaaaaaaaaa中'.
293\ 'aaaaaaaaaaaaaa中'.
294\ 'aaaaaaaaaaaaaa中'.
295\ 'aaaaaaaaaaaaaa中'.
296\ 'aaaaaaaaaaaaaa中'.
297\ 'aaaaaaaaaaaaaa中'.
298\ 'aaaaaaaaaaaaaa中'.
299\ 'aaaaaaaaaaaaaa中'.
300\ 'aaaaaaaaaaaaaa中'.
301\ 'aaaaaaaaaaaaaa中'.
302\ 'hello'])
303  call cursor(1,1)
304  norm! $
305  redraw!
306  let expect=[
307\ '!!!中aaaaaaaaaaaaaa>',
308\ '!!!中aaaaaaaaaaaaaa>',
309\ '!!!中aaaaaaaaaaaaaa>',
310\ '!!!中aaaaaaaaaaaaaa>',
311\ '!!!中aaaaaaaaaaaaaa>',
312\ '!!!中aaaaaaaaaaaaaa>',
313\ '!!!中aaaaaaaaaaaaaa>',
314\ '!!!中aaaaaaaaaaaaaa>',
315\ '!!!中aaaaaaaaaaaaaa>',
316\ '!!!中hello          ']
317  let lines = s:screen_lines([1, 10], winwidth(0))
318  call s:compare_lines(expect, lines)
319  call assert_equal(len(expect), winline())
320  call assert_equal(strwidth(trim(expect[-1], ' ', 2)), wincol())
321  norm! g0
322  call assert_equal(len(expect), winline())
323  call assert_equal(4, wincol())
324  call s:close_windows()
325endfunc
326
327func Test_unprintable_char_on_wrap_column()
328  call s:test_windows("setl nolbr wrap sbr=")
329  call setline(1, 'aaa' .. repeat("\uFEFF", 50) .. 'bbb')
330  call cursor(1,1)
331  norm! $
332  redraw!
333  let expect=[
334\ '<<<<feff><feff><feff',
335\ '><feff><feff><feff><',
336\ 'feff><feff><feff><fe',
337\ 'ff><feff><feff><feff',
338\ '><feff><feff><feff><',
339\ 'feff><feff><feff><fe',
340\ 'ff><feff><feff><feff',
341\ '><feff><feff><feff><',
342\ 'feff><feff><feff><fe',
343\ 'ff>bbb              ']
344  let lines = s:screen_lines([1, 10], winwidth(0))
345  call s:compare_lines(expect, lines)
346  call assert_equal(len(expect), winline())
347  call assert_equal(strwidth(trim(expect[-1], ' ', 2)), wincol())
348  setl sbr=!!
349  redraw!
350  let expect=[
351\ '!!><feff><feff><feff',
352\ '!!><feff><feff><feff',
353\ '!!><feff><feff><feff',
354\ '!!><feff><feff><feff',
355\ '!!><feff><feff><feff',
356\ '!!><feff><feff><feff',
357\ '!!><feff><feff><feff',
358\ '!!><feff><feff><feff',
359\ '!!><feff><feff><feff',
360\ '!!><feff><feff>bbb  ']
361  let lines = s:screen_lines([1, 10], winwidth(0))
362  call s:compare_lines(expect, lines)
363  call assert_equal(len(expect), winline())
364  call assert_equal(strwidth(trim(expect[-1], ' ', 2)), wincol())
365  call s:close_windows()
366endfunc
367
368" Test that Visual selection is drawn correctly when 'linebreak' is set and
369" selection ends before multibyte 'showbreak'.
370func Test_visual_ends_before_showbreak()
371  CheckScreendump
372
373  let lines =<< trim END
374      vim9script
375      &wrap = true
376      &linebreak = true
377      &showbreak = '↪ '
378      ['xxxxx ' .. 'y'->repeat(&columns - 6) .. ' zzzz']->setline(1)
379      normal! wvel
380  END
381  call writefile(lines, 'XvisualEndsBeforeShowbreak', 'D')
382  let buf = RunVimInTerminal('-S XvisualEndsBeforeShowbreak', #{rows: 6})
383  call VerifyScreenDump(buf, 'Test_visual_ends_before_showbreak', {})
384
385  call StopVimInTerminal(buf)
386endfunc
387
388func Test_visual_block_hl_with_linebreak()
389  CheckScreendump
390
391  let lines =<< trim END
392    func Case1()
393      20vnew
394      setlocal linebreak
395      call setline(1, ['foo ' .. repeat('x', 10), 'foo ' .. repeat('x', 20)])
396      exe "normal! gg0\<C-V>3lj"
397    endfunc
398
399    func Case2()
400      setlocal nolinebreak
401      call setline(1, ["foo\tbar", 'foo12345bar', "foo\tbar"])
402      exe "normal! gg03l\<C-V>2j2h"
403    endfunc
404
405    func Case3()
406      setlocal nolinebreak
407      call setline(1, ["foo\uffffbar", 'foo123456bar', "foo\uffffbar"])
408      exe "normal! gg03l\<C-V>2j2h"
409    endfunc
410
411    func Case4()
412      setlocal nolinebreak
413      call setline(1, [repeat('x', 15), repeat('x', 10), repeat('x', 10)])
414      call prop_type_add('test', {})
415      call prop_add(2, 5, #{text: "foo: ", type: "test"})
416      call prop_add(3, 5, #{text: "bar: ", type: "test"})
417      exe "normal! gg02l\<C-V>2j2l"
418    endfunc
419
420    set laststatus=0 showcmd ruler
421    " FIXME: clipboard=autoselect sometimes changes Visual highlight
422    set clipboard=
423  END
424  call writefile(lines, 'XvisualBlockHlWithLinebreak', 'D')
425  let buf = RunVimInTerminal('-S XvisualBlockHlWithLinebreak', #{rows: 6})
426
427  " 'linebreak' after end char (initially fixed by patch 7.4.467)
428  call term_sendkeys(buf, ":call Case1()\r")
429  call VerifyScreenDump(buf, 'Test_visual_block_hl_with_linebreak_1', {})
430
431  " TAB as end char: 'linebreak' shouldn't break Visual block hl
432  call term_sendkeys(buf, "\<Esc>:bwipe! | call Case2()\r")
433  call VerifyScreenDump(buf, 'Test_visual_block_hl_with_linebreak_2', {})
434  call term_sendkeys(buf, "\<Esc>:setlocal linebreak\rgv")
435  call term_wait(buf, 50)
436  call VerifyScreenDump(buf, 'Test_visual_block_hl_with_linebreak_2', {})
437
438  " Unprintable end char: 'linebreak' shouldn't break Visual block hl
439  call term_sendkeys(buf, "\<Esc>:bwipe! | call Case3()\r")
440  call VerifyScreenDump(buf, 'Test_visual_block_hl_with_linebreak_3', {})
441  call term_sendkeys(buf, "\<Esc>:setlocal linebreak\rgv")
442  call term_wait(buf, 50)
443  call VerifyScreenDump(buf, 'Test_visual_block_hl_with_linebreak_3', {})
444
445  " Virtual text before end char: 'linebreak' shouldn't break Visual block hl
446  call term_sendkeys(buf, "\<Esc>:bwipe! | call Case4()\r")
447  call VerifyScreenDump(buf, 'Test_visual_block_hl_with_linebreak_4', {})
448  call term_sendkeys(buf, "\<Esc>:setlocal linebreak\rgv")
449  call term_wait(buf, 50)
450  call VerifyScreenDump(buf, 'Test_visual_block_hl_with_linebreak_4', {})
451
452  call term_sendkeys(buf, "\<Esc>")
453  call StopVimInTerminal(buf)
454endfunc
455
456" vim: shiftwidth=2 sts=2 expandtab