robin/laufey

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

zeertzjqMerge pull request #38559 from zeertzjq/vim-9.2.02707d97de27cf

master
26.1 KiB862 linesraw
1" Tests for 'listchars' display with 'list' and :list
2
3source check.vim
4source view_util.vim
5source screendump.vim
6
7func Check_listchars(expected, end_lnum, end_scol = -1, leftcol = 0)
8  if a:leftcol > 0
9    let save_wrap = &wrap
10    set nowrap
11    call cursor(1, 1)
12    exe 'normal! ' .. a:leftcol .. 'zl'
13  endif
14
15  redraw!
16  for i in range(1, a:end_lnum)
17    if a:leftcol > 0
18      let col = virtcol2col(0, i, a:leftcol)
19      let col += getline(i)->strpart(col - 1, 1, v:true)->len()
20      call cursor(i, col)
21      redraw
22      call assert_equal(a:leftcol, winsaveview().leftcol)
23    else
24      call cursor(i, 1)
25    end
26
27    let end_scol = a:end_scol < 0 ? '$'->virtcol() - a:leftcol : a:end_scol
28    call assert_equal([a:expected[i - 1]->strcharpart(a:leftcol)],
29          \ ScreenLines(i, end_scol))
30  endfor
31
32  if a:leftcol > 0
33    let &wrap = save_wrap
34  endif
35endfunc
36
37func Test_listchars()
38  enew!
39  set ff=unix
40  set list
41
42  set listchars+=tab:>-,space:.,trail:<
43  call append(0, [
44	      \ '	aa	',
45	      \ '  bb	  ',
46	      \ '   cccc	 ',
47	      \ 'dd        ee  	',
48	      \ ' '
49	      \ ])
50  let expected = [
51	      \ '>-------aa>-----$',
52	      \ '..bb>---<<$',
53	      \ '...cccc><$',
54	      \ 'dd........ee<<>-$',
55	      \ '<$'
56	      \ ]
57  call Check_listchars(expected, 5)
58  call Check_listchars(expected, 4, -1, 5)
59
60  set listchars-=trail:<
61  let expected = [
62	      \ '>-------aa>-----$',
63	      \ '..bb>---..$',
64	      \ '...cccc>.$',
65	      \ 'dd........ee..>-$',
66	      \ '.$'
67	      \ ]
68  call Check_listchars(expected, 5)
69  call Check_listchars(expected, 4, -1, 5)
70
71  " tab with 3rd character.
72  set listchars-=tab:>-
73  set listchars+=tab:<=>,trail:-
74  let expected = [
75	      \ '<======>aa<====>$',
76	      \ '..bb<==>--$',
77	      \ '...cccc>-$',
78	      \ 'dd........ee--<>$',
79	      \ '-$'
80	      \ ]
81  call Check_listchars(expected, 5)
82  call Check_listchars(expected, 4, -1, 5)
83
84  " tab with 3rd character and linebreak set
85  set listchars-=tab:<=>
86  set listchars+=tab:<·>
87  set linebreak
88  let expected = [
89	      \ '<······>aa<····>$',
90	      \ '..bb<··>--$',
91	      \ '...cccc>-$',
92	      \ 'dd........ee--<>$',
93	      \ '-$'
94	      \ ]
95  call Check_listchars(expected, 5)
96  set nolinebreak
97  set listchars-=tab:<·>
98  set listchars+=tab:<=>
99
100  set listchars-=trail:-
101  let expected = [
102	      \ '<======>aa<====>$',
103	      \ '..bb<==>..$',
104	      \ '...cccc>.$',
105	      \ 'dd........ee..<>$',
106	      \ '.$'
107	      \ ]
108  call Check_listchars(expected, 5)
109  call Check_listchars(expected, 4, -1, 5)
110
111  set listchars-=tab:<=>
112  set listchars+=tab:>-
113  set listchars+=trail:<
114  set nolist
115  normal ggdG
116  call append(0, [
117	      \ '  fff	  ',
118	      \ '	gg	',
119	      \ '     h	',
120	      \ 'iii    	  ',
121	      \ ])
122  let l = split(execute("%list"), "\n")
123  call assert_equal([
124	      \ '..fff>--<<$',
125	      \ '>-------gg>-----$',
126	      \ '.....h>-$',
127	      \ 'iii<<<<><<$',
128	      \ '$'], l)
129
130  " Test lead and trail
131  normal ggdG
132  set listchars=eol:$  " Accommodate Nvim default
133  set listchars+=lead:>,trail:<,space:x
134  set list
135
136  call append(0, [
137	      \ '    ffff    ',
138	      \ '          gg',
139	      \ 'h           ',
140	      \ '            ',
141	      \ '    0  0    ',
142	      \ ])
143
144  let expected = [
145	      \ '>>>>ffff<<<<$',
146	      \ '>>>>>>>>>>gg$',
147	      \ 'h<<<<<<<<<<<$',
148	      \ '<<<<<<<<<<<<$',
149	      \ '>>>>0xx0<<<<$',
150	      \ '$'
151	      \ ]
152  call Check_listchars(expected, 6)
153  call Check_listchars(expected, 5, -1, 6)
154  call assert_equal(expected, split(execute("%list"), "\n"))
155
156  " In a line with only spaces, they aren't considered leading even if "trail"
157  " isn't set.
158  set listchars-=trail:<
159  let expected = [
160	      \ '>>>>ffffxxxx$',
161	      \ '>>>>>>>>>>gg$',
162	      \ 'hxxxxxxxxxxx$',
163	      \ 'xxxxxxxxxxxx$',
164	      \ '>>>>0xx0xxxx$',
165	      \ '$'
166	      \ ]
167  call Check_listchars(expected, 6)
168  call Check_listchars(expected, 5, -1, 6)
169  call assert_equal(expected, split(execute("%list"), "\n"))
170
171  " Test multispace
172  normal ggdG
173  set listchars=eol:$  " Accommodate Nvim default
174  set listchars+=multispace:yYzZ
175  set list
176
177  call append(0, [
178	      \ '    ffff    ',
179	      \ '  i i     gg',
180	      \ ' h          ',
181	      \ '            ',
182	      \ '          j ',
183	      \ '    0  0    ',
184	      \ ])
185
186  let expected = [
187	      \ 'yYzZffffyYzZ$',
188	      \ 'yYi iyYzZygg$',
189	      \ ' hyYzZyYzZyY$',
190	      \ 'yYzZyYzZyYzZ$',
191	      \ 'yYzZyYzZyYj $',
192	      \ 'yYzZ0yY0yYzZ$',
193	      \ '$'
194	      \ ]
195  call Check_listchars(expected, 7)
196  call Check_listchars(expected, 6, -1, 6)
197  call assert_equal(expected, split(execute("%list"), "\n"))
198
199  " Test leadmultispace + multispace
200  normal ggdG
201  set listchars=eol:$,multispace:yYzZ,nbsp:S
202  set listchars+=leadmultispace:.-+*
203  set list
204
205  call append(0, [
206	      \ '    ffff    ',
207	      \ '  i i     gg',
208	      \ ' h          ',
209	      \ '            ',
210	      \ '          j ',
211	      \ '    0  0    ',
212	      \ ])
213
214  let expected = [
215	      \ '.-+*ffffyYzZ$',
216	      \ '.-i iSyYzZgg$',
217	      \ ' hyYzZyYzZyY$',
218	      \ 'yYzZyYzZyYzZ$',
219	      \ '.-+*.-+*.-j $',
220	      \ '.-+*0yY0yYzZ$',
221	      \ '$'
222	      \ ]
223  call assert_equal('eol:$,multispace:yYzZ,nbsp:S,leadmultispace:.-+*', &listchars)
224  call Check_listchars(expected, 7)
225  call Check_listchars(expected, 6, -1, 1)
226  call Check_listchars(expected, 6, -1, 2)
227  call Check_listchars(expected, 6, -1, 3)
228  call Check_listchars(expected, 6, -1, 6)
229  call assert_equal(expected, split(execute("%list"), "\n"))
230
231  " Test leadmultispace without multispace
232  normal ggdG
233  set listchars-=multispace:yYzZ
234  set listchars+=space:+,trail:>,eol:$
235  set list
236
237  call append(0, [
238	      \ '    ffff    ',
239	      \ '  i i     gg',
240	      \ ' h          ',
241	      \ '            ',
242	      \ '          j ',
243	      \ '    0  0    ',
244	      \ ])
245
246  let expected = [
247	      \ '.-+*ffff>>>>$',
248	      \ '.-i+i+++++gg$',
249	      \ '+h>>>>>>>>>>$',
250	      \ '>>>>>>>>>>>>$',
251	      \ '.-+*.-+*.-j>$',
252	      \ '.-+*0++0>>>>$',
253	      \ '$'
254	      \ ]
255  call assert_equal('eol:$,nbsp:S,leadmultispace:.-+*,space:+,trail:>', &listchars)
256  call Check_listchars(expected, 7)
257  call Check_listchars(expected, 6, -1, 1)
258  call Check_listchars(expected, 6, -1, 2)
259  call Check_listchars(expected, 6, -1, 3)
260  call Check_listchars(expected, 6, -1, 6)
261  call assert_equal(expected, split(execute("%list"), "\n"))
262
263  " Test leadmultispace only
264  normal ggdG
265  set listchars=eol:$  " Accommodate Nvim default
266  set listchars=leadmultispace:.-+*
267  set list
268
269  call append(0, [
270	      \ '    ffff    ',
271	      \ '  i i     gg',
272	      \ ' h          ',
273	      \ '            ',
274	      \ '          j ',
275	      \ '    0  0    ',
276	      \ ])
277
278  let expected = [
279	      \ '.-+*ffff    ',
280	      \ '.-i i     gg',
281	      \ ' h          ',
282	      \ '            ',
283	      \ '.-+*.-+*.-j ',
284	      \ '.-+*0  0    ',
285	      \ ' '
286	      \ ]
287  call assert_equal('leadmultispace:.-+*', &listchars)
288  call Check_listchars(expected, 6, 12)
289  call assert_equal(expected, split(execute("%list"), "\n"))
290
291  " Changing the value of 'ambiwidth' twice shouldn't cause double-free when
292  " "leadmultispace" is specified.
293  set ambiwidth=double
294  set ambiwidth&
295
296  " Test leadmultispace and lead and space
297  normal ggdG
298  set listchars=eol:$  " Accommodate Nvim default
299  set listchars+=lead:<,space:-
300  set listchars+=leadmultispace:.-+*
301  set list
302
303  call append(0, [
304	      \ '    ffff    ',
305	      \ '  i i     gg',
306	      \ ' h          ',
307	      \ '            ',
308	      \ '          j ',
309	      \ '    0  0    ',
310	      \ ])
311
312  let expected = [
313	      \ '.-+*ffff----$',
314	      \ '.-i-i-----gg$',
315	      \ '<h----------$',
316	      \ '------------$',
317	      \ '.-+*.-+*.-j-$',
318	      \ '.-+*0--0----$',
319	      \ '$'
320	      \ ]
321  call assert_equal('eol:$,lead:<,space:-,leadmultispace:.-+*', &listchars)
322  call Check_listchars(expected, 7)
323  call Check_listchars(expected, 6, -1, 1)
324  call Check_listchars(expected, 6, -1, 2)
325  call Check_listchars(expected, 6, -1, 3)
326  call Check_listchars(expected, 6, -1, 6)
327  call assert_equal(expected, split(execute("%list"), "\n"))
328
329  " the last occurrence of 'multispace:' is used
330  set listchars=eol:$  " Accommodate Nvim default
331  set listchars+=multispace:yYzZ
332  set listchars+=space:x,multispace:XyY
333
334  let expected = [
335	      \ 'XyYXffffXyYX$',
336	      \ 'XyixiXyYXygg$',
337	      \ 'xhXyYXyYXyYX$',
338	      \ 'XyYXyYXyYXyY$',
339	      \ 'XyYXyYXyYXjx$',
340	      \ 'XyYX0Xy0XyYX$',
341	      \ '$'
342	      \ ]
343  call assert_equal('eol:$,space:x,multispace:XyY', &listchars)
344  call Check_listchars(expected, 7)
345  call Check_listchars(expected, 6, -1, 6)
346  call assert_equal(expected, split(execute("%list"), "\n"))
347
348  " when using :let, multiple 'multispace:' fields can exist
349  " and the last occurrence of 'multispace:' is used
350  let &listchars = 'eol:$,multispace:yYzZ,space:x,multispace:XyY'
351  call assert_equal('eol:$,multispace:yYzZ,space:x,multispace:XyY', &listchars)
352  call Check_listchars(expected, 7)
353  call Check_listchars(expected, 6, -1, 6)
354  call assert_equal(expected, split(execute("%list"), "\n"))
355
356  " restore to single multispace: for subsequent tests
357  set listchars=eol:$,space:x,multispace:XyY
358  set listchars+=lead:>,trail:<
359
360  let expected = [
361	      \ '>>>>ffff<<<<$',
362	      \ '>>ixiXyYXygg$',
363	      \ '>h<<<<<<<<<<$',
364	      \ '<<<<<<<<<<<<$',
365	      \ '>>>>>>>>>>j<$',
366	      \ '>>>>0Xy0<<<<$',
367	      \ '$'
368	      \ ]
369  call Check_listchars(expected, 7)
370  call Check_listchars(expected, 6, -1, 6)
371  call assert_equal(expected, split(execute("%list"), "\n"))
372
373  " removing 'multispace:'
374  set listchars-=multispace:
375
376  let expected = [
377	      \ '>>>>ffff<<<<$',
378	      \ '>>ixixxxxxgg$',
379	      \ '>h<<<<<<<<<<$',
380	      \ '<<<<<<<<<<<<$',
381	      \ '>>>>>>>>>>j<$',
382	      \ '>>>>0xx0<<<<$',
383	      \ '$'
384	      \ ]
385  call Check_listchars(expected, 7)
386  call Check_listchars(expected, 6, -1, 6)
387  call assert_equal(expected, split(execute("%list"), "\n"))
388
389  " Test leadtab basic functionality
390  normal ggdG
391  set listchars=tab:>-,leadtab:+*
392  set list
393  call append(0, [
394        \ "\ttext",
395        \ "\t\ttext",
396        \ "text\ttab"
397        \ ])
398  let expected = [
399        \ '+*******text        ',
400        \ '+*******+*******text',
401        \ 'text>---tab         '
402        \ ]
403  call Check_listchars(expected, 3, 20)
404  call assert_equal(expected->mapnew({_, s -> trim(s, ' ', 2)}) + [' '],
405                  \ split(execute("%list"), "\n"))
406
407  " Test leadtab with unicode characters
408  normal ggdG
409  set listchars=tab:>-,leadtab:├─┤
410  call append(0, ["\ttext"])
411  let expected = ['├──────┤text']
412  call Check_listchars(expected, 1, 12)
413  call assert_equal(expected + [' '], split(execute("%list"), "\n"))
414
415  " Test leadtab with mixed indentation (spaces + tabs)
416  normal ggdG
417  set listchars=tab:>-,leadtab:+*,space:.
418  call append(0, [" \t text"])
419  let expected = ['.+******.text']
420  call Check_listchars(expected, 1, 13)
421  call assert_equal(expected + [' '], split(execute("%list"), "\n"))
422
423  " Test leadtab with pipe character
424  normal ggdG
425  let &listchars = 'tab:>-,leadtab:| '
426  call append(0, ["\ttext"])
427  let expected = ['|       text']
428  call Check_listchars(expected, 1, 12)
429  call assert_equal(expected + [' '], split(execute("%list"), "\n"))
430
431  " Test leadtab with unicode bar
432  normal ggdG
433  let &listchars = 'tab:>-,leadtab:│ '
434  call append(0, ["\ttext"])
435  let expected = ['│       text']
436  call Check_listchars(expected, 1, 12)
437  call assert_equal(expected + [' '], split(execute("%list"), "\n"))
438
439  " Test leadtab vs tab distinction (leading vs non-leading)
440  " In a line with only tabs, they aren't considered leading.
441  normal ggdG
442  set listchars=tab:>-,leadtab:+*
443  call append(0, [
444        \ "\tleading",
445        \ "text\tnot leading",
446        \ "\t\tmultiple leading",
447        \ "\t\t"
448        \ ])
449  let expected = [
450        \ '+*******leading                 ',
451        \ 'text>---not leading             ',
452        \ '+*******+*******multiple leading',
453        \ '>------->-------                '
454        \ ]
455  call Check_listchars(expected, 4, 32)
456  call assert_equal(expected->mapnew({_, s -> trim(s, ' ', 2)}) + [' '],
457                  \ split(execute("%list"), "\n"))
458
459  " Test leadtab with trail and space
460  normal ggdG
461  set listchars=tab:>-,leadtab:+*,trail:<,space:.
462  call append(0, [
463        \ "\ttext  ",
464        \ "  \ttext",
465        \ "\t  text  "
466        \ ])
467  let expected = [
468        \ '+*******text<<  ',
469        \ '..+*****text    ',
470        \ '+*******..text<<'
471        \ ]
472  call Check_listchars(expected, 3, 16)
473  call assert_equal(expected->mapnew({_, s -> trim(s, ' ', 2)}) + [' '],
474                  \ split(execute("%list"), "\n"))
475
476  " Test leadtab with eol
477  normal ggdG
478  set listchars=tab:>-,leadtab:+*,eol:$
479  call append(0, ["\ttext", "text\ttab"])
480  let expected = [
481        \ '+*******text$',
482        \ 'text>---tab$ '
483        \ ]
484  call Check_listchars(expected, 2, 13)
485  call assert_equal(expected->mapnew({_, s -> trim(s, ' ', 2)}) + ['$'],
486                  \ split(execute("%list"), "\n"))
487
488  " test nbsp
489  normal ggdG
490  set listchars=nbsp:X,trail:Y
491  set list
492  " Non-breaking space
493  let nbsp = nr2char(0xa0)
494  call append(0, [ ">" .. nbsp .. "<" ])
495
496  let expected = '>X< '
497  call Check_listchars([expected], 1)
498
499  set listchars=nbsp:X
500  call Check_listchars([expected], 1)
501
502  " test extends
503  normal ggdG
504  set listchars=extends:Z
505  set nowrap
506  set nolist
507  call append(0, [ repeat('A', &columns + 1) ])
508
509  let expected = repeat('A', &columns)
510  call Check_listchars([expected], 1, &columns)
511
512  set list
513  let expected = expected[:-2] . 'Z'
514  call Check_listchars([expected], 1, &columns)
515
516  enew!
517  set listchars& ff&
518endfunc
519
520" Test that unicode listchars characters get properly inserted
521func Test_listchars_unicode()
522  enew!
523  let oldencoding=&encoding
524  set encoding=utf-8
525  set ff=unix
526
527  set listchars=eol:⇔,space:␣,multispace:≡≢≣,nbsp:≠,tab:←↔→
528  set list
529
530  let nbsp = nr2char(0xa0)
531  call append(0, ["        a\tb c" .. nbsp .. "d  "])
532  let expected = ['≡≢≣≡≢≣≡≢a←↔↔↔↔↔→b␣c≠d≡≢⇔']
533  call Check_listchars(expected, 1)
534  call Check_listchars(expected, 1, -1, 3)
535  call Check_listchars(expected, 1, -1, 13)
536
537  set listchars=eol:\\u21d4,space:\\u2423,multispace:≡\\u2262\\U00002263,nbsp:\\U00002260,tab:←↔\\u2192
538  call Check_listchars(expected, 1)
539  call Check_listchars(expected, 1, -1, 3)
540  call Check_listchars(expected, 1, -1, 13)
541
542  set listchars+=lead:⇨,trail:⇦
543  let expected = ['⇨⇨⇨⇨⇨⇨⇨⇨a←↔↔↔↔↔→b␣c≠d⇦⇦⇔']
544  call Check_listchars(expected, 1)
545  call Check_listchars(expected, 1, -1, 3)
546  call Check_listchars(expected, 1, -1, 13)
547
548  let &encoding=oldencoding
549  enew!
550  set listchars& ff&
551endfunction
552
553func Test_listchars_invalid()
554  enew!
555  set ff=unix
556
557  set listchars=eol:$  " Accommodate Nvim default
558  set list
559  set ambiwidth=double
560
561  " No colon
562  call assert_fails('set listchars=x', 'E474:')
563  call assert_fails('set listchars=x', 'E474:')
564  call assert_fails('set listchars=multispace', 'E474:')
565  call assert_fails('set listchars=leadmultispace', 'E474:')
566
567  " Too short
568  call assert_fails('set listchars=space:', 'E1511:')
569  call assert_fails('set listchars=tab:x', 'E1511:')
570  call assert_fails('set listchars=multispace:', 'E1511:')
571  call assert_fails('set listchars=leadmultispace:', 'E1511:')
572
573  " One occurrence too short
574  call assert_fails('set listchars=space:x,space:', 'E1511:')
575  call assert_fails('set listchars=space:,space:x', 'E1511:')
576  call assert_fails('set listchars=tab:xx,tab:x', 'E1511:')
577  call assert_fails('set listchars=tab:x,tab:xx', 'E1511:')
578  call assert_fails('set listchars=multispace:,multispace:x', 'E1511:')
579  call assert_fails('set listchars=multispace:x,multispace:', 'E1511:')
580  call assert_fails('set listchars=leadmultispace:,leadmultispace:x', 'E1511:')
581  call assert_fails('set listchars=leadmultispace:x,leadmultispace:', 'E1511:')
582
583  " Too long
584  call assert_fails('set listchars=space:xx', 'E1511:')
585  call assert_fails('set listchars=tab:xxxx', 'E1511:')
586
587  " Has double-width character
588  call assert_fails('set listchars=space:·', 'E1512:')
589  call assert_fails('set listchars=tab:·x', 'E1512:')
590  call assert_fails('set listchars=tab:x·', 'E1512:')
591  call assert_fails('set listchars=tab:xx·', 'E1512:')
592  call assert_fails('set listchars=multispace:·', 'E1512:')
593  call assert_fails('set listchars=multispace:xxx·', 'E1512:')
594  call assert_fails('set listchars=leadmultispace:·', 'E1512:')
595  call assert_fails('set listchars=leadmultispace:xxx·', 'E1512:')
596
597  " Has control character
598  call assert_fails("set listchars=space:\x01", 'E1512:')
599  call assert_fails("set listchars=tab:\x01x", 'E1512:')
600  call assert_fails("set listchars=tab:x\x01", 'E1512:')
601  call assert_fails("set listchars=tab:xx\x01", 'E1512:')
602  call assert_fails("set listchars=multispace:\x01", 'E1512:')
603  call assert_fails("set listchars=multispace:xxx\x01", 'E1512:')
604  call assert_fails('set listchars=space:\\x01', 'E1512:')
605  call assert_fails('set listchars=tab:\\x01x', 'E1512:')
606  call assert_fails('set listchars=tab:x\\x01', 'E1512:')
607  call assert_fails('set listchars=tab:xx\\x01', 'E1512:')
608  call assert_fails('set listchars=multispace:\\x01', 'E1512:')
609  call assert_fails('set listchars=multispace:xxx\\x01', 'E1512:')
610  call assert_fails("set listchars=leadmultispace:\x01", 'E1512:')
611  call assert_fails('set listchars=leadmultispace:\\x01', 'E1512:')
612  call assert_fails("set listchars=leadmultispace:xxx\x01", 'E1512:')
613  call assert_fails('set listchars=leadmultispace:xxx\\x01', 'E1512:')
614
615  enew!
616  set ambiwidth& listchars& ff&
617endfunction
618
619" Tests that space characters following composing character won't get replaced
620" by listchars.
621func Test_listchars_composing()
622  enew!
623  let oldencoding=&encoding
624  set encoding=utf-8
625  set ff=unix
626  set list
627
628  set listchars=eol:$,space:_,nbsp:=
629
630  let nbsp1 = nr2char(0xa0)
631  let nbsp2 = nr2char(0x202f)
632  call append(0, [
633        \ "  \u3099\t \u309A" .. nbsp1 .. nbsp1 .. "\u0302" .. nbsp2 .. nbsp2 .. "\u0302",
634        \ ])
635  let expected = [
636        \ "_ \u3099^I \u309A=" .. nbsp1 .. "\u0302=" .. nbsp2 .. "\u0302$"
637        \ ]
638  call Check_listchars(expected, 1)
639  let &encoding=oldencoding
640  enew!
641  set listchars& ff&
642endfunction
643
644" Check for the value of the 'listchars' option
645func s:CheckListCharsValue(expected)
646  call assert_equal(a:expected, &listchars)
647  call assert_equal(a:expected, getwinvar(0, '&listchars'))
648endfunc
649
650" Test for using a window local value for 'listchars'
651func Test_listchars_window_local()
652  %bw!
653  set list listchars&
654  let nvim_default = &listchars  " Accommodate Nvim default
655  new
656  " set a local value for 'listchars'
657  setlocal listchars=tab:+-,eol:#
658  call s:CheckListCharsValue('tab:+-,eol:#')
659  " When local value is reset, global value should be used
660  setlocal listchars=
661  call s:CheckListCharsValue(nvim_default)
662  " Use 'setlocal <' to copy global value
663  setlocal listchars=space:.,extends:>
664  setlocal listchars<
665  call s:CheckListCharsValue(nvim_default)
666  " Use 'set <' to copy global value
667  setlocal listchars=space:.,extends:>
668  set listchars<
669  call s:CheckListCharsValue(nvim_default)
670  " Changing global setting should not change the local setting
671  setlocal listchars=space:.,extends:>
672  setglobal listchars=tab:+-,eol:#
673  call s:CheckListCharsValue('space:.,extends:>')
674  " when split opening a new window, local value should be copied
675  split
676  call s:CheckListCharsValue('space:.,extends:>')
677  " clearing local value in one window should not change the other window
678  set listchars&
679  call s:CheckListCharsValue(nvim_default)
680  close
681  call s:CheckListCharsValue('space:.,extends:>')
682
683  " use different values for 'listchars' items in two different windows
684  call setline(1, ["\t  one  two  "])
685  setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:#
686  split
687  setlocal listchars=tab:[.],lead:#,space:_,trail:.,eol:&
688  split
689  set listchars=tab:+-+,lead:^,space:>,trail:<,eol:%
690  call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$')))
691  close
692  call assert_equal(['[......]##one__two..&'], ScreenLines(1, virtcol('$')))
693  close
694  call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$')))
695  " changing the global setting should not change the local value
696  setglobal listchars=tab:[.],lead:#,space:_,trail:.,eol:&
697  call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$')))
698  set listchars<
699  call assert_equal(['[......]##one__two..&'], ScreenLines(1, virtcol('$')))
700
701  " Using setglobal in a window with local setting should not affect the
702  " window. But should impact other windows using the global setting.
703  enew! | only
704  call setline(1, ["\t  one  two  "])
705  set listchars=tab:[.],lead:#,space:_,trail:.,eol:&
706  split
707  setlocal listchars=tab:+-+,lead:^,space:>,trail:<,eol:%
708  split
709  setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:#
710  setglobal listchars=tab:{.},lead:-,space:=,trail:#,eol:$
711  call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$')))
712  close
713  call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$')))
714  close
715  call assert_equal(['{......}--one==two##$'], ScreenLines(1, virtcol('$')))
716
717  " Setting the global setting to the default value should not impact a window
718  " using a local setting.
719  split
720  setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:#
721  setglobal listchars=eol:$  " Accommodate Nvim default
722  call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$')))
723  close
724  call assert_equal(['^I  one  two  $'], ScreenLines(1, virtcol('$')))
725
726  " Setting the local setting to the default value should not impact a window
727  " using a global setting.
728  set listchars=tab:{.},lead:-,space:=,trail:#,eol:$
729  split
730  setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:#
731  call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$')))
732  setlocal listchars=eol:$  " Accommodate Nvim default
733  call assert_equal(['^I  one  two  $'], ScreenLines(1, virtcol('$')))
734  close
735  call assert_equal(['{......}--one==two##$'], ScreenLines(1, virtcol('$')))
736
737  " Using set in a window with a local setting should change it to use the
738  " global setting and also impact other windows using the global setting.
739  split
740  setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:#
741  call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$')))
742  set listchars=tab:+-+,lead:^,space:>,trail:<,eol:%
743  call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$')))
744  close
745  call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$')))
746
747  " Setting invalid value for a local setting should not impact the local and
748  " global settings.
749  split
750  setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:#
751  let cmd = 'setlocal listchars=tab:{.},lead:-,space:=,trail:#,eol:$,x'
752  call assert_fails(cmd, 'E474:')
753  call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$')))
754  close
755  call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$')))
756
757  " Setting invalid value for a global setting should not impact the local and
758  " global settings.
759  split
760  setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:#
761  let cmd = 'setglobal listchars=tab:{.},lead:-,space:=,trail:#,eol:$,x'
762  call assert_fails(cmd, 'E474:')
763  call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$')))
764  close
765  call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$')))
766
767  " Closing window with local lcs-multispace should not cause a memory leak.
768  setlocal listchars=multispace:---+
769  split
770  call s:CheckListCharsValue('multispace:---+')
771  close
772
773  %bw!
774  set list& listchars&
775endfunc
776
777func Test_listchars_foldcolumn()
778  CheckScreendump
779
780  let lines =<< trim END
781      call setline(1, ['aaa', '', 'a', 'aaaaaa'])
782      vsplit
783      vsplit
784      windo set signcolumn=yes foldcolumn=1 winminwidth=0 nowrap list listchars=extends:>,precedes:<
785  END
786  call writefile(lines, 'XTest_listchars', 'D')
787
788  let buf = RunVimInTerminal('-S XTest_listchars', {'rows': 10, 'cols': 60})
789
790  call term_sendkeys(buf, "13\<C-W>>")
791  call VerifyScreenDump(buf, 'Test_listchars_01', {})
792  call term_sendkeys(buf, "\<C-W>>")
793  call VerifyScreenDump(buf, 'Test_listchars_02', {})
794  call term_sendkeys(buf, "\<C-W>>")
795  call VerifyScreenDump(buf, 'Test_listchars_03', {})
796  call term_sendkeys(buf, "\<C-W>>")
797  call VerifyScreenDump(buf, 'Test_listchars_04', {})
798  call term_sendkeys(buf, "\<C-W>>")
799  call VerifyScreenDump(buf, 'Test_listchars_05', {})
800  call term_sendkeys(buf, "\<C-W>h")
801  call term_sendkeys(buf, ":set nowrap foldcolumn=4\<CR>")
802  call term_sendkeys(buf, "15\<C-W><")
803  call VerifyScreenDump(buf, 'Test_listchars_06', {})
804  call term_sendkeys(buf, "4\<C-W><")
805  call VerifyScreenDump(buf, 'Test_listchars_07', {})
806
807  " clean up
808  call StopVimInTerminal(buf)
809endfunc
810
811func Test_listchars_precedes_with_wide_char()
812  new
813  setlocal nowrap list listchars=eol:$,precedes:!
814  call setline(1, '123口456')
815  call assert_equal(['123口456$ '], ScreenLines(1, 10))
816  let attr = screenattr(1, 9)
817
818  normal! zl
819  call assert_equal(['!3口456$  '], ScreenLines(1, 10))
820  call assert_equal(attr, screenattr(1, 1))
821  normal! zl
822  call assert_equal(['!口456$   '], ScreenLines(1, 10))
823  call assert_equal(attr, screenattr(1, 1))
824  normal! zl
825  call assert_equal(['!<456$    '], ScreenLines(1, 10))
826  call assert_equal(attr, screenattr(1, 1))
827  call assert_equal(attr, screenattr(1, 2))
828  normal! zl
829  call assert_equal(['!456$     '], ScreenLines(1, 10))
830  call assert_equal(attr, screenattr(1, 1))
831  normal! zl
832  call assert_equal(['!56$      '], ScreenLines(1, 10))
833  call assert_equal(attr, screenattr(1, 1))
834  normal! zl
835  call assert_equal(['!6$       '], ScreenLines(1, 10))
836  call assert_equal(attr, screenattr(1, 1))
837
838  bw!
839endfunc
840
841func Test_listchars_precedes_with_tab()
842  new
843  setlocal nowrap list listchars=eol:$,precedes:!,tab:<->
844  call setline(1, "1234\t56")
845  let expected_line = '1234<-->56$ '
846  call assert_equal([expected_line], ScreenLines(1, 12))
847  let expected_attrs = mapnew(range(1, 12), 'screenattr(1, v:val)')
848  let attr = expected_attrs[-2]
849
850  for i in range(8)
851    normal! zl
852    let expected_line = '!' .. expected_line[2:] .. ' '
853    let expected_attrs = [attr] + expected_attrs[2:] + expected_attrs[-1:]
854    call assert_equal([expected_line], ScreenLines(1, 12))
855    let attrs = mapnew(range(1, 12), 'screenattr(1, v:val)')
856    call assert_equal(expected_attrs, attrs)
857  endfor
858
859  bw!
860endfunc
861
862" vim: shiftwidth=2 sts=2 expandtab