blob: 69c98b9269685530e51077216d3bd6b921db04f0 [file] [log] [blame]
Bram Moolenaar209d3872017-11-16 21:52:51 +01001" Tests for 'listchars' display with 'list' and :list
2
3source view_util.vim
4
5func Test_listchars()
6 enew!
7 set ff=unix
8 set list
9
10 set listchars+=tab:>-,space:.,trail:<
11 call append(0, [
12 \ ' aa ',
13 \ ' bb ',
14 \ ' cccc ',
15 \ 'dd ee ',
16 \ ' '
17 \ ])
18 let expected = [
19 \ '>-------aa>-----$',
20 \ '..bb>---<<$',
21 \ '...cccc><$',
22 \ 'dd........ee<<>-$',
23 \ '<$'
24 \ ]
25 redraw!
26 for i in range(1, 5)
27 call cursor(i, 1)
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020028 call assert_equal([expected[i - 1]], ScreenLines(i, '$'->virtcol()))
Bram Moolenaar209d3872017-11-16 21:52:51 +010029 endfor
30
31 set listchars-=trail:<
32 let expected = [
33 \ '>-------aa>-----$',
34 \ '..bb>---..$',
35 \ '...cccc>.$',
36 \ 'dd........ee..>-$',
37 \ '.$'
38 \ ]
39 redraw!
40 for i in range(1, 5)
41 call cursor(i, 1)
42 call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
43 endfor
44
Bram Moolenaar83a52172019-01-16 22:41:54 +010045 " tab with 3rd character.
46 set listchars-=tab:>-
47 set listchars+=tab:<=>,trail:-
48 let expected = [
49 \ '<======>aa<====>$',
50 \ '..bb<==>--$',
51 \ '...cccc>-$',
52 \ 'dd........ee--<>$',
53 \ '-$'
54 \ ]
55 redraw!
56 for i in range(1, 5)
57 call cursor(i, 1)
58 call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
59 endfor
60
Bram Moolenaar69cbbec2019-08-17 14:10:56 +020061 " tab with 3rd character and linebreak set
62 set listchars-=tab:<=>
63 set listchars+=tab:<·>
64 set linebreak
65 let expected = [
66 \ '<······>aa<····>$',
67 \ '..bb<··>--$',
68 \ '...cccc>-$',
69 \ 'dd........ee--<>$',
70 \ '-$'
71 \ ]
72 redraw!
73 for i in range(1, 5)
74 call cursor(i, 1)
75 call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
76 endfor
77 set nolinebreak
78 set listchars-=tab:<·>
79 set listchars+=tab:<=>
80
Bram Moolenaar83a52172019-01-16 22:41:54 +010081 set listchars-=trail:-
82 let expected = [
83 \ '<======>aa<====>$',
84 \ '..bb<==>..$',
85 \ '...cccc>.$',
86 \ 'dd........ee..<>$',
87 \ '.$'
88 \ ]
89 redraw!
90 for i in range(1, 5)
91 call cursor(i, 1)
92 call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
93 endfor
94
95 set listchars-=tab:<=>
96 set listchars+=tab:>-
Bram Moolenaar209d3872017-11-16 21:52:51 +010097 set listchars+=trail:<
98 set nolist
99 normal ggdG
100 call append(0, [
101 \ ' fff ',
102 \ ' gg ',
103 \ ' h ',
104 \ 'iii ',
105 \ ])
106 let l = split(execute("%list"), "\n")
107 call assert_equal([
108 \ '..fff>--<<$',
109 \ '>-------gg>-----$',
110 \ '.....h>-$',
111 \ 'iii<<<<><<$', '$'], l)
112
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100113 " Test lead and trail
114 normal ggdG
115 set listchars&
116 set listchars+=lead:>,trail:<,space:x
117 set list
118
119 call append(0, [
120 \ ' ffff ',
121 \ ' gg',
122 \ 'h ',
123 \ ' ',
124 \ ' 0 0 ',
125 \ ])
126
127 let expected = [
128 \ '>>>>ffff<<<<$',
129 \ '>>>>>>>>>>gg$',
130 \ 'h<<<<<<<<<<<$',
131 \ '<<<<<<<<<<<<$',
132 \ '>>>>0xx0<<<<$',
133 \ '$'
134 \ ]
135 redraw!
136 for i in range(1, 5)
137 call cursor(i, 1)
138 call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
139 endfor
140
141 call assert_equal(expected, split(execute("%list"), "\n"))
Bram Moolenaar895d9662019-01-31 21:57:21 +0100142
143 " test nbsp
144 normal ggdG
145 set listchars=nbsp:X,trail:Y
146 set list
147 " Non-breaking space
148 let nbsp = nr2char(0xa0)
149 call append(0, [ ">".nbsp."<" ])
150
151 let expected = '>X< '
152
153 redraw!
154 call cursor(1, 1)
155 call assert_equal([expected], ScreenLines(1, virtcol('$')))
156
157 set listchars=nbsp:X
158 redraw!
159 call cursor(1, 1)
160 call assert_equal([expected], ScreenLines(1, virtcol('$')))
161
Bram Moolenaara5c6a0b2019-05-08 20:20:46 +0200162 " test extends
163 normal ggdG
164 set listchars=extends:Z
165 set nowrap
166 set nolist
167 call append(0, [ repeat('A', &columns + 1) ])
168
169 let expected = repeat('A', &columns)
170
171 redraw!
172 call cursor(1, 1)
173 call assert_equal([expected], ScreenLines(1, &columns))
174
175 set list
176 let expected = expected[:-2] . 'Z'
177 redraw!
178 call cursor(1, 1)
179 call assert_equal([expected], ScreenLines(1, &columns))
180
Bram Moolenaar209d3872017-11-16 21:52:51 +0100181 enew!
182 set listchars& ff&
183endfunc
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100184
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200185" Test that unicode listchars characters get properly inserted
186func Test_listchars_unicode()
187 enew!
188 let oldencoding=&encoding
189 set encoding=utf-8
190 set ff=unix
191
192 set listchars=eol:⇔,space:␣,nbsp:≠,tab:←↔→
193 set list
194
195 let nbsp = nr2char(0xa0)
196 call append(0, [
197 \ "a\tb c".nbsp."d"
198 \ ])
199 let expected = [
200 \ 'a←↔↔↔↔↔→b␣c≠d⇔'
201 \ ]
202 redraw!
203 call cursor(1, 1)
204 call assert_equal(expected, ScreenLines(1, virtcol('$')))
205 let &encoding=oldencoding
206 enew!
207 set listchars& ff&
208endfunction
209
210" Tests that space characters following composing character won't get replaced
211" by listchars.
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100212func Test_listchars_composing()
213 enew!
214 let oldencoding=&encoding
215 set encoding=utf-8
216 set ff=unix
217 set list
218
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200219 set listchars=eol:$,space:_,nbsp:=
220
221 let nbsp1 = nr2char(0xa0)
222 let nbsp2 = nr2char(0x202f)
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100223 call append(0, [
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200224 \ " \u3099\t \u309A".nbsp1.nbsp1."\u0302".nbsp2.nbsp2."\u0302",
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100225 \ ])
226 let expected = [
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200227 \ "_ \u3099^I \u309A=".nbsp1."\u0302=".nbsp2."\u0302$"
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100228 \ ]
229 redraw!
230 call cursor(1, 1)
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200231 call assert_equal(expected, ScreenLines(1, virtcol('$')))
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100232 let &encoding=oldencoding
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200233 enew!
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100234 set listchars& ff&
235endfunction
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200236
237" vim: shiftwidth=2 sts=2 expandtab