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 | |
| 7 | func Test_listchars() |
| 8 | enew! |
| 9 | set ff=unix |
| 10 | set list |
| 11 | |
| 12 | set listchars+=tab:>-,space:.,trail:< |
| 13 | call append(0, [ |
| 14 | \ ' aa ', |
| 15 | \ ' bb ', |
| 16 | \ ' cccc ', |
| 17 | \ 'dd ee ', |
| 18 | \ ' ' |
| 19 | \ ]) |
| 20 | let expected = [ |
| 21 | \ '>-------aa>-----$', |
| 22 | \ '..bb>---<<$', |
| 23 | \ '...cccc><$', |
| 24 | \ 'dd........ee<<>-$', |
| 25 | \ '<$' |
| 26 | \ ] |
| 27 | redraw! |
| 28 | for i in range(1, 5) |
| 29 | call cursor(i, 1) |
Bram Moolenaar | f92e58c | 2019-09-08 21:51:41 +0200 | [diff] [blame] | 30 | call assert_equal([expected[i - 1]], ScreenLines(i, '$'->virtcol())) |
Bram Moolenaar | 209d387 | 2017-11-16 21:52:51 +0100 | [diff] [blame] | 31 | endfor |
| 32 | |
| 33 | set listchars-=trail:< |
| 34 | let expected = [ |
| 35 | \ '>-------aa>-----$', |
| 36 | \ '..bb>---..$', |
| 37 | \ '...cccc>.$', |
| 38 | \ 'dd........ee..>-$', |
| 39 | \ '.$' |
| 40 | \ ] |
| 41 | redraw! |
| 42 | for i in range(1, 5) |
| 43 | call cursor(i, 1) |
| 44 | call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$'))) |
| 45 | endfor |
| 46 | |
Bram Moolenaar | 83a5217 | 2019-01-16 22:41:54 +0100 | [diff] [blame] | 47 | " tab with 3rd character. |
| 48 | set listchars-=tab:>- |
| 49 | set listchars+=tab:<=>,trail:- |
| 50 | let expected = [ |
| 51 | \ '<======>aa<====>$', |
| 52 | \ '..bb<==>--$', |
| 53 | \ '...cccc>-$', |
| 54 | \ 'dd........ee--<>$', |
| 55 | \ '-$' |
| 56 | \ ] |
| 57 | redraw! |
| 58 | for i in range(1, 5) |
| 59 | call cursor(i, 1) |
| 60 | call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$'))) |
| 61 | endfor |
| 62 | |
Bram Moolenaar | 69cbbec | 2019-08-17 14:10:56 +0200 | [diff] [blame] | 63 | " tab with 3rd character and linebreak set |
| 64 | set listchars-=tab:<=> |
| 65 | set listchars+=tab:<·> |
| 66 | set linebreak |
| 67 | let expected = [ |
| 68 | \ '<······>aa<····>$', |
| 69 | \ '..bb<··>--$', |
| 70 | \ '...cccc>-$', |
| 71 | \ 'dd........ee--<>$', |
| 72 | \ '-$' |
| 73 | \ ] |
| 74 | redraw! |
| 75 | for i in range(1, 5) |
| 76 | call cursor(i, 1) |
| 77 | call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$'))) |
| 78 | endfor |
| 79 | set nolinebreak |
| 80 | set listchars-=tab:<·> |
| 81 | set listchars+=tab:<=> |
| 82 | |
Bram Moolenaar | 83a5217 | 2019-01-16 22:41:54 +0100 | [diff] [blame] | 83 | set listchars-=trail:- |
| 84 | let expected = [ |
| 85 | \ '<======>aa<====>$', |
| 86 | \ '..bb<==>..$', |
| 87 | \ '...cccc>.$', |
| 88 | \ 'dd........ee..<>$', |
| 89 | \ '.$' |
| 90 | \ ] |
| 91 | redraw! |
| 92 | for i in range(1, 5) |
| 93 | call cursor(i, 1) |
| 94 | call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$'))) |
| 95 | endfor |
| 96 | |
| 97 | set listchars-=tab:<=> |
| 98 | set listchars+=tab:>- |
Bram Moolenaar | 209d387 | 2017-11-16 21:52:51 +0100 | [diff] [blame] | 99 | set listchars+=trail:< |
| 100 | set nolist |
| 101 | normal ggdG |
| 102 | call append(0, [ |
| 103 | \ ' fff ', |
| 104 | \ ' gg ', |
| 105 | \ ' h ', |
| 106 | \ 'iii ', |
| 107 | \ ]) |
| 108 | let l = split(execute("%list"), "\n") |
| 109 | call assert_equal([ |
| 110 | \ '..fff>--<<$', |
| 111 | \ '>-------gg>-----$', |
| 112 | \ '.....h>-$', |
| 113 | \ 'iii<<<<><<$', '$'], l) |
| 114 | |
Bram Moolenaar | 91478ae | 2021-02-03 15:58:13 +0100 | [diff] [blame] | 115 | " Test lead and trail |
| 116 | normal ggdG |
| 117 | set listchars& |
| 118 | set listchars+=lead:>,trail:<,space:x |
| 119 | set list |
| 120 | |
| 121 | call append(0, [ |
| 122 | \ ' ffff ', |
| 123 | \ ' gg', |
| 124 | \ 'h ', |
| 125 | \ ' ', |
| 126 | \ ' 0 0 ', |
| 127 | \ ]) |
| 128 | |
| 129 | let expected = [ |
| 130 | \ '>>>>ffff<<<<$', |
| 131 | \ '>>>>>>>>>>gg$', |
| 132 | \ 'h<<<<<<<<<<<$', |
| 133 | \ '<<<<<<<<<<<<$', |
| 134 | \ '>>>>0xx0<<<<$', |
| 135 | \ '$' |
| 136 | \ ] |
| 137 | redraw! |
| 138 | for i in range(1, 5) |
| 139 | call cursor(i, 1) |
| 140 | call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$'))) |
| 141 | endfor |
| 142 | |
| 143 | call assert_equal(expected, split(execute("%list"), "\n")) |
Bram Moolenaar | 895d966 | 2019-01-31 21:57:21 +0100 | [diff] [blame] | 144 | |
| 145 | " test nbsp |
| 146 | normal ggdG |
| 147 | set listchars=nbsp:X,trail:Y |
| 148 | set list |
| 149 | " Non-breaking space |
| 150 | let nbsp = nr2char(0xa0) |
Bram Moolenaar | f138728 | 2021-03-22 17:11:15 +0100 | [diff] [blame] | 151 | call append(0, [ ">" .. nbsp .. "<" ]) |
Bram Moolenaar | 895d966 | 2019-01-31 21:57:21 +0100 | [diff] [blame] | 152 | |
| 153 | let expected = '>X< ' |
| 154 | |
| 155 | redraw! |
| 156 | call cursor(1, 1) |
| 157 | call assert_equal([expected], ScreenLines(1, virtcol('$'))) |
| 158 | |
| 159 | set listchars=nbsp:X |
| 160 | redraw! |
| 161 | call cursor(1, 1) |
| 162 | call assert_equal([expected], ScreenLines(1, virtcol('$'))) |
| 163 | |
Bram Moolenaar | a5c6a0b | 2019-05-08 20:20:46 +0200 | [diff] [blame] | 164 | " test extends |
| 165 | normal ggdG |
| 166 | set listchars=extends:Z |
| 167 | set nowrap |
| 168 | set nolist |
| 169 | call append(0, [ repeat('A', &columns + 1) ]) |
| 170 | |
| 171 | let expected = repeat('A', &columns) |
| 172 | |
| 173 | redraw! |
| 174 | call cursor(1, 1) |
| 175 | call assert_equal([expected], ScreenLines(1, &columns)) |
| 176 | |
| 177 | set list |
| 178 | let expected = expected[:-2] . 'Z' |
| 179 | redraw! |
| 180 | call cursor(1, 1) |
| 181 | call assert_equal([expected], ScreenLines(1, &columns)) |
| 182 | |
Bram Moolenaar | 209d387 | 2017-11-16 21:52:51 +0100 | [diff] [blame] | 183 | enew! |
| 184 | set listchars& ff& |
| 185 | endfunc |
Bram Moolenaar | 5f8069b | 2019-03-30 15:34:47 +0100 | [diff] [blame] | 186 | |
Bram Moolenaar | e5e4e22 | 2019-04-04 13:28:45 +0200 | [diff] [blame] | 187 | " Test that unicode listchars characters get properly inserted |
| 188 | func Test_listchars_unicode() |
| 189 | enew! |
| 190 | let oldencoding=&encoding |
| 191 | set encoding=utf-8 |
| 192 | set ff=unix |
| 193 | |
| 194 | set listchars=eol:⇔,space:␣,nbsp:≠,tab:←↔→ |
| 195 | set list |
| 196 | |
| 197 | let nbsp = nr2char(0xa0) |
Bram Moolenaar | f138728 | 2021-03-22 17:11:15 +0100 | [diff] [blame] | 198 | call append(0, ["a\tb c" .. nbsp .. "d"]) |
| 199 | let expected = ['a←↔↔↔↔↔→b␣c≠d⇔'] |
Bram Moolenaar | e5e4e22 | 2019-04-04 13:28:45 +0200 | [diff] [blame] | 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& |
| 206 | endfunction |
| 207 | |
| 208 | " Tests that space characters following composing character won't get replaced |
| 209 | " by listchars. |
Bram Moolenaar | 5f8069b | 2019-03-30 15:34:47 +0100 | [diff] [blame] | 210 | func Test_listchars_composing() |
| 211 | enew! |
| 212 | let oldencoding=&encoding |
| 213 | set encoding=utf-8 |
| 214 | set ff=unix |
| 215 | set list |
| 216 | |
Bram Moolenaar | e5e4e22 | 2019-04-04 13:28:45 +0200 | [diff] [blame] | 217 | set listchars=eol:$,space:_,nbsp:= |
| 218 | |
| 219 | let nbsp1 = nr2char(0xa0) |
| 220 | let nbsp2 = nr2char(0x202f) |
Bram Moolenaar | 5f8069b | 2019-03-30 15:34:47 +0100 | [diff] [blame] | 221 | call append(0, [ |
Bram Moolenaar | f138728 | 2021-03-22 17:11:15 +0100 | [diff] [blame] | 222 | \ " \u3099\t \u309A" .. nbsp1 .. nbsp1 .. "\u0302" .. nbsp2 .. nbsp2 .. "\u0302", |
Bram Moolenaar | 5f8069b | 2019-03-30 15:34:47 +0100 | [diff] [blame] | 223 | \ ]) |
| 224 | let expected = [ |
Bram Moolenaar | f138728 | 2021-03-22 17:11:15 +0100 | [diff] [blame] | 225 | \ "_ \u3099^I \u309A=" .. nbsp1 .. "\u0302=" .. nbsp2 .. "\u0302$" |
Bram Moolenaar | 5f8069b | 2019-03-30 15:34:47 +0100 | [diff] [blame] | 226 | \ ] |
| 227 | redraw! |
| 228 | call cursor(1, 1) |
Bram Moolenaar | e5e4e22 | 2019-04-04 13:28:45 +0200 | [diff] [blame] | 229 | call assert_equal(expected, ScreenLines(1, virtcol('$'))) |
Bram Moolenaar | 5f8069b | 2019-03-30 15:34:47 +0100 | [diff] [blame] | 230 | let &encoding=oldencoding |
Bram Moolenaar | e5e4e22 | 2019-04-04 13:28:45 +0200 | [diff] [blame] | 231 | enew! |
Bram Moolenaar | 5f8069b | 2019-03-30 15:34:47 +0100 | [diff] [blame] | 232 | set listchars& ff& |
| 233 | endfunction |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 234 | |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 235 | " Check for the value of the 'listchars' option |
| 236 | func s:CheckListCharsValue(expected) |
| 237 | call assert_equal(a:expected, &listchars) |
| 238 | call assert_equal(a:expected, getwinvar(0, '&listchars')) |
| 239 | endfunc |
| 240 | |
| 241 | " Test for using a window local value for 'listchars' |
| 242 | func Test_listchars_window_local() |
| 243 | %bw! |
| 244 | set list listchars& |
| 245 | new |
| 246 | " set a local value for 'listchars' |
| 247 | setlocal listchars=tab:+-,eol:# |
| 248 | call s:CheckListCharsValue('tab:+-,eol:#') |
| 249 | " When local value is reset, global value should be used |
| 250 | setlocal listchars= |
| 251 | call s:CheckListCharsValue('eol:$') |
| 252 | " Use 'setlocal <' to copy global value |
| 253 | setlocal listchars=space:.,extends:> |
| 254 | setlocal listchars< |
| 255 | call s:CheckListCharsValue('eol:$') |
| 256 | " Use 'set <' to copy global value |
| 257 | setlocal listchars=space:.,extends:> |
| 258 | set listchars< |
| 259 | call s:CheckListCharsValue('eol:$') |
| 260 | " Changing global setting should not change the local setting |
| 261 | setlocal listchars=space:.,extends:> |
| 262 | setglobal listchars=tab:+-,eol:# |
| 263 | call s:CheckListCharsValue('space:.,extends:>') |
| 264 | " when split opening a new window, local value should be copied |
| 265 | split |
| 266 | call s:CheckListCharsValue('space:.,extends:>') |
| 267 | " clearing local value in one window should not change the other window |
| 268 | set listchars& |
| 269 | call s:CheckListCharsValue('eol:$') |
| 270 | close |
| 271 | call s:CheckListCharsValue('space:.,extends:>') |
| 272 | |
| 273 | " use different values for 'listchars' items in two different windows |
| 274 | call setline(1, ["\t one two "]) |
| 275 | setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:# |
| 276 | split |
| 277 | setlocal listchars=tab:[.],lead:#,space:_,trail:.,eol:& |
| 278 | split |
| 279 | set listchars=tab:+-+,lead:^,space:>,trail:<,eol:% |
| 280 | call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$'))) |
| 281 | close |
| 282 | call assert_equal(['[......]##one__two..&'], ScreenLines(1, virtcol('$'))) |
| 283 | close |
| 284 | call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$'))) |
| 285 | " changing the global setting should not change the local value |
| 286 | setglobal listchars=tab:[.],lead:#,space:_,trail:.,eol:& |
| 287 | call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$'))) |
| 288 | set listchars< |
| 289 | call assert_equal(['[......]##one__two..&'], ScreenLines(1, virtcol('$'))) |
| 290 | |
| 291 | " Using setglobal in a window with local setting should not affect the |
| 292 | " window. But should impact other windows using the global setting. |
| 293 | enew! | only |
| 294 | call setline(1, ["\t one two "]) |
| 295 | set listchars=tab:[.],lead:#,space:_,trail:.,eol:& |
| 296 | split |
| 297 | setlocal listchars=tab:+-+,lead:^,space:>,trail:<,eol:% |
| 298 | split |
| 299 | setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:# |
| 300 | setglobal listchars=tab:{.},lead:-,space:=,trail:#,eol:$ |
| 301 | call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$'))) |
| 302 | close |
| 303 | call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$'))) |
| 304 | close |
| 305 | call assert_equal(['{......}--one==two##$'], ScreenLines(1, virtcol('$'))) |
| 306 | |
| 307 | " Setting the global setting to the default value should not impact a window |
| 308 | " using a local setting |
| 309 | split |
| 310 | setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:# |
| 311 | setglobal listchars&vim |
| 312 | call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$'))) |
| 313 | close |
| 314 | call assert_equal(['^I one two $'], ScreenLines(1, virtcol('$'))) |
| 315 | |
| 316 | " Setting the local setting to the default value should not impact a window |
| 317 | " using a global setting |
| 318 | set listchars=tab:{.},lead:-,space:=,trail:#,eol:$ |
| 319 | split |
| 320 | setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:# |
| 321 | call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$'))) |
| 322 | setlocal listchars&vim |
| 323 | call assert_equal(['^I one two $'], ScreenLines(1, virtcol('$'))) |
| 324 | close |
| 325 | call assert_equal(['{......}--one==two##$'], ScreenLines(1, virtcol('$'))) |
| 326 | |
| 327 | " Using set in a window with a local setting should change it to use the |
| 328 | " global setting and also impact other windows using the global setting |
| 329 | split |
| 330 | setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:# |
| 331 | call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$'))) |
| 332 | set listchars=tab:+-+,lead:^,space:>,trail:<,eol:% |
| 333 | call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$'))) |
| 334 | close |
| 335 | call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$'))) |
| 336 | |
Bram Moolenaar | 04ea7e9 | 2021-02-16 21:14:33 +0100 | [diff] [blame] | 337 | " Setting invalid value for a local setting should not impact the local and |
| 338 | " global settings |
| 339 | split |
| 340 | setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:# |
| 341 | let cmd = 'setlocal listchars=tab:{.},lead:-,space:=,trail:#,eol:$,x' |
| 342 | call assert_fails(cmd, 'E474:') |
| 343 | call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$'))) |
| 344 | close |
| 345 | call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$'))) |
| 346 | |
| 347 | " Setting invalid value for a global setting should not impact the local and |
| 348 | " global settings |
| 349 | split |
| 350 | setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:# |
| 351 | let cmd = 'setglobal listchars=tab:{.},lead:-,space:=,trail:#,eol:$,x' |
| 352 | call assert_fails(cmd, 'E474:') |
| 353 | call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$'))) |
| 354 | close |
| 355 | call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$'))) |
| 356 | |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 357 | %bw! |
| 358 | set list& listchars& |
| 359 | endfunc |
| 360 | |
Bram Moolenaar | 41fb723 | 2021-07-08 12:40:05 +0200 | [diff] [blame] | 361 | func Test_listchars_foldcolumn() |
| 362 | CheckScreendump |
| 363 | |
| 364 | let lines =<< trim END |
| 365 | call setline(1, ['aaa', '', 'a', 'aaaaaa']) |
| 366 | vsplit |
| 367 | vsplit |
| 368 | windo set signcolumn=yes foldcolumn=1 winminwidth=0 nowrap list listchars=extends:>,precedes:< |
| 369 | END |
| 370 | call writefile(lines, 'XTest_listchars') |
| 371 | |
| 372 | let buf = RunVimInTerminal('-S XTest_listchars', {'rows': 10, 'cols': 60}) |
| 373 | |
| 374 | call term_sendkeys(buf, "13\<C-W>>") |
| 375 | call VerifyScreenDump(buf, 'Test_listchars_01', {}) |
| 376 | call term_sendkeys(buf, "\<C-W>>") |
| 377 | call VerifyScreenDump(buf, 'Test_listchars_02', {}) |
| 378 | call term_sendkeys(buf, "\<C-W>>") |
| 379 | call VerifyScreenDump(buf, 'Test_listchars_03', {}) |
| 380 | call term_sendkeys(buf, "\<C-W>>") |
| 381 | call VerifyScreenDump(buf, 'Test_listchars_04', {}) |
| 382 | call term_sendkeys(buf, "\<C-W>>") |
| 383 | call VerifyScreenDump(buf, 'Test_listchars_05', {}) |
Bram Moolenaar | 30441bb | 2021-07-08 13:19:31 +0200 | [diff] [blame^] | 384 | call term_sendkeys(buf, "\<C-W>h") |
| 385 | call term_sendkeys(buf, ":set nowrap foldcolumn=4\<CR>") |
| 386 | call term_sendkeys(buf, "15\<C-W><") |
| 387 | call VerifyScreenDump(buf, 'Test_listchars_06', {}) |
| 388 | call term_sendkeys(buf, "4\<C-W><") |
| 389 | call VerifyScreenDump(buf, 'Test_listchars_07', {}) |
Bram Moolenaar | 41fb723 | 2021-07-08 12:40:05 +0200 | [diff] [blame] | 390 | |
| 391 | " clean up |
| 392 | call StopVimInTerminal(buf) |
| 393 | call delete('XTest_listchars') |
| 394 | endfunc |
| 395 | |
| 396 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 397 | " vim: shiftwidth=2 sts=2 expandtab |