1" 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) 28 call assert_equal([expected[i - 1]], ScreenLines(i, '$'->virtcol())) 29 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 45 " 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 61 " 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 81 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:>- 97 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 113 114 " test nbsp 115 normal ggdG 116 set listchars=nbsp:X,trail:Y 117 set list 118 " Non-breaking space 119 let nbsp = nr2char(0xa0) 120 call append(0, [ ">".nbsp."<" ]) 121 122 let expected = '>X< ' 123 124 redraw! 125 call cursor(1, 1) 126 call assert_equal([expected], ScreenLines(1, virtcol('$'))) 127 128 set listchars=nbsp:X 129 redraw! 130 call cursor(1, 1) 131 call assert_equal([expected], ScreenLines(1, virtcol('$'))) 132 133 " test extends 134 normal ggdG 135 set listchars=extends:Z 136 set nowrap 137 set nolist 138 call append(0, [ repeat('A', &columns + 1) ]) 139 140 let expected = repeat('A', &columns) 141 142 redraw! 143 call cursor(1, 1) 144 call assert_equal([expected], ScreenLines(1, &columns)) 145 146 set list 147 let expected = expected[:-2] . 'Z' 148 redraw! 149 call cursor(1, 1) 150 call assert_equal([expected], ScreenLines(1, &columns)) 151 152 enew! 153 set listchars& ff& 154endfunc 155 156" Test that unicode listchars characters get properly inserted 157func Test_listchars_unicode() 158 enew! 159 let oldencoding=&encoding 160 set encoding=utf-8 161 set ff=unix 162 163 set listchars=eol:⇔,space:␣,nbsp:≠,tab:←↔→ 164 set list 165 166 let nbsp = nr2char(0xa0) 167 call append(0, [ 168 \ "a\tb c".nbsp."d" 169 \ ]) 170 let expected = [ 171 \ 'a←↔↔↔↔↔→b␣c≠d⇔' 172 \ ] 173 redraw! 174 call cursor(1, 1) 175 call assert_equal(expected, ScreenLines(1, virtcol('$'))) 176 let &encoding=oldencoding 177 enew! 178 set listchars& ff& 179endfunction 180 181" Tests that space characters following composing character won't get replaced 182" by listchars. 183func Test_listchars_composing() 184 enew! 185 let oldencoding=&encoding 186 set encoding=utf-8 187 set ff=unix 188 set list 189 190 set listchars=eol:$,space:_,nbsp:= 191 192 let nbsp1 = nr2char(0xa0) 193 let nbsp2 = nr2char(0x202f) 194 call append(0, [ 195 \ " \u3099\t \u309A".nbsp1.nbsp1."\u0302".nbsp2.nbsp2."\u0302", 196 \ ]) 197 let expected = [ 198 \ "_ \u3099^I \u309A=".nbsp1."\u0302=".nbsp2."\u0302$" 199 \ ] 200 redraw! 201 call cursor(1, 1) 202 call assert_equal(expected, ScreenLines(1, virtcol('$'))) 203 let &encoding=oldencoding 204 enew! 205 set listchars& ff& 206endfunction 207