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 set listchars-=trail:- 62 let expected = [ 63 \ '<======>aa<====>$', 64 \ '..bb<==>..$', 65 \ '...cccc>.$', 66 \ 'dd........ee..<>$', 67 \ '.$' 68 \ ] 69 redraw! 70 for i in range(1, 5) 71 call cursor(i, 1) 72 call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$'))) 73 endfor 74 75 set listchars-=tab:<=> 76 set listchars+=tab:>- 77 set listchars+=trail:< 78 set nolist 79 normal ggdG 80 call append(0, [ 81 \ ' fff ', 82 \ ' gg ', 83 \ ' h ', 84 \ 'iii ', 85 \ ]) 86 let l = split(execute("%list"), "\n") 87 call assert_equal([ 88 \ '..fff>--<<$', 89 \ '>-------gg>-----$', 90 \ '.....h>-$', 91 \ 'iii<<<<><<$', '$'], l) 92 93 94 " test nbsp 95 normal ggdG 96 set listchars=nbsp:X,trail:Y 97 set list 98 " Non-breaking space 99 let nbsp = nr2char(0xa0) 100 call append(0, [ ">".nbsp."<" ]) 101 102 let expected = '>X< ' 103 104 redraw! 105 call cursor(1, 1) 106 call assert_equal([expected], ScreenLines(1, virtcol('$'))) 107 108 set listchars=nbsp:X 109 redraw! 110 call cursor(1, 1) 111 call assert_equal([expected], ScreenLines(1, virtcol('$'))) 112 113 " test extends 114 normal ggdG 115 set listchars=extends:Z 116 set nowrap 117 set nolist 118 call append(0, [ repeat('A', &columns + 1) ]) 119 120 let expected = repeat('A', &columns) 121 122 redraw! 123 call cursor(1, 1) 124 call assert_equal([expected], ScreenLines(1, &columns)) 125 126 set list 127 let expected = expected[:-2] . 'Z' 128 redraw! 129 call cursor(1, 1) 130 call assert_equal([expected], ScreenLines(1, &columns)) 131 132 enew! 133 set listchars& ff& 134endfunc 135 136" Test that unicode listchars characters get properly inserted 137func Test_listchars_unicode() 138 enew! 139 let oldencoding=&encoding 140 set encoding=utf-8 141 set ff=unix 142 143 set listchars=eol:⇔,space:␣,nbsp:≠,tab:←↔→ 144 set list 145 146 let nbsp = nr2char(0xa0) 147 call append(0, [ 148 \ "a\tb c".nbsp."d" 149 \ ]) 150 let expected = [ 151 \ 'a←↔↔↔↔↔→b␣c≠d⇔' 152 \ ] 153 redraw! 154 call cursor(1, 1) 155 call assert_equal(expected, ScreenLines(1, virtcol('$'))) 156 let &encoding=oldencoding 157 enew! 158 set listchars& ff& 159endfunction 160 161" Tests that space characters following composing character won't get replaced 162" by listchars. 163func Test_listchars_composing() 164 enew! 165 let oldencoding=&encoding 166 set encoding=utf-8 167 set ff=unix 168 set list 169 170 set listchars=eol:$,space:_,nbsp:= 171 172 let nbsp1 = nr2char(0xa0) 173 let nbsp2 = nr2char(0x202f) 174 call append(0, [ 175 \ " \u3099\t \u309A".nbsp1.nbsp1."\u0302".nbsp2.nbsp2."\u0302", 176 \ ]) 177 let expected = [ 178 \ "_ \u3099^I \u309A=".nbsp1."\u0302=".nbsp2."\u0302$" 179 \ ] 180 redraw! 181 call cursor(1, 1) 182 call assert_equal(expected, ScreenLines(1, virtcol('$'))) 183 let &encoding=oldencoding 184 enew! 185 set listchars& ff& 186endfunction 187