blob: 8628fb20e04abfaf0bedd69f742617c73f972fae [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
zeertzjqabc80812023-09-24 23:32:18 +02007func 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
Bram Moolenaar209d3872017-11-16 21:52:51 +010037func 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 \ ]
zeertzjqabc80812023-09-24 23:32:18 +020057 call Check_listchars(expected, 5)
58 call Check_listchars(expected, 4, -1, 5)
Bram Moolenaar209d3872017-11-16 21:52:51 +010059
60 set listchars-=trail:<
61 let expected = [
62 \ '>-------aa>-----$',
63 \ '..bb>---..$',
64 \ '...cccc>.$',
65 \ 'dd........ee..>-$',
66 \ '.$'
67 \ ]
zeertzjqabc80812023-09-24 23:32:18 +020068 call Check_listchars(expected, 5)
69 call Check_listchars(expected, 4, -1, 5)
Bram Moolenaar209d3872017-11-16 21:52:51 +010070
Bram Moolenaar83a52172019-01-16 22:41:54 +010071 " 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 \ ]
zeertzjqabc80812023-09-24 23:32:18 +020081 call Check_listchars(expected, 5)
82 call Check_listchars(expected, 4, -1, 5)
Bram Moolenaar83a52172019-01-16 22:41:54 +010083
Bram Moolenaar69cbbec2019-08-17 14:10:56 +020084 " 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 \ ]
zeertzjqabc80812023-09-24 23:32:18 +020095 call Check_listchars(expected, 5)
Bram Moolenaar69cbbec2019-08-17 14:10:56 +020096 set nolinebreak
97 set listchars-=tab:<·>
98 set listchars+=tab:<=>
99
Bram Moolenaar83a52172019-01-16 22:41:54 +0100100 set listchars-=trail:-
101 let expected = [
102 \ '<======>aa<====>$',
103 \ '..bb<==>..$',
104 \ '...cccc>.$',
105 \ 'dd........ee..<>$',
106 \ '.$'
107 \ ]
zeertzjqabc80812023-09-24 23:32:18 +0200108 call Check_listchars(expected, 5)
109 call Check_listchars(expected, 4, -1, 5)
Bram Moolenaar83a52172019-01-16 22:41:54 +0100110
111 set listchars-=tab:<=>
112 set listchars+=tab:>-
Bram Moolenaar209d3872017-11-16 21:52:51 +0100113 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>-$',
zeertzjqabc80812023-09-24 23:32:18 +0200127 \ 'iii<<<<><<$',
128 \ '$'], l)
Bram Moolenaar209d3872017-11-16 21:52:51 +0100129
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100130 " Test lead and trail
131 normal ggdG
132 set listchars&
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<<<<$',
zeertzjqabc80812023-09-24 23:32:18 +0200150 \ '$'
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100151 \ ]
zeertzjqabc80812023-09-24 23:32:18 +0200152 call Check_listchars(expected, 6)
153 call Check_listchars(expected, 5, -1, 6)
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100154 call assert_equal(expected, split(execute("%list"), "\n"))
Bram Moolenaar895d9662019-01-31 21:57:21 +0100155
zeertzjqf14b8ba2021-09-10 16:58:30 +0200156 " Test multispace
157 normal ggdG
158 set listchars&
159 set listchars+=multispace:yYzZ
160 set list
161
162 call append(0, [
163 \ ' ffff ',
164 \ ' i i gg',
165 \ ' h ',
166 \ ' j ',
167 \ ' 0 0 ',
168 \ ])
169
170 let expected = [
171 \ 'yYzZffffyYzZ$',
172 \ 'yYi iyYzZygg$',
173 \ ' hyYzZyYzZyY$',
174 \ 'yYzZyYzZyYj $',
175 \ 'yYzZ0yY0yYzZ$',
zeertzjqabc80812023-09-24 23:32:18 +0200176 \ '$'
zeertzjqf14b8ba2021-09-10 16:58:30 +0200177 \ ]
zeertzjqabc80812023-09-24 23:32:18 +0200178 call Check_listchars(expected, 6)
179 call Check_listchars(expected, 5, -1, 6)
zeertzjqf14b8ba2021-09-10 16:58:30 +0200180 call assert_equal(expected, split(execute("%list"), "\n"))
181
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100182 " Test leadmultispace + multispace
183 normal ggdG
184 set listchars=eol:$,multispace:yYzZ,nbsp:S
185 set listchars+=leadmultispace:.-+*
186 set list
187
188 call append(0, [
189 \ ' ffff ',
190 \ ' i i  gg',
191 \ ' h ',
192 \ ' j ',
193 \ ' 0 0 ',
194 \ ])
195
196 let expected = [
197 \ '.-+*ffffyYzZ$',
198 \ '.-i iSyYzZgg$',
199 \ ' hyYzZyYzZyY$',
200 \ '.-+*.-+*.-j $',
201 \ '.-+*0yY0yYzZ$',
zeertzjqabc80812023-09-24 23:32:18 +0200202 \ '$'
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100203 \ ]
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100204 call assert_equal('eol:$,multispace:yYzZ,nbsp:S,leadmultispace:.-+*', &listchars)
zeertzjqabc80812023-09-24 23:32:18 +0200205 call Check_listchars(expected, 6)
206 call Check_listchars(expected, 5, -1, 1)
207 call Check_listchars(expected, 5, -1, 2)
208 call Check_listchars(expected, 5, -1, 3)
209 call Check_listchars(expected, 5, -1, 6)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100210 call assert_equal(expected, split(execute("%list"), "\n"))
211
212 " Test leadmultispace without multispace
213 normal ggdG
214 set listchars-=multispace:yYzZ
215 set listchars+=space:+,trail:>,eol:$
216 set list
217
218 call append(0, [
219 \ ' ffff ',
220 \ ' i i gg',
221 \ ' h ',
222 \ ' j ',
223 \ ' 0 0 ',
224 \ ])
225
226 let expected = [
227 \ '.-+*ffff>>>>$',
228 \ '.-i+i+++++gg$',
229 \ '+h>>>>>>>>>>$',
230 \ '.-+*.-+*.-j>$',
231 \ '.-+*0++0>>>>$',
zeertzjqabc80812023-09-24 23:32:18 +0200232 \ '$'
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100233 \ ]
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100234 call assert_equal('eol:$,nbsp:S,leadmultispace:.-+*,space:+,trail:>,eol:$', &listchars)
zeertzjqabc80812023-09-24 23:32:18 +0200235 call Check_listchars(expected, 6)
236 call Check_listchars(expected, 5, -1, 1)
237 call Check_listchars(expected, 5, -1, 2)
238 call Check_listchars(expected, 5, -1, 3)
239 call Check_listchars(expected, 5, -1, 6)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100240 call assert_equal(expected, split(execute("%list"), "\n"))
241
242 " Test leadmultispace only
243 normal ggdG
244 set listchars&
245 set listchars=leadmultispace:.-+*
246 set list
247
248 call append(0, [
249 \ ' ffff ',
250 \ ' i i gg',
251 \ ' h ',
252 \ ' j ',
253 \ ' 0 0 ',
254 \ ])
255
256 let expected = [
257 \ '.-+*ffff ',
258 \ '.-i i gg',
259 \ ' h ',
260 \ '.-+*.-+*.-j ',
261 \ '.-+*0 0 ',
zeertzjqabc80812023-09-24 23:32:18 +0200262 \ ' '
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100263 \ ]
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100264 call assert_equal('leadmultispace:.-+*', &listchars)
zeertzjqabc80812023-09-24 23:32:18 +0200265 call Check_listchars(expected, 5, 12)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100266 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----$',
zeertzjqabc80812023-09-24 23:32:18 +0200289 \ '$'
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100290 \ ]
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100291 call assert_equal('eol:$,lead:<,space:-,leadmultispace:.-+*', &listchars)
zeertzjqabc80812023-09-24 23:32:18 +0200292 call Check_listchars(expected, 6)
293 call Check_listchars(expected, 5, -1, 1)
294 call Check_listchars(expected, 5, -1, 2)
295 call Check_listchars(expected, 5, -1, 3)
296 call Check_listchars(expected, 5, -1, 6)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100297 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$',
zeertzjqabc80812023-09-24 23:32:18 +0200310 \ '$'
zeertzjqf14b8ba2021-09-10 16:58:30 +0200311 \ ]
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100312 call assert_equal('eol:$,multispace:yYzZ,space:x,multispace:XyY', &listchars)
zeertzjqabc80812023-09-24 23:32:18 +0200313 call Check_listchars(expected, 6)
314 call Check_listchars(expected, 5, -1, 6)
zeertzjqf14b8ba2021-09-10 16:58:30 +0200315 call assert_equal(expected, split(execute("%list"), "\n"))
316
317 set listchars+=lead:>,trail:<
318
319 let expected = [
320 \ '>>>>ffff<<<<$',
321 \ '>>ixiXyYXygg$',
322 \ '>h<<<<<<<<<<$',
323 \ '>>>>>>>>>>j<$',
324 \ '>>>>0Xy0<<<<$',
zeertzjqabc80812023-09-24 23:32:18 +0200325 \ '$'
zeertzjqf14b8ba2021-09-10 16:58:30 +0200326 \ ]
zeertzjqabc80812023-09-24 23:32:18 +0200327 call Check_listchars(expected, 6)
328 call Check_listchars(expected, 5, -1, 6)
zeertzjqf14b8ba2021-09-10 16:58:30 +0200329 call assert_equal(expected, split(execute("%list"), "\n"))
330
331 " removing 'multispace:'
332 set listchars-=multispace:XyY
333 set listchars-=multispace:yYzZ
334
335 let expected = [
336 \ '>>>>ffff<<<<$',
337 \ '>>ixixxxxxgg$',
338 \ '>h<<<<<<<<<<$',
339 \ '>>>>>>>>>>j<$',
340 \ '>>>>0xx0<<<<$',
zeertzjqabc80812023-09-24 23:32:18 +0200341 \ '$'
zeertzjqf14b8ba2021-09-10 16:58:30 +0200342 \ ]
zeertzjqabc80812023-09-24 23:32:18 +0200343 call Check_listchars(expected, 6)
344 call Check_listchars(expected, 5, -1, 6)
zeertzjqf14b8ba2021-09-10 16:58:30 +0200345 call assert_equal(expected, split(execute("%list"), "\n"))
346
Bram Moolenaar895d9662019-01-31 21:57:21 +0100347 " test nbsp
348 normal ggdG
349 set listchars=nbsp:X,trail:Y
350 set list
351 " Non-breaking space
352 let nbsp = nr2char(0xa0)
Bram Moolenaarf1387282021-03-22 17:11:15 +0100353 call append(0, [ ">" .. nbsp .. "<" ])
Bram Moolenaar895d9662019-01-31 21:57:21 +0100354
355 let expected = '>X< '
zeertzjqabc80812023-09-24 23:32:18 +0200356 call Check_listchars([expected], 1)
Bram Moolenaar895d9662019-01-31 21:57:21 +0100357
358 set listchars=nbsp:X
zeertzjqabc80812023-09-24 23:32:18 +0200359 call Check_listchars([expected], 1)
Bram Moolenaar895d9662019-01-31 21:57:21 +0100360
Bram Moolenaara5c6a0b2019-05-08 20:20:46 +0200361 " test extends
362 normal ggdG
363 set listchars=extends:Z
364 set nowrap
365 set nolist
366 call append(0, [ repeat('A', &columns + 1) ])
367
368 let expected = repeat('A', &columns)
zeertzjqabc80812023-09-24 23:32:18 +0200369 call Check_listchars([expected], 1, &columns)
Bram Moolenaara5c6a0b2019-05-08 20:20:46 +0200370
371 set list
372 let expected = expected[:-2] . 'Z'
zeertzjqabc80812023-09-24 23:32:18 +0200373 call Check_listchars([expected], 1, &columns)
Bram Moolenaara5c6a0b2019-05-08 20:20:46 +0200374
Bram Moolenaar209d3872017-11-16 21:52:51 +0100375 enew!
376 set listchars& ff&
377endfunc
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100378
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200379" Test that unicode listchars characters get properly inserted
380func Test_listchars_unicode()
381 enew!
382 let oldencoding=&encoding
383 set encoding=utf-8
384 set ff=unix
385
zeertzjqf14b8ba2021-09-10 16:58:30 +0200386 set listchars=eol:⇔,space:␣,multispace:≡≢≣,nbsp:≠,tab:←↔→
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200387 set list
388
389 let nbsp = nr2char(0xa0)
zeertzjqf14b8ba2021-09-10 16:58:30 +0200390 call append(0, [" a\tb c" .. nbsp .. "d "])
391 let expected = ['≡≢≣≡≢≣≡≢a←↔↔↔↔↔→b␣c≠d≡≢⇔']
zeertzjqabc80812023-09-24 23:32:18 +0200392 call Check_listchars(expected, 1)
393 call Check_listchars(expected, 1, -1, 3)
394 call Check_listchars(expected, 1, -1, 13)
zeertzjqf14b8ba2021-09-10 16:58:30 +0200395
Bram Moolenaar93ff6722021-10-16 17:51:40 +0100396 set listchars=eol:\\u21d4,space:\\u2423,multispace:≡\\u2262\\U00002263,nbsp:\\U00002260,tab:←↔\\u2192
zeertzjqabc80812023-09-24 23:32:18 +0200397 call Check_listchars(expected, 1)
398 call Check_listchars(expected, 1, -1, 3)
399 call Check_listchars(expected, 1, -1, 13)
Bram Moolenaar93ff6722021-10-16 17:51:40 +0100400
zeertzjqf14b8ba2021-09-10 16:58:30 +0200401 set listchars+=lead:⇨,trail:⇦
402 let expected = ['⇨⇨⇨⇨⇨⇨⇨⇨a←↔↔↔↔↔→b␣c≠d⇦⇦⇔']
zeertzjqabc80812023-09-24 23:32:18 +0200403 call Check_listchars(expected, 1)
404 call Check_listchars(expected, 1, -1, 3)
405 call Check_listchars(expected, 1, -1, 13)
zeertzjqf14b8ba2021-09-10 16:58:30 +0200406
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200407 let &encoding=oldencoding
408 enew!
409 set listchars& ff&
410endfunction
411
zeertzjqf14b8ba2021-09-10 16:58:30 +0200412func Test_listchars_invalid()
413 enew!
414 set ff=unix
415
416 set listchars&
417 set list
418 set ambiwidth=double
419
420 " No colon
421 call assert_fails('set listchars=x', 'E474:')
422 call assert_fails('set listchars=x', 'E474:')
423 call assert_fails('set listchars=multispace', 'E474:')
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100424 call assert_fails('set listchars=leadmultispace', 'E474:')
zeertzjqf14b8ba2021-09-10 16:58:30 +0200425
426 " Too short
427 call assert_fails('set listchars=space:', 'E474:')
428 call assert_fails('set listchars=tab:x', 'E474:')
429 call assert_fails('set listchars=multispace:', 'E474:')
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100430 call assert_fails('set listchars=leadmultispace:', 'E474:')
zeertzjqf14b8ba2021-09-10 16:58:30 +0200431
432 " One occurrence too short
433 call assert_fails('set listchars=space:,space:x', 'E474:')
434 call assert_fails('set listchars=space:x,space:', 'E474:')
435 call assert_fails('set listchars=tab:x,tab:xx', 'E474:')
436 call assert_fails('set listchars=tab:xx,tab:x', 'E474:')
437 call assert_fails('set listchars=multispace:,multispace:x', 'E474:')
438 call assert_fails('set listchars=multispace:x,multispace:', 'E474:')
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100439 call assert_fails('set listchars=leadmultispace:,leadmultispace:x', 'E474:')
440 call assert_fails('set listchars=leadmultispace:x,leadmultispace:', 'E474:')
zeertzjqf14b8ba2021-09-10 16:58:30 +0200441
442 " Too long
443 call assert_fails('set listchars=space:xx', 'E474:')
444 call assert_fails('set listchars=tab:xxxx', 'E474:')
445
zeertzjq60618c82021-12-18 15:32:46 +0000446 " Has double-width character
zeertzjqf14b8ba2021-09-10 16:58:30 +0200447 call assert_fails('set listchars=space:·', 'E474:')
448 call assert_fails('set listchars=tab:·x', 'E474:')
449 call assert_fails('set listchars=tab:x·', 'E474:')
450 call assert_fails('set listchars=tab:xx·', 'E474:')
451 call assert_fails('set listchars=multispace:·', 'E474:')
452 call assert_fails('set listchars=multispace:xxx·', 'E474:')
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100453 call assert_fails('set listchars=leadmultispace:·', 'E474:')
454 call assert_fails('set listchars=leadmultispace:xxx·', 'E474:')
zeertzjqf14b8ba2021-09-10 16:58:30 +0200455
zeertzjq60618c82021-12-18 15:32:46 +0000456 " Has control character
457 call assert_fails("set listchars=space:\x01", 'E474:')
458 call assert_fails("set listchars=tab:\x01x", 'E474:')
459 call assert_fails("set listchars=tab:x\x01", 'E474:')
460 call assert_fails("set listchars=tab:xx\x01", 'E474:')
461 call assert_fails("set listchars=multispace:\x01", 'E474:')
462 call assert_fails("set listchars=multispace:xxx\x01", 'E474:')
463 call assert_fails('set listchars=space:\\x01', 'E474:')
464 call assert_fails('set listchars=tab:\\x01x', 'E474:')
465 call assert_fails('set listchars=tab:x\\x01', 'E474:')
466 call assert_fails('set listchars=tab:xx\\x01', 'E474:')
467 call assert_fails('set listchars=multispace:\\x01', 'E474:')
468 call assert_fails('set listchars=multispace:xxx\\x01', 'E474:')
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100469 call assert_fails("set listchars=leadmultispace:\x01", 'E474:')
470 call assert_fails('set listchars=leadmultispace:\\x01', 'E474:')
471 call assert_fails("set listchars=leadmultispace:xxx\x01", 'E474:')
472 call assert_fails('set listchars=leadmultispace:xxx\\x01', 'E474:')
zeertzjq60618c82021-12-18 15:32:46 +0000473
zeertzjqf14b8ba2021-09-10 16:58:30 +0200474 enew!
475 set ambiwidth& listchars& ff&
476endfunction
477
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200478" Tests that space characters following composing character won't get replaced
479" by listchars.
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100480func Test_listchars_composing()
481 enew!
482 let oldencoding=&encoding
483 set encoding=utf-8
484 set ff=unix
485 set list
486
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200487 set listchars=eol:$,space:_,nbsp:=
Bram Moolenaar94722c52023-01-28 19:19:03 +0000488
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200489 let nbsp1 = nr2char(0xa0)
490 let nbsp2 = nr2char(0x202f)
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100491 call append(0, [
Bram Moolenaarf1387282021-03-22 17:11:15 +0100492 \ " \u3099\t \u309A" .. nbsp1 .. nbsp1 .. "\u0302" .. nbsp2 .. nbsp2 .. "\u0302",
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100493 \ ])
494 let expected = [
Bram Moolenaarf1387282021-03-22 17:11:15 +0100495 \ "_ \u3099^I \u309A=" .. nbsp1 .. "\u0302=" .. nbsp2 .. "\u0302$"
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100496 \ ]
zeertzjqabc80812023-09-24 23:32:18 +0200497 call Check_listchars(expected, 1)
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100498 let &encoding=oldencoding
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200499 enew!
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100500 set listchars& ff&
501endfunction
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200502
Bram Moolenaareed9d462021-02-15 20:38:25 +0100503" Check for the value of the 'listchars' option
504func s:CheckListCharsValue(expected)
505 call assert_equal(a:expected, &listchars)
506 call assert_equal(a:expected, getwinvar(0, '&listchars'))
507endfunc
508
509" Test for using a window local value for 'listchars'
510func Test_listchars_window_local()
511 %bw!
512 set list listchars&
513 new
514 " set a local value for 'listchars'
515 setlocal listchars=tab:+-,eol:#
516 call s:CheckListCharsValue('tab:+-,eol:#')
517 " When local value is reset, global value should be used
518 setlocal listchars=
519 call s:CheckListCharsValue('eol:$')
520 " Use 'setlocal <' to copy global value
521 setlocal listchars=space:.,extends:>
522 setlocal listchars<
523 call s:CheckListCharsValue('eol:$')
524 " Use 'set <' to copy global value
525 setlocal listchars=space:.,extends:>
526 set listchars<
527 call s:CheckListCharsValue('eol:$')
528 " Changing global setting should not change the local setting
529 setlocal listchars=space:.,extends:>
530 setglobal listchars=tab:+-,eol:#
531 call s:CheckListCharsValue('space:.,extends:>')
532 " when split opening a new window, local value should be copied
533 split
534 call s:CheckListCharsValue('space:.,extends:>')
535 " clearing local value in one window should not change the other window
536 set listchars&
537 call s:CheckListCharsValue('eol:$')
538 close
539 call s:CheckListCharsValue('space:.,extends:>')
540
541 " use different values for 'listchars' items in two different windows
542 call setline(1, ["\t one two "])
543 setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:#
544 split
545 setlocal listchars=tab:[.],lead:#,space:_,trail:.,eol:&
546 split
547 set listchars=tab:+-+,lead:^,space:>,trail:<,eol:%
548 call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$')))
549 close
550 call assert_equal(['[......]##one__two..&'], ScreenLines(1, virtcol('$')))
551 close
552 call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$')))
553 " changing the global setting should not change the local value
554 setglobal listchars=tab:[.],lead:#,space:_,trail:.,eol:&
555 call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$')))
556 set listchars<
557 call assert_equal(['[......]##one__two..&'], ScreenLines(1, virtcol('$')))
558
559 " Using setglobal in a window with local setting should not affect the
560 " window. But should impact other windows using the global setting.
561 enew! | only
562 call setline(1, ["\t one two "])
563 set listchars=tab:[.],lead:#,space:_,trail:.,eol:&
564 split
565 setlocal listchars=tab:+-+,lead:^,space:>,trail:<,eol:%
566 split
567 setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:#
568 setglobal listchars=tab:{.},lead:-,space:=,trail:#,eol:$
569 call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$')))
570 close
571 call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$')))
572 close
573 call assert_equal(['{......}--one==two##$'], ScreenLines(1, virtcol('$')))
574
575 " Setting the global setting to the default value should not impact a window
zeertzjq7a33ebf2021-11-02 20:56:07 +0000576 " using a local setting.
Bram Moolenaareed9d462021-02-15 20:38:25 +0100577 split
578 setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:#
579 setglobal listchars&vim
580 call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$')))
581 close
582 call assert_equal(['^I one two $'], ScreenLines(1, virtcol('$')))
583
584 " Setting the local setting to the default value should not impact a window
zeertzjq7a33ebf2021-11-02 20:56:07 +0000585 " using a global setting.
Bram Moolenaareed9d462021-02-15 20:38:25 +0100586 set listchars=tab:{.},lead:-,space:=,trail:#,eol:$
587 split
588 setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:#
589 call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$')))
590 setlocal listchars&vim
591 call assert_equal(['^I one two $'], ScreenLines(1, virtcol('$')))
592 close
593 call assert_equal(['{......}--one==two##$'], ScreenLines(1, virtcol('$')))
594
595 " Using set in a window with a local setting should change it to use the
zeertzjq7a33ebf2021-11-02 20:56:07 +0000596 " global setting and also impact other windows using the global setting.
Bram Moolenaareed9d462021-02-15 20:38:25 +0100597 split
598 setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:#
599 call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$')))
600 set listchars=tab:+-+,lead:^,space:>,trail:<,eol:%
601 call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$')))
602 close
603 call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$')))
604
Bram Moolenaar04ea7e92021-02-16 21:14:33 +0100605 " Setting invalid value for a local setting should not impact the local and
zeertzjq7a33ebf2021-11-02 20:56:07 +0000606 " global settings.
Bram Moolenaar04ea7e92021-02-16 21:14:33 +0100607 split
608 setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:#
609 let cmd = 'setlocal listchars=tab:{.},lead:-,space:=,trail:#,eol:$,x'
610 call assert_fails(cmd, 'E474:')
611 call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$')))
612 close
613 call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$')))
614
615 " Setting invalid value for a global setting should not impact the local and
zeertzjq7a33ebf2021-11-02 20:56:07 +0000616 " global settings.
Bram Moolenaar04ea7e92021-02-16 21:14:33 +0100617 split
618 setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:#
619 let cmd = 'setglobal listchars=tab:{.},lead:-,space:=,trail:#,eol:$,x'
620 call assert_fails(cmd, 'E474:')
621 call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$')))
622 close
623 call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$')))
624
zeertzjq7a33ebf2021-11-02 20:56:07 +0000625 " Closing window with local lcs-multispace should not cause a memory leak.
626 setlocal listchars=multispace:---+
627 split
628 call s:CheckListCharsValue('multispace:---+')
629 close
630
Bram Moolenaareed9d462021-02-15 20:38:25 +0100631 %bw!
632 set list& listchars&
633endfunc
634
Bram Moolenaar41fb7232021-07-08 12:40:05 +0200635func Test_listchars_foldcolumn()
636 CheckScreendump
637
638 let lines =<< trim END
639 call setline(1, ['aaa', '', 'a', 'aaaaaa'])
640 vsplit
641 vsplit
642 windo set signcolumn=yes foldcolumn=1 winminwidth=0 nowrap list listchars=extends:>,precedes:<
643 END
Bram Moolenaar7dd5a782022-09-29 21:01:57 +0100644 call writefile(lines, 'XTest_listchars', 'D')
Bram Moolenaar41fb7232021-07-08 12:40:05 +0200645
646 let buf = RunVimInTerminal('-S XTest_listchars', {'rows': 10, 'cols': 60})
647
648 call term_sendkeys(buf, "13\<C-W>>")
649 call VerifyScreenDump(buf, 'Test_listchars_01', {})
650 call term_sendkeys(buf, "\<C-W>>")
651 call VerifyScreenDump(buf, 'Test_listchars_02', {})
652 call term_sendkeys(buf, "\<C-W>>")
653 call VerifyScreenDump(buf, 'Test_listchars_03', {})
654 call term_sendkeys(buf, "\<C-W>>")
655 call VerifyScreenDump(buf, 'Test_listchars_04', {})
656 call term_sendkeys(buf, "\<C-W>>")
657 call VerifyScreenDump(buf, 'Test_listchars_05', {})
Bram Moolenaar30441bb2021-07-08 13:19:31 +0200658 call term_sendkeys(buf, "\<C-W>h")
659 call term_sendkeys(buf, ":set nowrap foldcolumn=4\<CR>")
660 call term_sendkeys(buf, "15\<C-W><")
661 call VerifyScreenDump(buf, 'Test_listchars_06', {})
662 call term_sendkeys(buf, "4\<C-W><")
663 call VerifyScreenDump(buf, 'Test_listchars_07', {})
Bram Moolenaar41fb7232021-07-08 12:40:05 +0200664
665 " clean up
666 call StopVimInTerminal(buf)
Bram Moolenaar41fb7232021-07-08 12:40:05 +0200667endfunc
668
669
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200670" vim: shiftwidth=2 sts=2 expandtab