Bram Moolenaar | 209d387 | 2017-11-16 21:52:51 +0100 | [diff] [blame] | 1 | " Tests for 'listchars' display with 'list' and :list |
| 2 | |
Bram Moolenaar | 41fb723 | 2021-07-08 12:40:05 +0200 | [diff] [blame] | 3 | source check.vim |
Bram Moolenaar | 209d387 | 2017-11-16 21:52:51 +0100 | [diff] [blame] | 4 | source view_util.vim |
Bram Moolenaar | 41fb723 | 2021-07-08 12:40:05 +0200 | [diff] [blame] | 5 | source screendump.vim |
Bram Moolenaar | 209d387 | 2017-11-16 21:52:51 +0100 | [diff] [blame] | 6 | |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 7 | func Check_listchars(expected, end_lnum, end_scol = -1, leftcol = 0) |
| 8 | if a:leftcol > 0 |
| 9 | let save_wrap = &wrap |
| 10 | set nowrap |
| 11 | call cursor(1, 1) |
| 12 | exe 'normal! ' .. a:leftcol .. 'zl' |
| 13 | endif |
| 14 | |
| 15 | redraw! |
| 16 | for i in range(1, a:end_lnum) |
| 17 | if a:leftcol > 0 |
| 18 | let col = virtcol2col(0, i, a:leftcol) |
| 19 | let col += getline(i)->strpart(col - 1, 1, v:true)->len() |
| 20 | call cursor(i, col) |
| 21 | redraw |
| 22 | call assert_equal(a:leftcol, winsaveview().leftcol) |
| 23 | else |
| 24 | call cursor(i, 1) |
| 25 | end |
| 26 | |
| 27 | let end_scol = a:end_scol < 0 ? '$'->virtcol() - a:leftcol : a:end_scol |
| 28 | call assert_equal([a:expected[i - 1]->strcharpart(a:leftcol)], |
| 29 | \ ScreenLines(i, end_scol)) |
| 30 | endfor |
| 31 | |
| 32 | if a:leftcol > 0 |
| 33 | let &wrap = save_wrap |
| 34 | endif |
| 35 | endfunc |
| 36 | |
Bram Moolenaar | 209d387 | 2017-11-16 21:52:51 +0100 | [diff] [blame] | 37 | func Test_listchars() |
| 38 | enew! |
| 39 | set ff=unix |
| 40 | set list |
| 41 | |
| 42 | set listchars+=tab:>-,space:.,trail:< |
| 43 | call append(0, [ |
| 44 | \ ' aa ', |
| 45 | \ ' bb ', |
| 46 | \ ' cccc ', |
| 47 | \ 'dd ee ', |
| 48 | \ ' ' |
| 49 | \ ]) |
| 50 | let expected = [ |
| 51 | \ '>-------aa>-----$', |
| 52 | \ '..bb>---<<$', |
| 53 | \ '...cccc><$', |
| 54 | \ 'dd........ee<<>-$', |
| 55 | \ '<$' |
| 56 | \ ] |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 57 | call Check_listchars(expected, 5) |
| 58 | call Check_listchars(expected, 4, -1, 5) |
Bram Moolenaar | 209d387 | 2017-11-16 21:52:51 +0100 | [diff] [blame] | 59 | |
| 60 | set listchars-=trail:< |
| 61 | let expected = [ |
| 62 | \ '>-------aa>-----$', |
| 63 | \ '..bb>---..$', |
| 64 | \ '...cccc>.$', |
| 65 | \ 'dd........ee..>-$', |
| 66 | \ '.$' |
| 67 | \ ] |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 68 | call Check_listchars(expected, 5) |
| 69 | call Check_listchars(expected, 4, -1, 5) |
Bram Moolenaar | 209d387 | 2017-11-16 21:52:51 +0100 | [diff] [blame] | 70 | |
Bram Moolenaar | 83a5217 | 2019-01-16 22:41:54 +0100 | [diff] [blame] | 71 | " tab with 3rd character. |
| 72 | set listchars-=tab:>- |
| 73 | set listchars+=tab:<=>,trail:- |
| 74 | let expected = [ |
| 75 | \ '<======>aa<====>$', |
| 76 | \ '..bb<==>--$', |
| 77 | \ '...cccc>-$', |
| 78 | \ 'dd........ee--<>$', |
| 79 | \ '-$' |
| 80 | \ ] |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 81 | call Check_listchars(expected, 5) |
| 82 | call Check_listchars(expected, 4, -1, 5) |
Bram Moolenaar | 83a5217 | 2019-01-16 22:41:54 +0100 | [diff] [blame] | 83 | |
Bram Moolenaar | 69cbbec | 2019-08-17 14:10:56 +0200 | [diff] [blame] | 84 | " tab with 3rd character and linebreak set |
| 85 | set listchars-=tab:<=> |
| 86 | set listchars+=tab:<·> |
| 87 | set linebreak |
| 88 | let expected = [ |
| 89 | \ '<······>aa<····>$', |
| 90 | \ '..bb<··>--$', |
| 91 | \ '...cccc>-$', |
| 92 | \ 'dd........ee--<>$', |
| 93 | \ '-$' |
| 94 | \ ] |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 95 | call Check_listchars(expected, 5) |
Bram Moolenaar | 69cbbec | 2019-08-17 14:10:56 +0200 | [diff] [blame] | 96 | set nolinebreak |
| 97 | set listchars-=tab:<·> |
| 98 | set listchars+=tab:<=> |
| 99 | |
Bram Moolenaar | 83a5217 | 2019-01-16 22:41:54 +0100 | [diff] [blame] | 100 | set listchars-=trail:- |
| 101 | let expected = [ |
| 102 | \ '<======>aa<====>$', |
| 103 | \ '..bb<==>..$', |
| 104 | \ '...cccc>.$', |
| 105 | \ 'dd........ee..<>$', |
| 106 | \ '.$' |
| 107 | \ ] |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 108 | call Check_listchars(expected, 5) |
| 109 | call Check_listchars(expected, 4, -1, 5) |
Bram Moolenaar | 83a5217 | 2019-01-16 22:41:54 +0100 | [diff] [blame] | 110 | |
| 111 | set listchars-=tab:<=> |
| 112 | set listchars+=tab:>- |
Bram Moolenaar | 209d387 | 2017-11-16 21:52:51 +0100 | [diff] [blame] | 113 | set listchars+=trail:< |
| 114 | set nolist |
| 115 | normal ggdG |
| 116 | call append(0, [ |
| 117 | \ ' fff ', |
| 118 | \ ' gg ', |
| 119 | \ ' h ', |
| 120 | \ 'iii ', |
| 121 | \ ]) |
| 122 | let l = split(execute("%list"), "\n") |
| 123 | call assert_equal([ |
| 124 | \ '..fff>--<<$', |
| 125 | \ '>-------gg>-----$', |
| 126 | \ '.....h>-$', |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 127 | \ 'iii<<<<><<$', |
| 128 | \ '$'], l) |
Bram Moolenaar | 209d387 | 2017-11-16 21:52:51 +0100 | [diff] [blame] | 129 | |
Bram Moolenaar | 91478ae | 2021-02-03 15:58:13 +0100 | [diff] [blame] | 130 | " Test lead and trail |
| 131 | normal ggdG |
| 132 | set listchars& |
| 133 | set listchars+=lead:>,trail:<,space:x |
| 134 | set list |
| 135 | |
| 136 | call append(0, [ |
| 137 | \ ' ffff ', |
| 138 | \ ' gg', |
| 139 | \ 'h ', |
| 140 | \ ' ', |
| 141 | \ ' 0 0 ', |
| 142 | \ ]) |
| 143 | |
| 144 | let expected = [ |
| 145 | \ '>>>>ffff<<<<$', |
| 146 | \ '>>>>>>>>>>gg$', |
| 147 | \ 'h<<<<<<<<<<<$', |
| 148 | \ '<<<<<<<<<<<<$', |
| 149 | \ '>>>>0xx0<<<<$', |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 150 | \ '$' |
Bram Moolenaar | 91478ae | 2021-02-03 15:58:13 +0100 | [diff] [blame] | 151 | \ ] |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 152 | call Check_listchars(expected, 6) |
| 153 | call Check_listchars(expected, 5, -1, 6) |
Bram Moolenaar | 91478ae | 2021-02-03 15:58:13 +0100 | [diff] [blame] | 154 | call assert_equal(expected, split(execute("%list"), "\n")) |
Bram Moolenaar | 895d966 | 2019-01-31 21:57:21 +0100 | [diff] [blame] | 155 | |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 156 | " Test multispace |
| 157 | normal ggdG |
| 158 | set listchars& |
| 159 | set listchars+=multispace:yYzZ |
| 160 | set list |
| 161 | |
| 162 | call append(0, [ |
| 163 | \ ' ffff ', |
| 164 | \ ' i i gg', |
| 165 | \ ' h ', |
| 166 | \ ' j ', |
| 167 | \ ' 0 0 ', |
| 168 | \ ]) |
| 169 | |
| 170 | let expected = [ |
| 171 | \ 'yYzZffffyYzZ$', |
| 172 | \ 'yYi iyYzZygg$', |
| 173 | \ ' hyYzZyYzZyY$', |
| 174 | \ 'yYzZyYzZyYj $', |
| 175 | \ 'yYzZ0yY0yYzZ$', |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 176 | \ '$' |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 177 | \ ] |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 178 | call Check_listchars(expected, 6) |
| 179 | call Check_listchars(expected, 5, -1, 6) |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 180 | call assert_equal(expected, split(execute("%list"), "\n")) |
| 181 | |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 182 | " Test leadmultispace + multispace |
| 183 | normal ggdG |
| 184 | set listchars=eol:$,multispace:yYzZ,nbsp:S |
| 185 | set listchars+=leadmultispace:.-+* |
| 186 | set list |
| 187 | |
| 188 | call append(0, [ |
| 189 | \ ' ffff ', |
| 190 | \ ' i i gg', |
| 191 | \ ' h ', |
| 192 | \ ' j ', |
| 193 | \ ' 0 0 ', |
| 194 | \ ]) |
| 195 | |
| 196 | let expected = [ |
| 197 | \ '.-+*ffffyYzZ$', |
| 198 | \ '.-i iSyYzZgg$', |
| 199 | \ ' hyYzZyYzZyY$', |
| 200 | \ '.-+*.-+*.-j $', |
| 201 | \ '.-+*0yY0yYzZ$', |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 202 | \ '$' |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 203 | \ ] |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 204 | call assert_equal('eol:$,multispace:yYzZ,nbsp:S,leadmultispace:.-+*', &listchars) |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 205 | call Check_listchars(expected, 6) |
| 206 | call Check_listchars(expected, 5, -1, 1) |
| 207 | call Check_listchars(expected, 5, -1, 2) |
| 208 | call Check_listchars(expected, 5, -1, 3) |
| 209 | call Check_listchars(expected, 5, -1, 6) |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 210 | call assert_equal(expected, split(execute("%list"), "\n")) |
| 211 | |
| 212 | " Test leadmultispace without multispace |
| 213 | normal ggdG |
| 214 | set listchars-=multispace:yYzZ |
| 215 | set listchars+=space:+,trail:>,eol:$ |
| 216 | set list |
| 217 | |
| 218 | call append(0, [ |
| 219 | \ ' ffff ', |
| 220 | \ ' i i gg', |
| 221 | \ ' h ', |
| 222 | \ ' j ', |
| 223 | \ ' 0 0 ', |
| 224 | \ ]) |
| 225 | |
| 226 | let expected = [ |
| 227 | \ '.-+*ffff>>>>$', |
| 228 | \ '.-i+i+++++gg$', |
| 229 | \ '+h>>>>>>>>>>$', |
| 230 | \ '.-+*.-+*.-j>$', |
| 231 | \ '.-+*0++0>>>>$', |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 232 | \ '$' |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 233 | \ ] |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 234 | call assert_equal('eol:$,nbsp:S,leadmultispace:.-+*,space:+,trail:>,eol:$', &listchars) |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 235 | call Check_listchars(expected, 6) |
| 236 | call Check_listchars(expected, 5, -1, 1) |
| 237 | call Check_listchars(expected, 5, -1, 2) |
| 238 | call Check_listchars(expected, 5, -1, 3) |
| 239 | call Check_listchars(expected, 5, -1, 6) |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 240 | call assert_equal(expected, split(execute("%list"), "\n")) |
| 241 | |
| 242 | " Test leadmultispace only |
| 243 | normal ggdG |
| 244 | set listchars& |
| 245 | set listchars=leadmultispace:.-+* |
| 246 | set list |
| 247 | |
| 248 | call append(0, [ |
| 249 | \ ' ffff ', |
| 250 | \ ' i i gg', |
| 251 | \ ' h ', |
| 252 | \ ' j ', |
| 253 | \ ' 0 0 ', |
| 254 | \ ]) |
| 255 | |
| 256 | let expected = [ |
| 257 | \ '.-+*ffff ', |
| 258 | \ '.-i i gg', |
| 259 | \ ' h ', |
| 260 | \ '.-+*.-+*.-j ', |
| 261 | \ '.-+*0 0 ', |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 262 | \ ' ' |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 263 | \ ] |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 264 | call assert_equal('leadmultispace:.-+*', &listchars) |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 265 | call Check_listchars(expected, 5, 12) |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 266 | call assert_equal(expected, split(execute("%list"), "\n")) |
| 267 | |
| 268 | " Test leadmultispace and lead and space |
| 269 | normal ggdG |
| 270 | set listchars& |
| 271 | set listchars+=lead:<,space:- |
| 272 | set listchars+=leadmultispace:.-+* |
| 273 | set list |
| 274 | |
| 275 | call append(0, [ |
| 276 | \ ' ffff ', |
| 277 | \ ' i i gg', |
| 278 | \ ' h ', |
| 279 | \ ' j ', |
| 280 | \ ' 0 0 ', |
| 281 | \ ]) |
| 282 | |
| 283 | let expected = [ |
| 284 | \ '.-+*ffff----$', |
| 285 | \ '.-i-i-----gg$', |
| 286 | \ '<h----------$', |
| 287 | \ '.-+*.-+*.-j-$', |
| 288 | \ '.-+*0--0----$', |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 289 | \ '$' |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 290 | \ ] |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 291 | call assert_equal('eol:$,lead:<,space:-,leadmultispace:.-+*', &listchars) |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 292 | call Check_listchars(expected, 6) |
| 293 | call Check_listchars(expected, 5, -1, 1) |
| 294 | call Check_listchars(expected, 5, -1, 2) |
| 295 | call Check_listchars(expected, 5, -1, 3) |
| 296 | call Check_listchars(expected, 5, -1, 6) |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 297 | call assert_equal(expected, split(execute("%list"), "\n")) |
| 298 | |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 299 | " the last occurrence of 'multispace:' is used |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 300 | set listchars& |
| 301 | set listchars+=multispace:yYzZ |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 302 | set listchars+=space:x,multispace:XyY |
| 303 | |
| 304 | let expected = [ |
| 305 | \ 'XyYXffffXyYX$', |
| 306 | \ 'XyixiXyYXygg$', |
| 307 | \ 'xhXyYXyYXyYX$', |
| 308 | \ 'XyYXyYXyYXjx$', |
| 309 | \ 'XyYX0Xy0XyYX$', |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 310 | \ '$' |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 311 | \ ] |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 312 | call assert_equal('eol:$,multispace:yYzZ,space:x,multispace:XyY', &listchars) |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 313 | call Check_listchars(expected, 6) |
| 314 | call Check_listchars(expected, 5, -1, 6) |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 315 | call assert_equal(expected, split(execute("%list"), "\n")) |
| 316 | |
| 317 | set listchars+=lead:>,trail:< |
| 318 | |
| 319 | let expected = [ |
| 320 | \ '>>>>ffff<<<<$', |
| 321 | \ '>>ixiXyYXygg$', |
| 322 | \ '>h<<<<<<<<<<$', |
| 323 | \ '>>>>>>>>>>j<$', |
| 324 | \ '>>>>0Xy0<<<<$', |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 325 | \ '$' |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 326 | \ ] |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 327 | call Check_listchars(expected, 6) |
| 328 | call Check_listchars(expected, 5, -1, 6) |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 329 | call assert_equal(expected, split(execute("%list"), "\n")) |
| 330 | |
| 331 | " removing 'multispace:' |
| 332 | set listchars-=multispace:XyY |
| 333 | set listchars-=multispace:yYzZ |
| 334 | |
| 335 | let expected = [ |
| 336 | \ '>>>>ffff<<<<$', |
| 337 | \ '>>ixixxxxxgg$', |
| 338 | \ '>h<<<<<<<<<<$', |
| 339 | \ '>>>>>>>>>>j<$', |
| 340 | \ '>>>>0xx0<<<<$', |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 341 | \ '$' |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 342 | \ ] |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 343 | call Check_listchars(expected, 6) |
| 344 | call Check_listchars(expected, 5, -1, 6) |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 345 | call assert_equal(expected, split(execute("%list"), "\n")) |
| 346 | |
Bram Moolenaar | 895d966 | 2019-01-31 21:57:21 +0100 | [diff] [blame] | 347 | " test nbsp |
| 348 | normal ggdG |
| 349 | set listchars=nbsp:X,trail:Y |
| 350 | set list |
| 351 | " Non-breaking space |
| 352 | let nbsp = nr2char(0xa0) |
Bram Moolenaar | f138728 | 2021-03-22 17:11:15 +0100 | [diff] [blame] | 353 | call append(0, [ ">" .. nbsp .. "<" ]) |
Bram Moolenaar | 895d966 | 2019-01-31 21:57:21 +0100 | [diff] [blame] | 354 | |
| 355 | let expected = '>X< ' |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 356 | call Check_listchars([expected], 1) |
Bram Moolenaar | 895d966 | 2019-01-31 21:57:21 +0100 | [diff] [blame] | 357 | |
| 358 | set listchars=nbsp:X |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 359 | call Check_listchars([expected], 1) |
Bram Moolenaar | 895d966 | 2019-01-31 21:57:21 +0100 | [diff] [blame] | 360 | |
Bram Moolenaar | a5c6a0b | 2019-05-08 20:20:46 +0200 | [diff] [blame] | 361 | " test extends |
| 362 | normal ggdG |
| 363 | set listchars=extends:Z |
| 364 | set nowrap |
| 365 | set nolist |
| 366 | call append(0, [ repeat('A', &columns + 1) ]) |
| 367 | |
| 368 | let expected = repeat('A', &columns) |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 369 | call Check_listchars([expected], 1, &columns) |
Bram Moolenaar | a5c6a0b | 2019-05-08 20:20:46 +0200 | [diff] [blame] | 370 | |
| 371 | set list |
| 372 | let expected = expected[:-2] . 'Z' |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 373 | call Check_listchars([expected], 1, &columns) |
Bram Moolenaar | a5c6a0b | 2019-05-08 20:20:46 +0200 | [diff] [blame] | 374 | |
Bram Moolenaar | 209d387 | 2017-11-16 21:52:51 +0100 | [diff] [blame] | 375 | enew! |
| 376 | set listchars& ff& |
| 377 | endfunc |
Bram Moolenaar | 5f8069b | 2019-03-30 15:34:47 +0100 | [diff] [blame] | 378 | |
Bram Moolenaar | e5e4e22 | 2019-04-04 13:28:45 +0200 | [diff] [blame] | 379 | " Test that unicode listchars characters get properly inserted |
| 380 | func Test_listchars_unicode() |
| 381 | enew! |
| 382 | let oldencoding=&encoding |
| 383 | set encoding=utf-8 |
| 384 | set ff=unix |
| 385 | |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 386 | set listchars=eol:⇔,space:␣,multispace:≡≢≣,nbsp:≠,tab:←↔→ |
Bram Moolenaar | e5e4e22 | 2019-04-04 13:28:45 +0200 | [diff] [blame] | 387 | set list |
| 388 | |
| 389 | let nbsp = nr2char(0xa0) |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 390 | call append(0, [" a\tb c" .. nbsp .. "d "]) |
| 391 | let expected = ['≡≢≣≡≢≣≡≢a←↔↔↔↔↔→b␣c≠d≡≢⇔'] |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 392 | call Check_listchars(expected, 1) |
| 393 | call Check_listchars(expected, 1, -1, 3) |
| 394 | call Check_listchars(expected, 1, -1, 13) |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 395 | |
Bram Moolenaar | 93ff672 | 2021-10-16 17:51:40 +0100 | [diff] [blame] | 396 | set listchars=eol:\\u21d4,space:\\u2423,multispace:≡\\u2262\\U00002263,nbsp:\\U00002260,tab:←↔\\u2192 |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 397 | call Check_listchars(expected, 1) |
| 398 | call Check_listchars(expected, 1, -1, 3) |
| 399 | call Check_listchars(expected, 1, -1, 13) |
Bram Moolenaar | 93ff672 | 2021-10-16 17:51:40 +0100 | [diff] [blame] | 400 | |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 401 | set listchars+=lead:⇨,trail:⇦ |
| 402 | let expected = ['⇨⇨⇨⇨⇨⇨⇨⇨a←↔↔↔↔↔→b␣c≠d⇦⇦⇔'] |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 403 | call Check_listchars(expected, 1) |
| 404 | call Check_listchars(expected, 1, -1, 3) |
| 405 | call Check_listchars(expected, 1, -1, 13) |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 406 | |
Bram Moolenaar | e5e4e22 | 2019-04-04 13:28:45 +0200 | [diff] [blame] | 407 | let &encoding=oldencoding |
| 408 | enew! |
| 409 | set listchars& ff& |
| 410 | endfunction |
| 411 | |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 412 | func Test_listchars_invalid() |
| 413 | enew! |
| 414 | set ff=unix |
| 415 | |
| 416 | set listchars& |
| 417 | set list |
| 418 | set ambiwidth=double |
| 419 | |
| 420 | " No colon |
| 421 | call assert_fails('set listchars=x', 'E474:') |
| 422 | call assert_fails('set listchars=x', 'E474:') |
| 423 | call assert_fails('set listchars=multispace', 'E474:') |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 424 | call assert_fails('set listchars=leadmultispace', 'E474:') |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 425 | |
| 426 | " Too short |
| 427 | call assert_fails('set listchars=space:', 'E474:') |
| 428 | call assert_fails('set listchars=tab:x', 'E474:') |
| 429 | call assert_fails('set listchars=multispace:', 'E474:') |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 430 | call assert_fails('set listchars=leadmultispace:', 'E474:') |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 431 | |
| 432 | " One occurrence too short |
| 433 | call assert_fails('set listchars=space:,space:x', 'E474:') |
| 434 | call assert_fails('set listchars=space:x,space:', 'E474:') |
| 435 | call assert_fails('set listchars=tab:x,tab:xx', 'E474:') |
| 436 | call assert_fails('set listchars=tab:xx,tab:x', 'E474:') |
| 437 | call assert_fails('set listchars=multispace:,multispace:x', 'E474:') |
| 438 | call assert_fails('set listchars=multispace:x,multispace:', 'E474:') |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 439 | call assert_fails('set listchars=leadmultispace:,leadmultispace:x', 'E474:') |
| 440 | call assert_fails('set listchars=leadmultispace:x,leadmultispace:', 'E474:') |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 441 | |
| 442 | " Too long |
| 443 | call assert_fails('set listchars=space:xx', 'E474:') |
| 444 | call assert_fails('set listchars=tab:xxxx', 'E474:') |
| 445 | |
zeertzjq | 60618c8 | 2021-12-18 15:32:46 +0000 | [diff] [blame] | 446 | " Has double-width character |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 447 | call assert_fails('set listchars=space:·', 'E474:') |
| 448 | call assert_fails('set listchars=tab:·x', 'E474:') |
| 449 | call assert_fails('set listchars=tab:x·', 'E474:') |
| 450 | call assert_fails('set listchars=tab:xx·', 'E474:') |
| 451 | call assert_fails('set listchars=multispace:·', 'E474:') |
| 452 | call assert_fails('set listchars=multispace:xxx·', 'E474:') |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 453 | call assert_fails('set listchars=leadmultispace:·', 'E474:') |
| 454 | call assert_fails('set listchars=leadmultispace:xxx·', 'E474:') |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 455 | |
zeertzjq | 60618c8 | 2021-12-18 15:32:46 +0000 | [diff] [blame] | 456 | " Has control character |
| 457 | call assert_fails("set listchars=space:\x01", 'E474:') |
| 458 | call assert_fails("set listchars=tab:\x01x", 'E474:') |
| 459 | call assert_fails("set listchars=tab:x\x01", 'E474:') |
| 460 | call assert_fails("set listchars=tab:xx\x01", 'E474:') |
| 461 | call assert_fails("set listchars=multispace:\x01", 'E474:') |
| 462 | call assert_fails("set listchars=multispace:xxx\x01", 'E474:') |
| 463 | call assert_fails('set listchars=space:\\x01', 'E474:') |
| 464 | call assert_fails('set listchars=tab:\\x01x', 'E474:') |
| 465 | call assert_fails('set listchars=tab:x\\x01', 'E474:') |
| 466 | call assert_fails('set listchars=tab:xx\\x01', 'E474:') |
| 467 | call assert_fails('set listchars=multispace:\\x01', 'E474:') |
| 468 | call assert_fails('set listchars=multispace:xxx\\x01', 'E474:') |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 469 | call assert_fails("set listchars=leadmultispace:\x01", 'E474:') |
| 470 | call assert_fails('set listchars=leadmultispace:\\x01', 'E474:') |
| 471 | call assert_fails("set listchars=leadmultispace:xxx\x01", 'E474:') |
| 472 | call assert_fails('set listchars=leadmultispace:xxx\\x01', 'E474:') |
zeertzjq | 60618c8 | 2021-12-18 15:32:46 +0000 | [diff] [blame] | 473 | |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 474 | enew! |
| 475 | set ambiwidth& listchars& ff& |
| 476 | endfunction |
| 477 | |
Bram Moolenaar | e5e4e22 | 2019-04-04 13:28:45 +0200 | [diff] [blame] | 478 | " Tests that space characters following composing character won't get replaced |
| 479 | " by listchars. |
Bram Moolenaar | 5f8069b | 2019-03-30 15:34:47 +0100 | [diff] [blame] | 480 | func Test_listchars_composing() |
| 481 | enew! |
| 482 | let oldencoding=&encoding |
| 483 | set encoding=utf-8 |
| 484 | set ff=unix |
| 485 | set list |
| 486 | |
Bram Moolenaar | e5e4e22 | 2019-04-04 13:28:45 +0200 | [diff] [blame] | 487 | set listchars=eol:$,space:_,nbsp:= |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 488 | |
Bram Moolenaar | e5e4e22 | 2019-04-04 13:28:45 +0200 | [diff] [blame] | 489 | let nbsp1 = nr2char(0xa0) |
| 490 | let nbsp2 = nr2char(0x202f) |
Bram Moolenaar | 5f8069b | 2019-03-30 15:34:47 +0100 | [diff] [blame] | 491 | call append(0, [ |
Bram Moolenaar | f138728 | 2021-03-22 17:11:15 +0100 | [diff] [blame] | 492 | \ " \u3099\t \u309A" .. nbsp1 .. nbsp1 .. "\u0302" .. nbsp2 .. nbsp2 .. "\u0302", |
Bram Moolenaar | 5f8069b | 2019-03-30 15:34:47 +0100 | [diff] [blame] | 493 | \ ]) |
| 494 | let expected = [ |
Bram Moolenaar | f138728 | 2021-03-22 17:11:15 +0100 | [diff] [blame] | 495 | \ "_ \u3099^I \u309A=" .. nbsp1 .. "\u0302=" .. nbsp2 .. "\u0302$" |
Bram Moolenaar | 5f8069b | 2019-03-30 15:34:47 +0100 | [diff] [blame] | 496 | \ ] |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 497 | call Check_listchars(expected, 1) |
Bram Moolenaar | 5f8069b | 2019-03-30 15:34:47 +0100 | [diff] [blame] | 498 | let &encoding=oldencoding |
Bram Moolenaar | e5e4e22 | 2019-04-04 13:28:45 +0200 | [diff] [blame] | 499 | enew! |
Bram Moolenaar | 5f8069b | 2019-03-30 15:34:47 +0100 | [diff] [blame] | 500 | set listchars& ff& |
| 501 | endfunction |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 502 | |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 503 | " Check for the value of the 'listchars' option |
| 504 | func s:CheckListCharsValue(expected) |
| 505 | call assert_equal(a:expected, &listchars) |
| 506 | call assert_equal(a:expected, getwinvar(0, '&listchars')) |
| 507 | endfunc |
| 508 | |
| 509 | " Test for using a window local value for 'listchars' |
| 510 | func Test_listchars_window_local() |
| 511 | %bw! |
| 512 | set list listchars& |
| 513 | new |
| 514 | " set a local value for 'listchars' |
| 515 | setlocal listchars=tab:+-,eol:# |
| 516 | call s:CheckListCharsValue('tab:+-,eol:#') |
| 517 | " When local value is reset, global value should be used |
| 518 | setlocal listchars= |
| 519 | call s:CheckListCharsValue('eol:$') |
| 520 | " Use 'setlocal <' to copy global value |
| 521 | setlocal listchars=space:.,extends:> |
| 522 | setlocal listchars< |
| 523 | call s:CheckListCharsValue('eol:$') |
| 524 | " Use 'set <' to copy global value |
| 525 | setlocal listchars=space:.,extends:> |
| 526 | set listchars< |
| 527 | call s:CheckListCharsValue('eol:$') |
| 528 | " Changing global setting should not change the local setting |
| 529 | setlocal listchars=space:.,extends:> |
| 530 | setglobal listchars=tab:+-,eol:# |
| 531 | call s:CheckListCharsValue('space:.,extends:>') |
| 532 | " when split opening a new window, local value should be copied |
| 533 | split |
| 534 | call s:CheckListCharsValue('space:.,extends:>') |
| 535 | " clearing local value in one window should not change the other window |
| 536 | set listchars& |
| 537 | call s:CheckListCharsValue('eol:$') |
| 538 | close |
| 539 | call s:CheckListCharsValue('space:.,extends:>') |
| 540 | |
| 541 | " use different values for 'listchars' items in two different windows |
| 542 | call setline(1, ["\t one two "]) |
| 543 | setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:# |
| 544 | split |
| 545 | setlocal listchars=tab:[.],lead:#,space:_,trail:.,eol:& |
| 546 | split |
| 547 | set listchars=tab:+-+,lead:^,space:>,trail:<,eol:% |
| 548 | call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$'))) |
| 549 | close |
| 550 | call assert_equal(['[......]##one__two..&'], ScreenLines(1, virtcol('$'))) |
| 551 | close |
| 552 | call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$'))) |
| 553 | " changing the global setting should not change the local value |
| 554 | setglobal listchars=tab:[.],lead:#,space:_,trail:.,eol:& |
| 555 | call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$'))) |
| 556 | set listchars< |
| 557 | call assert_equal(['[......]##one__two..&'], ScreenLines(1, virtcol('$'))) |
| 558 | |
| 559 | " Using setglobal in a window with local setting should not affect the |
| 560 | " window. But should impact other windows using the global setting. |
| 561 | enew! | only |
| 562 | call setline(1, ["\t one two "]) |
| 563 | set listchars=tab:[.],lead:#,space:_,trail:.,eol:& |
| 564 | split |
| 565 | setlocal listchars=tab:+-+,lead:^,space:>,trail:<,eol:% |
| 566 | split |
| 567 | setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:# |
| 568 | setglobal listchars=tab:{.},lead:-,space:=,trail:#,eol:$ |
| 569 | call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$'))) |
| 570 | close |
| 571 | call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$'))) |
| 572 | close |
| 573 | call assert_equal(['{......}--one==two##$'], ScreenLines(1, virtcol('$'))) |
| 574 | |
| 575 | " Setting the global setting to the default value should not impact a window |
zeertzjq | 7a33ebf | 2021-11-02 20:56:07 +0000 | [diff] [blame] | 576 | " using a local setting. |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 577 | split |
| 578 | setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:# |
| 579 | setglobal listchars&vim |
| 580 | call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$'))) |
| 581 | close |
| 582 | call assert_equal(['^I one two $'], ScreenLines(1, virtcol('$'))) |
| 583 | |
| 584 | " Setting the local setting to the default value should not impact a window |
zeertzjq | 7a33ebf | 2021-11-02 20:56:07 +0000 | [diff] [blame] | 585 | " using a global setting. |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 586 | set listchars=tab:{.},lead:-,space:=,trail:#,eol:$ |
| 587 | split |
| 588 | setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:# |
| 589 | call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$'))) |
| 590 | setlocal listchars&vim |
| 591 | call assert_equal(['^I one two $'], ScreenLines(1, virtcol('$'))) |
| 592 | close |
| 593 | call assert_equal(['{......}--one==two##$'], ScreenLines(1, virtcol('$'))) |
| 594 | |
| 595 | " Using set in a window with a local setting should change it to use the |
zeertzjq | 7a33ebf | 2021-11-02 20:56:07 +0000 | [diff] [blame] | 596 | " global setting and also impact other windows using the global setting. |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 597 | split |
| 598 | setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:# |
| 599 | call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$'))) |
| 600 | set listchars=tab:+-+,lead:^,space:>,trail:<,eol:% |
| 601 | call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$'))) |
| 602 | close |
| 603 | call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$'))) |
| 604 | |
Bram Moolenaar | 04ea7e9 | 2021-02-16 21:14:33 +0100 | [diff] [blame] | 605 | " Setting invalid value for a local setting should not impact the local and |
zeertzjq | 7a33ebf | 2021-11-02 20:56:07 +0000 | [diff] [blame] | 606 | " global settings. |
Bram Moolenaar | 04ea7e9 | 2021-02-16 21:14:33 +0100 | [diff] [blame] | 607 | split |
| 608 | setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:# |
| 609 | let cmd = 'setlocal listchars=tab:{.},lead:-,space:=,trail:#,eol:$,x' |
| 610 | call assert_fails(cmd, 'E474:') |
| 611 | call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$'))) |
| 612 | close |
| 613 | call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$'))) |
| 614 | |
| 615 | " Setting invalid value for a global setting should not impact the local and |
zeertzjq | 7a33ebf | 2021-11-02 20:56:07 +0000 | [diff] [blame] | 616 | " global settings. |
Bram Moolenaar | 04ea7e9 | 2021-02-16 21:14:33 +0100 | [diff] [blame] | 617 | split |
| 618 | setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:# |
| 619 | let cmd = 'setglobal listchars=tab:{.},lead:-,space:=,trail:#,eol:$,x' |
| 620 | call assert_fails(cmd, 'E474:') |
| 621 | call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$'))) |
| 622 | close |
| 623 | call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$'))) |
| 624 | |
zeertzjq | 7a33ebf | 2021-11-02 20:56:07 +0000 | [diff] [blame] | 625 | " Closing window with local lcs-multispace should not cause a memory leak. |
| 626 | setlocal listchars=multispace:---+ |
| 627 | split |
| 628 | call s:CheckListCharsValue('multispace:---+') |
| 629 | close |
| 630 | |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 631 | %bw! |
| 632 | set list& listchars& |
| 633 | endfunc |
| 634 | |
Bram Moolenaar | 41fb723 | 2021-07-08 12:40:05 +0200 | [diff] [blame] | 635 | func Test_listchars_foldcolumn() |
| 636 | CheckScreendump |
| 637 | |
| 638 | let lines =<< trim END |
| 639 | call setline(1, ['aaa', '', 'a', 'aaaaaa']) |
| 640 | vsplit |
| 641 | vsplit |
| 642 | windo set signcolumn=yes foldcolumn=1 winminwidth=0 nowrap list listchars=extends:>,precedes:< |
| 643 | END |
Bram Moolenaar | 7dd5a78 | 2022-09-29 21:01:57 +0100 | [diff] [blame] | 644 | call writefile(lines, 'XTest_listchars', 'D') |
Bram Moolenaar | 41fb723 | 2021-07-08 12:40:05 +0200 | [diff] [blame] | 645 | |
| 646 | let buf = RunVimInTerminal('-S XTest_listchars', {'rows': 10, 'cols': 60}) |
| 647 | |
| 648 | call term_sendkeys(buf, "13\<C-W>>") |
| 649 | call VerifyScreenDump(buf, 'Test_listchars_01', {}) |
| 650 | call term_sendkeys(buf, "\<C-W>>") |
| 651 | call VerifyScreenDump(buf, 'Test_listchars_02', {}) |
| 652 | call term_sendkeys(buf, "\<C-W>>") |
| 653 | call VerifyScreenDump(buf, 'Test_listchars_03', {}) |
| 654 | call term_sendkeys(buf, "\<C-W>>") |
| 655 | call VerifyScreenDump(buf, 'Test_listchars_04', {}) |
| 656 | call term_sendkeys(buf, "\<C-W>>") |
| 657 | call VerifyScreenDump(buf, 'Test_listchars_05', {}) |
Bram Moolenaar | 30441bb | 2021-07-08 13:19:31 +0200 | [diff] [blame] | 658 | call term_sendkeys(buf, "\<C-W>h") |
| 659 | call term_sendkeys(buf, ":set nowrap foldcolumn=4\<CR>") |
| 660 | call term_sendkeys(buf, "15\<C-W><") |
| 661 | call VerifyScreenDump(buf, 'Test_listchars_06', {}) |
| 662 | call term_sendkeys(buf, "4\<C-W><") |
| 663 | call VerifyScreenDump(buf, 'Test_listchars_07', {}) |
Bram Moolenaar | 41fb723 | 2021-07-08 12:40:05 +0200 | [diff] [blame] | 664 | |
| 665 | " clean up |
| 666 | call StopVimInTerminal(buf) |
Bram Moolenaar | 41fb723 | 2021-07-08 12:40:05 +0200 | [diff] [blame] | 667 | endfunc |
| 668 | |
| 669 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 670 | " vim: shiftwidth=2 sts=2 expandtab |