Bram Moolenaar | 209d387 | 2017-11-16 21:52:51 +0100 | [diff] [blame] | 1 | " Tests for 'listchars' display with 'list' and :list |
| 2 | |
| 3 | source view_util.vim |
| 4 | |
| 5 | func 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 Moolenaar | f92e58c | 2019-09-08 21:51:41 +0200 | [diff] [blame^] | 28 | call assert_equal([expected[i - 1]], ScreenLines(i, '$'->virtcol())) |
Bram Moolenaar | 209d387 | 2017-11-16 21:52:51 +0100 | [diff] [blame] | 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 | |
Bram Moolenaar | 83a5217 | 2019-01-16 22:41:54 +0100 | [diff] [blame] | 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 | |
Bram Moolenaar | 69cbbec | 2019-08-17 14:10:56 +0200 | [diff] [blame] | 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 | |
Bram Moolenaar | 83a5217 | 2019-01-16 22:41:54 +0100 | [diff] [blame] | 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:>- |
Bram Moolenaar | 209d387 | 2017-11-16 21:52:51 +0100 | [diff] [blame] | 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 | |
Bram Moolenaar | 895d966 | 2019-01-31 21:57:21 +0100 | [diff] [blame] | 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 | |
Bram Moolenaar | a5c6a0b | 2019-05-08 20:20:46 +0200 | [diff] [blame] | 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 | |
Bram Moolenaar | 209d387 | 2017-11-16 21:52:51 +0100 | [diff] [blame] | 152 | enew! |
| 153 | set listchars& ff& |
| 154 | endfunc |
Bram Moolenaar | 5f8069b | 2019-03-30 15:34:47 +0100 | [diff] [blame] | 155 | |
Bram Moolenaar | e5e4e22 | 2019-04-04 13:28:45 +0200 | [diff] [blame] | 156 | " Test that unicode listchars characters get properly inserted |
| 157 | func 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& |
| 179 | endfunction |
| 180 | |
| 181 | " Tests that space characters following composing character won't get replaced |
| 182 | " by listchars. |
Bram Moolenaar | 5f8069b | 2019-03-30 15:34:47 +0100 | [diff] [blame] | 183 | func Test_listchars_composing() |
| 184 | enew! |
| 185 | let oldencoding=&encoding |
| 186 | set encoding=utf-8 |
| 187 | set ff=unix |
| 188 | set list |
| 189 | |
Bram Moolenaar | e5e4e22 | 2019-04-04 13:28:45 +0200 | [diff] [blame] | 190 | set listchars=eol:$,space:_,nbsp:= |
| 191 | |
| 192 | let nbsp1 = nr2char(0xa0) |
| 193 | let nbsp2 = nr2char(0x202f) |
Bram Moolenaar | 5f8069b | 2019-03-30 15:34:47 +0100 | [diff] [blame] | 194 | call append(0, [ |
Bram Moolenaar | e5e4e22 | 2019-04-04 13:28:45 +0200 | [diff] [blame] | 195 | \ " \u3099\t \u309A".nbsp1.nbsp1."\u0302".nbsp2.nbsp2."\u0302", |
Bram Moolenaar | 5f8069b | 2019-03-30 15:34:47 +0100 | [diff] [blame] | 196 | \ ]) |
| 197 | let expected = [ |
Bram Moolenaar | e5e4e22 | 2019-04-04 13:28:45 +0200 | [diff] [blame] | 198 | \ "_ \u3099^I \u309A=".nbsp1."\u0302=".nbsp2."\u0302$" |
Bram Moolenaar | 5f8069b | 2019-03-30 15:34:47 +0100 | [diff] [blame] | 199 | \ ] |
| 200 | redraw! |
| 201 | call cursor(1, 1) |
Bram Moolenaar | e5e4e22 | 2019-04-04 13:28:45 +0200 | [diff] [blame] | 202 | call assert_equal(expected, ScreenLines(1, virtcol('$'))) |
Bram Moolenaar | 5f8069b | 2019-03-30 15:34:47 +0100 | [diff] [blame] | 203 | let &encoding=oldencoding |
Bram Moolenaar | e5e4e22 | 2019-04-04 13:28:45 +0200 | [diff] [blame] | 204 | enew! |
Bram Moolenaar | 5f8069b | 2019-03-30 15:34:47 +0100 | [diff] [blame] | 205 | set listchars& ff& |
| 206 | endfunction |