blob: b9b078c0a160436e6268c978f278b2864931bd40 [file] [log] [blame]
Bram Moolenaar209d3872017-11-16 21:52:51 +01001" Tests for 'listchars' display with 'list' and :list
2
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003source check.vim
Bram Moolenaar209d3872017-11-16 21:52:51 +01004source view_util.vim
Bram Moolenaar41fb7232021-07-08 12:40:05 +02005source screendump.vim
Bram Moolenaar209d3872017-11-16 21:52:51 +01006
7func Test_listchars()
8 enew!
9 set ff=unix
10 set list
11
12 set listchars+=tab:>-,space:.,trail:<
13 call append(0, [
14 \ ' aa ',
15 \ ' bb ',
16 \ ' cccc ',
17 \ 'dd ee ',
18 \ ' '
19 \ ])
20 let expected = [
21 \ '>-------aa>-----$',
22 \ '..bb>---<<$',
23 \ '...cccc><$',
24 \ 'dd........ee<<>-$',
25 \ '<$'
26 \ ]
27 redraw!
28 for i in range(1, 5)
29 call cursor(i, 1)
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020030 call assert_equal([expected[i - 1]], ScreenLines(i, '$'->virtcol()))
Bram Moolenaar209d3872017-11-16 21:52:51 +010031 endfor
32
33 set listchars-=trail:<
34 let expected = [
35 \ '>-------aa>-----$',
36 \ '..bb>---..$',
37 \ '...cccc>.$',
38 \ 'dd........ee..>-$',
39 \ '.$'
40 \ ]
41 redraw!
42 for i in range(1, 5)
43 call cursor(i, 1)
44 call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
45 endfor
46
Bram Moolenaar83a52172019-01-16 22:41:54 +010047 " tab with 3rd character.
48 set listchars-=tab:>-
49 set listchars+=tab:<=>,trail:-
50 let expected = [
51 \ '<======>aa<====>$',
52 \ '..bb<==>--$',
53 \ '...cccc>-$',
54 \ 'dd........ee--<>$',
55 \ '-$'
56 \ ]
57 redraw!
58 for i in range(1, 5)
59 call cursor(i, 1)
60 call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
61 endfor
62
Bram Moolenaar69cbbec2019-08-17 14:10:56 +020063 " tab with 3rd character and linebreak set
64 set listchars-=tab:<=>
65 set listchars+=tab:<·>
66 set linebreak
67 let expected = [
68 \ '<······>aa<····>$',
69 \ '..bb<··>--$',
70 \ '...cccc>-$',
71 \ 'dd........ee--<>$',
72 \ '-$'
73 \ ]
74 redraw!
75 for i in range(1, 5)
76 call cursor(i, 1)
77 call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
78 endfor
79 set nolinebreak
80 set listchars-=tab:<·>
81 set listchars+=tab:<=>
82
Bram Moolenaar83a52172019-01-16 22:41:54 +010083 set listchars-=trail:-
84 let expected = [
85 \ '<======>aa<====>$',
86 \ '..bb<==>..$',
87 \ '...cccc>.$',
88 \ 'dd........ee..<>$',
89 \ '.$'
90 \ ]
91 redraw!
92 for i in range(1, 5)
93 call cursor(i, 1)
94 call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
95 endfor
96
97 set listchars-=tab:<=>
98 set listchars+=tab:>-
Bram Moolenaar209d3872017-11-16 21:52:51 +010099 set listchars+=trail:<
100 set nolist
101 normal ggdG
102 call append(0, [
103 \ ' fff ',
104 \ ' gg ',
105 \ ' h ',
106 \ 'iii ',
107 \ ])
108 let l = split(execute("%list"), "\n")
109 call assert_equal([
110 \ '..fff>--<<$',
111 \ '>-------gg>-----$',
112 \ '.....h>-$',
113 \ 'iii<<<<><<$', '$'], l)
114
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100115 " Test lead and trail
116 normal ggdG
117 set listchars&
118 set listchars+=lead:>,trail:<,space:x
119 set list
120
121 call append(0, [
122 \ ' ffff ',
123 \ ' gg',
124 \ 'h ',
125 \ ' ',
126 \ ' 0 0 ',
127 \ ])
128
129 let expected = [
130 \ '>>>>ffff<<<<$',
131 \ '>>>>>>>>>>gg$',
132 \ 'h<<<<<<<<<<<$',
133 \ '<<<<<<<<<<<<$',
134 \ '>>>>0xx0<<<<$',
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100135 \ '$'
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100136 \ ]
137 redraw!
138 for i in range(1, 5)
139 call cursor(i, 1)
140 call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
141 endfor
142
143 call assert_equal(expected, split(execute("%list"), "\n"))
Bram Moolenaar895d9662019-01-31 21:57:21 +0100144
zeertzjqf14b8ba2021-09-10 16:58:30 +0200145 " Test multispace
146 normal ggdG
147 set listchars&
148 set listchars+=multispace:yYzZ
149 set list
150
151 call append(0, [
152 \ ' ffff ',
153 \ ' i i gg',
154 \ ' h ',
155 \ ' j ',
156 \ ' 0 0 ',
157 \ ])
158
159 let expected = [
160 \ 'yYzZffffyYzZ$',
161 \ 'yYi iyYzZygg$',
162 \ ' hyYzZyYzZyY$',
163 \ 'yYzZyYzZyYj $',
164 \ 'yYzZ0yY0yYzZ$',
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100165 \ '$'
zeertzjqf14b8ba2021-09-10 16:58:30 +0200166 \ ]
167 redraw!
168 for i in range(1, 5)
169 call cursor(i, 1)
170 call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
171 endfor
172
173 call assert_equal(expected, split(execute("%list"), "\n"))
174
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100175 " Test leadmultispace + multispace
176 normal ggdG
177 set listchars=eol:$,multispace:yYzZ,nbsp:S
178 set listchars+=leadmultispace:.-+*
179 set list
180
181 call append(0, [
182 \ ' ffff ',
183 \ ' i i  gg',
184 \ ' h ',
185 \ ' j ',
186 \ ' 0 0 ',
187 \ ])
188
189 let expected = [
190 \ '.-+*ffffyYzZ$',
191 \ '.-i iSyYzZgg$',
192 \ ' hyYzZyYzZyY$',
193 \ '.-+*.-+*.-j $',
194 \ '.-+*0yY0yYzZ$',
195 \ '$'
196 \ ]
197 redraw!
198 call assert_equal('eol:$,multispace:yYzZ,nbsp:S,leadmultispace:.-+*', &listchars)
199 for i in range(1, 5)
200 call cursor(i, 1)
201 call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
202 endfor
203
204 call assert_equal(expected, split(execute("%list"), "\n"))
205
206 " Test leadmultispace without multispace
207 normal ggdG
208 set listchars-=multispace:yYzZ
209 set listchars+=space:+,trail:>,eol:$
210 set list
211
212 call append(0, [
213 \ ' ffff ',
214 \ ' i i gg',
215 \ ' h ',
216 \ ' j ',
217 \ ' 0 0 ',
218 \ ])
219
220 let expected = [
221 \ '.-+*ffff>>>>$',
222 \ '.-i+i+++++gg$',
223 \ '+h>>>>>>>>>>$',
224 \ '.-+*.-+*.-j>$',
225 \ '.-+*0++0>>>>$',
226 \ '$',
227 \ ]
228
229 redraw!
230 call assert_equal('eol:$,nbsp:S,leadmultispace:.-+*,space:+,trail:>,eol:$', &listchars)
231 for i in range(1, 5)
232 call cursor(i, 1)
233 call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
234 endfor
235
236 call assert_equal(expected, split(execute("%list"), "\n"))
237
238 " Test leadmultispace only
239 normal ggdG
240 set listchars&
241 set listchars=leadmultispace:.-+*
242 set list
243
244 call append(0, [
245 \ ' ffff ',
246 \ ' i i gg',
247 \ ' h ',
248 \ ' j ',
249 \ ' 0 0 ',
250 \ ])
251
252 let expected = [
253 \ '.-+*ffff ',
254 \ '.-i i gg',
255 \ ' h ',
256 \ '.-+*.-+*.-j ',
257 \ '.-+*0 0 ',
258 \ ' ',
259 \ ]
260 redraw!
261 call assert_equal('leadmultispace:.-+*', &listchars)
262 for i in range(1, 5)
263 call cursor(i, 1)
264 call assert_equal([expected[i - 1]], ScreenLines(i, 12))
265 endfor
266 call assert_equal(expected, split(execute("%list"), "\n"))
267
268 " Test leadmultispace and lead and space
269 normal ggdG
270 set listchars&
271 set listchars+=lead:<,space:-
272 set listchars+=leadmultispace:.-+*
273 set list
274
275 call append(0, [
276 \ ' ffff ',
277 \ ' i i gg',
278 \ ' h ',
279 \ ' j ',
280 \ ' 0 0 ',
281 \ ])
282
283 let expected = [
284 \ '.-+*ffff----$',
285 \ '.-i-i-----gg$',
286 \ '<h----------$',
287 \ '.-+*.-+*.-j-$',
288 \ '.-+*0--0----$',
289 \ '$',
290 \ ]
291 redraw!
292 call assert_equal('eol:$,lead:<,space:-,leadmultispace:.-+*', &listchars)
293 for i in range(1, 5)
294 call cursor(i, 1)
295 call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
296 endfor
297 call assert_equal(expected, split(execute("%list"), "\n"))
298
zeertzjqf14b8ba2021-09-10 16:58:30 +0200299 " the last occurrence of 'multispace:' is used
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100300 set listchars&
301 set listchars+=multispace:yYzZ
zeertzjqf14b8ba2021-09-10 16:58:30 +0200302 set listchars+=space:x,multispace:XyY
303
304 let expected = [
305 \ 'XyYXffffXyYX$',
306 \ 'XyixiXyYXygg$',
307 \ 'xhXyYXyYXyYX$',
308 \ 'XyYXyYXyYXjx$',
309 \ 'XyYX0Xy0XyYX$',
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100310 \ '$'
zeertzjqf14b8ba2021-09-10 16:58:30 +0200311 \ ]
312 redraw!
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100313 call assert_equal('eol:$,multispace:yYzZ,space:x,multispace:XyY', &listchars)
zeertzjqf14b8ba2021-09-10 16:58:30 +0200314 for i in range(1, 5)
315 call cursor(i, 1)
316 call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
317 endfor
318
319 call assert_equal(expected, split(execute("%list"), "\n"))
320
321 set listchars+=lead:>,trail:<
322
323 let expected = [
324 \ '>>>>ffff<<<<$',
325 \ '>>ixiXyYXygg$',
326 \ '>h<<<<<<<<<<$',
327 \ '>>>>>>>>>>j<$',
328 \ '>>>>0Xy0<<<<$',
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100329 \ '$'
zeertzjqf14b8ba2021-09-10 16:58:30 +0200330 \ ]
331 redraw!
332 for i in range(1, 5)
333 call cursor(i, 1)
334 call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
335 endfor
336
337 call assert_equal(expected, split(execute("%list"), "\n"))
338
339 " removing 'multispace:'
340 set listchars-=multispace:XyY
341 set listchars-=multispace:yYzZ
342
343 let expected = [
344 \ '>>>>ffff<<<<$',
345 \ '>>ixixxxxxgg$',
346 \ '>h<<<<<<<<<<$',
347 \ '>>>>>>>>>>j<$',
348 \ '>>>>0xx0<<<<$',
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100349 \ '$'
zeertzjqf14b8ba2021-09-10 16:58:30 +0200350 \ ]
351 redraw!
352 for i in range(1, 5)
353 call cursor(i, 1)
354 call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
355 endfor
356
357 call assert_equal(expected, split(execute("%list"), "\n"))
358
Bram Moolenaar895d9662019-01-31 21:57:21 +0100359 " test nbsp
360 normal ggdG
361 set listchars=nbsp:X,trail:Y
362 set list
363 " Non-breaking space
364 let nbsp = nr2char(0xa0)
Bram Moolenaarf1387282021-03-22 17:11:15 +0100365 call append(0, [ ">" .. nbsp .. "<" ])
Bram Moolenaar895d9662019-01-31 21:57:21 +0100366
367 let expected = '>X< '
368
369 redraw!
370 call cursor(1, 1)
371 call assert_equal([expected], ScreenLines(1, virtcol('$')))
372
373 set listchars=nbsp:X
374 redraw!
375 call cursor(1, 1)
376 call assert_equal([expected], ScreenLines(1, virtcol('$')))
377
Bram Moolenaara5c6a0b2019-05-08 20:20:46 +0200378 " test extends
379 normal ggdG
380 set listchars=extends:Z
381 set nowrap
382 set nolist
383 call append(0, [ repeat('A', &columns + 1) ])
384
385 let expected = repeat('A', &columns)
386
387 redraw!
388 call cursor(1, 1)
389 call assert_equal([expected], ScreenLines(1, &columns))
390
391 set list
392 let expected = expected[:-2] . 'Z'
393 redraw!
394 call cursor(1, 1)
395 call assert_equal([expected], ScreenLines(1, &columns))
396
Bram Moolenaar209d3872017-11-16 21:52:51 +0100397 enew!
398 set listchars& ff&
399endfunc
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100400
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200401" Test that unicode listchars characters get properly inserted
402func Test_listchars_unicode()
403 enew!
404 let oldencoding=&encoding
405 set encoding=utf-8
406 set ff=unix
407
zeertzjqf14b8ba2021-09-10 16:58:30 +0200408 set listchars=eol:⇔,space:␣,multispace:≡≢≣,nbsp:≠,tab:←↔→
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200409 set list
410
411 let nbsp = nr2char(0xa0)
zeertzjqf14b8ba2021-09-10 16:58:30 +0200412 call append(0, [" a\tb c" .. nbsp .. "d "])
413 let expected = ['≡≢≣≡≢≣≡≢a←↔↔↔↔↔→b␣c≠d≡≢⇔']
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200414 redraw!
415 call cursor(1, 1)
416 call assert_equal(expected, ScreenLines(1, virtcol('$')))
zeertzjqf14b8ba2021-09-10 16:58:30 +0200417
Bram Moolenaar93ff6722021-10-16 17:51:40 +0100418 set listchars=eol:\\u21d4,space:\\u2423,multispace:≡\\u2262\\U00002263,nbsp:\\U00002260,tab:←↔\\u2192
419 redraw!
420 call assert_equal(expected, ScreenLines(1, virtcol('$')))
421
zeertzjqf14b8ba2021-09-10 16:58:30 +0200422 set listchars+=lead:⇨,trail:⇦
423 let expected = ['⇨⇨⇨⇨⇨⇨⇨⇨a←↔↔↔↔↔→b␣c≠d⇦⇦⇔']
424 redraw!
425 call cursor(1, 1)
426 call assert_equal(expected, ScreenLines(1, virtcol('$')))
427
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200428 let &encoding=oldencoding
429 enew!
430 set listchars& ff&
431endfunction
432
zeertzjqf14b8ba2021-09-10 16:58:30 +0200433func Test_listchars_invalid()
434 enew!
435 set ff=unix
436
437 set listchars&
438 set list
439 set ambiwidth=double
440
441 " No colon
442 call assert_fails('set listchars=x', 'E474:')
443 call assert_fails('set listchars=x', 'E474:')
444 call assert_fails('set listchars=multispace', 'E474:')
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100445 call assert_fails('set listchars=leadmultispace', 'E474:')
zeertzjqf14b8ba2021-09-10 16:58:30 +0200446
447 " Too short
448 call assert_fails('set listchars=space:', 'E474:')
449 call assert_fails('set listchars=tab:x', 'E474:')
450 call assert_fails('set listchars=multispace:', 'E474:')
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100451 call assert_fails('set listchars=leadmultispace:', 'E474:')
zeertzjqf14b8ba2021-09-10 16:58:30 +0200452
453 " One occurrence too short
454 call assert_fails('set listchars=space:,space:x', 'E474:')
455 call assert_fails('set listchars=space:x,space:', 'E474:')
456 call assert_fails('set listchars=tab:x,tab:xx', 'E474:')
457 call assert_fails('set listchars=tab:xx,tab:x', 'E474:')
458 call assert_fails('set listchars=multispace:,multispace:x', 'E474:')
459 call assert_fails('set listchars=multispace:x,multispace:', 'E474:')
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100460 call assert_fails('set listchars=leadmultispace:,leadmultispace:x', 'E474:')
461 call assert_fails('set listchars=leadmultispace:x,leadmultispace:', 'E474:')
zeertzjqf14b8ba2021-09-10 16:58:30 +0200462
463 " Too long
464 call assert_fails('set listchars=space:xx', 'E474:')
465 call assert_fails('set listchars=tab:xxxx', 'E474:')
466
zeertzjq60618c82021-12-18 15:32:46 +0000467 " Has double-width character
zeertzjqf14b8ba2021-09-10 16:58:30 +0200468 call assert_fails('set listchars=space:·', 'E474:')
469 call assert_fails('set listchars=tab:·x', 'E474:')
470 call assert_fails('set listchars=tab:x·', 'E474:')
471 call assert_fails('set listchars=tab:xx·', 'E474:')
472 call assert_fails('set listchars=multispace:·', 'E474:')
473 call assert_fails('set listchars=multispace:xxx·', 'E474:')
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100474 call assert_fails('set listchars=leadmultispace:·', 'E474:')
475 call assert_fails('set listchars=leadmultispace:xxx·', 'E474:')
zeertzjqf14b8ba2021-09-10 16:58:30 +0200476
zeertzjq60618c82021-12-18 15:32:46 +0000477 " Has control character
478 call assert_fails("set listchars=space:\x01", 'E474:')
479 call assert_fails("set listchars=tab:\x01x", 'E474:')
480 call assert_fails("set listchars=tab:x\x01", 'E474:')
481 call assert_fails("set listchars=tab:xx\x01", 'E474:')
482 call assert_fails("set listchars=multispace:\x01", 'E474:')
483 call assert_fails("set listchars=multispace:xxx\x01", 'E474:')
484 call assert_fails('set listchars=space:\\x01', 'E474:')
485 call assert_fails('set listchars=tab:\\x01x', 'E474:')
486 call assert_fails('set listchars=tab:x\\x01', 'E474:')
487 call assert_fails('set listchars=tab:xx\\x01', 'E474:')
488 call assert_fails('set listchars=multispace:\\x01', 'E474:')
489 call assert_fails('set listchars=multispace:xxx\\x01', 'E474:')
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100490 call assert_fails("set listchars=leadmultispace:\x01", 'E474:')
491 call assert_fails('set listchars=leadmultispace:\\x01', 'E474:')
492 call assert_fails("set listchars=leadmultispace:xxx\x01", 'E474:')
493 call assert_fails('set listchars=leadmultispace:xxx\\x01', 'E474:')
zeertzjq60618c82021-12-18 15:32:46 +0000494
zeertzjqf14b8ba2021-09-10 16:58:30 +0200495 enew!
496 set ambiwidth& listchars& ff&
497endfunction
498
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200499" Tests that space characters following composing character won't get replaced
500" by listchars.
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100501func Test_listchars_composing()
502 enew!
503 let oldencoding=&encoding
504 set encoding=utf-8
505 set ff=unix
506 set list
507
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200508 set listchars=eol:$,space:_,nbsp:=
509
510 let nbsp1 = nr2char(0xa0)
511 let nbsp2 = nr2char(0x202f)
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100512 call append(0, [
Bram Moolenaarf1387282021-03-22 17:11:15 +0100513 \ " \u3099\t \u309A" .. nbsp1 .. nbsp1 .. "\u0302" .. nbsp2 .. nbsp2 .. "\u0302",
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100514 \ ])
515 let expected = [
Bram Moolenaarf1387282021-03-22 17:11:15 +0100516 \ "_ \u3099^I \u309A=" .. nbsp1 .. "\u0302=" .. nbsp2 .. "\u0302$"
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100517 \ ]
518 redraw!
519 call cursor(1, 1)
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200520 call assert_equal(expected, ScreenLines(1, virtcol('$')))
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100521 let &encoding=oldencoding
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200522 enew!
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100523 set listchars& ff&
524endfunction
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200525
Bram Moolenaareed9d462021-02-15 20:38:25 +0100526" Check for the value of the 'listchars' option
527func s:CheckListCharsValue(expected)
528 call assert_equal(a:expected, &listchars)
529 call assert_equal(a:expected, getwinvar(0, '&listchars'))
530endfunc
531
532" Test for using a window local value for 'listchars'
533func Test_listchars_window_local()
534 %bw!
535 set list listchars&
536 new
537 " set a local value for 'listchars'
538 setlocal listchars=tab:+-,eol:#
539 call s:CheckListCharsValue('tab:+-,eol:#')
540 " When local value is reset, global value should be used
541 setlocal listchars=
542 call s:CheckListCharsValue('eol:$')
543 " Use 'setlocal <' to copy global value
544 setlocal listchars=space:.,extends:>
545 setlocal listchars<
546 call s:CheckListCharsValue('eol:$')
547 " Use 'set <' to copy global value
548 setlocal listchars=space:.,extends:>
549 set listchars<
550 call s:CheckListCharsValue('eol:$')
551 " Changing global setting should not change the local setting
552 setlocal listchars=space:.,extends:>
553 setglobal listchars=tab:+-,eol:#
554 call s:CheckListCharsValue('space:.,extends:>')
555 " when split opening a new window, local value should be copied
556 split
557 call s:CheckListCharsValue('space:.,extends:>')
558 " clearing local value in one window should not change the other window
559 set listchars&
560 call s:CheckListCharsValue('eol:$')
561 close
562 call s:CheckListCharsValue('space:.,extends:>')
563
564 " use different values for 'listchars' items in two different windows
565 call setline(1, ["\t one two "])
566 setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:#
567 split
568 setlocal listchars=tab:[.],lead:#,space:_,trail:.,eol:&
569 split
570 set listchars=tab:+-+,lead:^,space:>,trail:<,eol:%
571 call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$')))
572 close
573 call assert_equal(['[......]##one__two..&'], ScreenLines(1, virtcol('$')))
574 close
575 call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$')))
576 " changing the global setting should not change the local value
577 setglobal listchars=tab:[.],lead:#,space:_,trail:.,eol:&
578 call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$')))
579 set listchars<
580 call assert_equal(['[......]##one__two..&'], ScreenLines(1, virtcol('$')))
581
582 " Using setglobal in a window with local setting should not affect the
583 " window. But should impact other windows using the global setting.
584 enew! | only
585 call setline(1, ["\t one two "])
586 set listchars=tab:[.],lead:#,space:_,trail:.,eol:&
587 split
588 setlocal listchars=tab:+-+,lead:^,space:>,trail:<,eol:%
589 split
590 setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:#
591 setglobal listchars=tab:{.},lead:-,space:=,trail:#,eol:$
592 call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$')))
593 close
594 call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$')))
595 close
596 call assert_equal(['{......}--one==two##$'], ScreenLines(1, virtcol('$')))
597
598 " Setting the global setting to the default value should not impact a window
zeertzjq7a33ebf2021-11-02 20:56:07 +0000599 " using a local setting.
Bram Moolenaareed9d462021-02-15 20:38:25 +0100600 split
601 setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:#
602 setglobal listchars&vim
603 call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$')))
604 close
605 call assert_equal(['^I one two $'], ScreenLines(1, virtcol('$')))
606
607 " Setting the local setting to the default value should not impact a window
zeertzjq7a33ebf2021-11-02 20:56:07 +0000608 " using a global setting.
Bram Moolenaareed9d462021-02-15 20:38:25 +0100609 set listchars=tab:{.},lead:-,space:=,trail:#,eol:$
610 split
611 setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:#
612 call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$')))
613 setlocal listchars&vim
614 call assert_equal(['^I one two $'], ScreenLines(1, virtcol('$')))
615 close
616 call assert_equal(['{......}--one==two##$'], ScreenLines(1, virtcol('$')))
617
618 " Using set in a window with a local setting should change it to use the
zeertzjq7a33ebf2021-11-02 20:56:07 +0000619 " global setting and also impact other windows using the global setting.
Bram Moolenaareed9d462021-02-15 20:38:25 +0100620 split
621 setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:#
622 call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$')))
623 set listchars=tab:+-+,lead:^,space:>,trail:<,eol:%
624 call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$')))
625 close
626 call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$')))
627
Bram Moolenaar04ea7e92021-02-16 21:14:33 +0100628 " Setting invalid value for a local setting should not impact the local and
zeertzjq7a33ebf2021-11-02 20:56:07 +0000629 " global settings.
Bram Moolenaar04ea7e92021-02-16 21:14:33 +0100630 split
631 setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:#
632 let cmd = 'setlocal listchars=tab:{.},lead:-,space:=,trail:#,eol:$,x'
633 call assert_fails(cmd, 'E474:')
634 call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$')))
635 close
636 call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$')))
637
638 " Setting invalid value for a global setting should not impact the local and
zeertzjq7a33ebf2021-11-02 20:56:07 +0000639 " global settings.
Bram Moolenaar04ea7e92021-02-16 21:14:33 +0100640 split
641 setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:#
642 let cmd = 'setglobal listchars=tab:{.},lead:-,space:=,trail:#,eol:$,x'
643 call assert_fails(cmd, 'E474:')
644 call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$')))
645 close
646 call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$')))
647
zeertzjq7a33ebf2021-11-02 20:56:07 +0000648 " Closing window with local lcs-multispace should not cause a memory leak.
649 setlocal listchars=multispace:---+
650 split
651 call s:CheckListCharsValue('multispace:---+')
652 close
653
Bram Moolenaareed9d462021-02-15 20:38:25 +0100654 %bw!
655 set list& listchars&
656endfunc
657
Bram Moolenaar41fb7232021-07-08 12:40:05 +0200658func Test_listchars_foldcolumn()
659 CheckScreendump
660
661 let lines =<< trim END
662 call setline(1, ['aaa', '', 'a', 'aaaaaa'])
663 vsplit
664 vsplit
665 windo set signcolumn=yes foldcolumn=1 winminwidth=0 nowrap list listchars=extends:>,precedes:<
666 END
Bram Moolenaar7dd5a782022-09-29 21:01:57 +0100667 call writefile(lines, 'XTest_listchars', 'D')
Bram Moolenaar41fb7232021-07-08 12:40:05 +0200668
669 let buf = RunVimInTerminal('-S XTest_listchars', {'rows': 10, 'cols': 60})
670
671 call term_sendkeys(buf, "13\<C-W>>")
672 call VerifyScreenDump(buf, 'Test_listchars_01', {})
673 call term_sendkeys(buf, "\<C-W>>")
674 call VerifyScreenDump(buf, 'Test_listchars_02', {})
675 call term_sendkeys(buf, "\<C-W>>")
676 call VerifyScreenDump(buf, 'Test_listchars_03', {})
677 call term_sendkeys(buf, "\<C-W>>")
678 call VerifyScreenDump(buf, 'Test_listchars_04', {})
679 call term_sendkeys(buf, "\<C-W>>")
680 call VerifyScreenDump(buf, 'Test_listchars_05', {})
Bram Moolenaar30441bb2021-07-08 13:19:31 +0200681 call term_sendkeys(buf, "\<C-W>h")
682 call term_sendkeys(buf, ":set nowrap foldcolumn=4\<CR>")
683 call term_sendkeys(buf, "15\<C-W><")
684 call VerifyScreenDump(buf, 'Test_listchars_06', {})
685 call term_sendkeys(buf, "4\<C-W><")
686 call VerifyScreenDump(buf, 'Test_listchars_07', {})
Bram Moolenaar41fb7232021-07-08 12:40:05 +0200687
688 " clean up
689 call StopVimInTerminal(buf)
Bram Moolenaar41fb7232021-07-08 12:40:05 +0200690endfunc
691
692
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200693" vim: shiftwidth=2 sts=2 expandtab