comparison src/testdir/test_listchars.vim @ 25778:373278f5bd51 v8.2.3424

patch 8.2.3424: a sequence of spaces is hard to see in list mode Commit: https://github.com/vim/vim/commit/f14b8ba1373f569705cb80419248054100b02360 Author: zeertzjq <zeertzjq@outlook.com> Date: Fri Sep 10 16:58:30 2021 +0200 patch 8.2.3424: a sequence of spaces is hard to see in list mode Problem: A sequence of spaces is hard to see in list mode. Solution: Add the "multispace" option to 'listchars'. (closes https://github.com/vim/vim/issues/8834)
author Bram Moolenaar <Bram@vim.org>
date Fri, 10 Sep 2021 17:00:07 +0200
parents 406ab8d0bc0f
children 40b17deb294f
comparison
equal deleted inserted replaced
25777:584b2206c6d4 25778:373278f5bd51
140 call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$'))) 140 call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
141 endfor 141 endfor
142 142
143 call assert_equal(expected, split(execute("%list"), "\n")) 143 call assert_equal(expected, split(execute("%list"), "\n"))
144 144
145 " 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$',
165 \ '$'
166 \ ]
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
175 " the last occurrence of 'multispace:' is used
176 set listchars+=space:x,multispace:XyY
177
178 let expected = [
179 \ 'XyYXffffXyYX$',
180 \ 'XyixiXyYXygg$',
181 \ 'xhXyYXyYXyYX$',
182 \ 'XyYXyYXyYXjx$',
183 \ 'XyYX0Xy0XyYX$',
184 \ '$'
185 \ ]
186 redraw!
187 for i in range(1, 5)
188 call cursor(i, 1)
189 call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
190 endfor
191
192 call assert_equal(expected, split(execute("%list"), "\n"))
193
194 set listchars+=lead:>,trail:<
195
196 let expected = [
197 \ '>>>>ffff<<<<$',
198 \ '>>ixiXyYXygg$',
199 \ '>h<<<<<<<<<<$',
200 \ '>>>>>>>>>>j<$',
201 \ '>>>>0Xy0<<<<$',
202 \ '$'
203 \ ]
204 redraw!
205 for i in range(1, 5)
206 call cursor(i, 1)
207 call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
208 endfor
209
210 call assert_equal(expected, split(execute("%list"), "\n"))
211
212 " removing 'multispace:'
213 set listchars-=multispace:XyY
214 set listchars-=multispace:yYzZ
215
216 let expected = [
217 \ '>>>>ffff<<<<$',
218 \ '>>ixixxxxxgg$',
219 \ '>h<<<<<<<<<<$',
220 \ '>>>>>>>>>>j<$',
221 \ '>>>>0xx0<<<<$',
222 \ '$'
223 \ ]
224 redraw!
225 for i in range(1, 5)
226 call cursor(i, 1)
227 call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
228 endfor
229
230 call assert_equal(expected, split(execute("%list"), "\n"))
231
145 " test nbsp 232 " test nbsp
146 normal ggdG 233 normal ggdG
147 set listchars=nbsp:X,trail:Y 234 set listchars=nbsp:X,trail:Y
148 set list 235 set list
149 " Non-breaking space 236 " Non-breaking space
189 enew! 276 enew!
190 let oldencoding=&encoding 277 let oldencoding=&encoding
191 set encoding=utf-8 278 set encoding=utf-8
192 set ff=unix 279 set ff=unix
193 280
194 set listchars=eol:⇔,space:␣,nbsp:≠,tab:←↔→ 281 set listchars=eol:⇔,space:␣,multispace:≡≢≣,nbsp:≠,tab:←↔→
195 set list 282 set list
196 283
197 let nbsp = nr2char(0xa0) 284 let nbsp = nr2char(0xa0)
198 call append(0, ["a\tb c" .. nbsp .. "d"]) 285 call append(0, [" a\tb c" .. nbsp .. "d "])
199 let expected = ['a←↔↔↔↔↔→b␣c≠d⇔'] 286 let expected = ['≡≢≣≡≢≣≡≢a←↔↔↔↔↔→b␣c≠d≡≢⇔']
200 redraw! 287 redraw!
201 call cursor(1, 1) 288 call cursor(1, 1)
202 call assert_equal(expected, ScreenLines(1, virtcol('$'))) 289 call assert_equal(expected, ScreenLines(1, virtcol('$')))
290
291 set listchars+=lead:⇨,trail:⇦
292 let expected = ['⇨⇨⇨⇨⇨⇨⇨⇨a←↔↔↔↔↔→b␣c≠d⇦⇦⇔']
293 redraw!
294 call cursor(1, 1)
295 call assert_equal(expected, ScreenLines(1, virtcol('$')))
296
203 let &encoding=oldencoding 297 let &encoding=oldencoding
204 enew! 298 enew!
205 set listchars& ff& 299 set listchars& ff&
300 endfunction
301
302 func Test_listchars_invalid()
303 enew!
304 set ff=unix
305
306 set listchars&
307 set list
308 set ambiwidth=double
309
310 " No colon
311 call assert_fails('set listchars=x', 'E474:')
312 call assert_fails('set listchars=x', 'E474:')
313 call assert_fails('set listchars=multispace', 'E474:')
314
315 " Too short
316 call assert_fails('set listchars=space:', 'E474:')
317 call assert_fails('set listchars=tab:x', 'E474:')
318 call assert_fails('set listchars=multispace:', 'E474:')
319
320 " One occurrence too short
321 call assert_fails('set listchars=space:,space:x', 'E474:')
322 call assert_fails('set listchars=space:x,space:', 'E474:')
323 call assert_fails('set listchars=tab:x,tab:xx', 'E474:')
324 call assert_fails('set listchars=tab:xx,tab:x', 'E474:')
325 call assert_fails('set listchars=multispace:,multispace:x', 'E474:')
326 call assert_fails('set listchars=multispace:x,multispace:', 'E474:')
327
328 " Too long
329 call assert_fails('set listchars=space:xx', 'E474:')
330 call assert_fails('set listchars=tab:xxxx', 'E474:')
331
332 " Has non-single width character
333 call assert_fails('set listchars=space:·', 'E474:')
334 call assert_fails('set listchars=tab:·x', 'E474:')
335 call assert_fails('set listchars=tab:x·', 'E474:')
336 call assert_fails('set listchars=tab:xx·', 'E474:')
337 call assert_fails('set listchars=multispace:·', 'E474:')
338 call assert_fails('set listchars=multispace:xxx·', 'E474:')
339
340 enew!
341 set ambiwidth& listchars& ff&
206 endfunction 342 endfunction
207 343
208 " Tests that space characters following composing character won't get replaced 344 " Tests that space characters following composing character won't get replaced
209 " by listchars. 345 " by listchars.
210 func Test_listchars_composing() 346 func Test_listchars_composing()