diff 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
line wrap: on
line diff
--- a/src/testdir/test_listchars.vim
+++ b/src/testdir/test_listchars.vim
@@ -142,6 +142,93 @@ func Test_listchars()
 
   call assert_equal(expected, split(execute("%list"), "\n"))
 
+  " Test multispace
+  normal ggdG
+  set listchars&
+  set listchars+=multispace:yYzZ
+  set list
+
+  call append(0, [
+	      \ '    ffff    ',
+	      \ '  i i     gg',
+	      \ ' h          ',
+	      \ '          j ',
+	      \ '    0  0    ',
+	      \ ])
+
+  let expected = [
+	      \ 'yYzZffffyYzZ$',
+	      \ 'yYi iyYzZygg$',
+	      \ ' hyYzZyYzZyY$',
+	      \ 'yYzZyYzZyYj $',
+	      \ 'yYzZ0yY0yYzZ$',
+              \ '$'
+	      \ ]
+  redraw!
+  for i in range(1, 5)
+    call cursor(i, 1)
+    call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
+  endfor
+
+  call assert_equal(expected, split(execute("%list"), "\n"))
+
+  " the last occurrence of 'multispace:' is used
+  set listchars+=space:x,multispace:XyY
+
+  let expected = [
+	      \ 'XyYXffffXyYX$',
+	      \ 'XyixiXyYXygg$',
+	      \ 'xhXyYXyYXyYX$',
+	      \ 'XyYXyYXyYXjx$',
+	      \ 'XyYX0Xy0XyYX$',
+              \ '$'
+	      \ ]
+  redraw!
+  for i in range(1, 5)
+    call cursor(i, 1)
+    call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
+  endfor
+
+  call assert_equal(expected, split(execute("%list"), "\n"))
+
+  set listchars+=lead:>,trail:<
+
+  let expected = [
+	      \ '>>>>ffff<<<<$',
+	      \ '>>ixiXyYXygg$',
+	      \ '>h<<<<<<<<<<$',
+	      \ '>>>>>>>>>>j<$',
+	      \ '>>>>0Xy0<<<<$',
+              \ '$'
+	      \ ]
+  redraw!
+  for i in range(1, 5)
+    call cursor(i, 1)
+    call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
+  endfor
+
+  call assert_equal(expected, split(execute("%list"), "\n"))
+
+  " removing 'multispace:'
+  set listchars-=multispace:XyY
+  set listchars-=multispace:yYzZ
+
+  let expected = [
+	      \ '>>>>ffff<<<<$',
+	      \ '>>ixixxxxxgg$',
+	      \ '>h<<<<<<<<<<$',
+	      \ '>>>>>>>>>>j<$',
+	      \ '>>>>0xx0<<<<$',
+              \ '$'
+	      \ ]
+  redraw!
+  for i in range(1, 5)
+    call cursor(i, 1)
+    call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
+  endfor
+
+  call assert_equal(expected, split(execute("%list"), "\n"))
+
   " test nbsp
   normal ggdG
   set listchars=nbsp:X,trail:Y
@@ -191,20 +278,69 @@ func Test_listchars_unicode()
   set encoding=utf-8
   set ff=unix
 
-  set listchars=eol:⇔,space:␣,nbsp:≠,tab:←↔→
+  set listchars=eol:⇔,space:␣,multispace:≡≢≣,nbsp:≠,tab:←↔→
   set list
 
   let nbsp = nr2char(0xa0)
-  call append(0, ["a\tb c" .. nbsp .. "d"])
-  let expected = ['a←↔↔↔↔↔→b␣c≠d⇔']
+  call append(0, ["        a\tb c" .. nbsp .. "d  "])
+  let expected = ['≡≢≣≡≢≣≡≢a←↔↔↔↔↔→b␣c≠d≡≢⇔']
+  redraw!
+  call cursor(1, 1)
+  call assert_equal(expected, ScreenLines(1, virtcol('$')))
+
+  set listchars+=lead:⇨,trail:⇦
+  let expected = ['⇨⇨⇨⇨⇨⇨⇨⇨a←↔↔↔↔↔→b␣c≠d⇦⇦⇔']
   redraw!
   call cursor(1, 1)
   call assert_equal(expected, ScreenLines(1, virtcol('$')))
+
   let &encoding=oldencoding
   enew!
   set listchars& ff&
 endfunction
 
+func Test_listchars_invalid()
+  enew!
+  set ff=unix
+
+  set listchars&
+  set list
+  set ambiwidth=double
+
+  " No colon
+  call assert_fails('set listchars=x', 'E474:')
+  call assert_fails('set listchars=x', 'E474:')
+  call assert_fails('set listchars=multispace', 'E474:')
+
+  " Too short
+  call assert_fails('set listchars=space:', 'E474:')
+  call assert_fails('set listchars=tab:x', 'E474:')
+  call assert_fails('set listchars=multispace:', 'E474:')
+
+  " One occurrence too short
+  call assert_fails('set listchars=space:,space:x', 'E474:')
+  call assert_fails('set listchars=space:x,space:', 'E474:')
+  call assert_fails('set listchars=tab:x,tab:xx', 'E474:')
+  call assert_fails('set listchars=tab:xx,tab:x', 'E474:')
+  call assert_fails('set listchars=multispace:,multispace:x', 'E474:')
+  call assert_fails('set listchars=multispace:x,multispace:', 'E474:')
+
+  " Too long
+  call assert_fails('set listchars=space:xx', 'E474:')
+  call assert_fails('set listchars=tab:xxxx', 'E474:')
+
+  " Has non-single width character
+  call assert_fails('set listchars=space:·', 'E474:')
+  call assert_fails('set listchars=tab:·x', 'E474:')
+  call assert_fails('set listchars=tab:x·', 'E474:')
+  call assert_fails('set listchars=tab:xx·', 'E474:')
+  call assert_fails('set listchars=multispace:·', 'E474:')
+  call assert_fails('set listchars=multispace:xxx·', 'E474:')
+
+  enew!
+  set ambiwidth& listchars& ff&
+endfunction
+
 " Tests that space characters following composing character won't get replaced
 " by listchars.
 func Test_listchars_composing()