robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
7d97de27cf
master
1" Tests for 'listchars' display with 'list' and :list 2 3source check.vim 4source view_util.vim 5source screendump.vim 6 7func Check_listchars ( expected , end_lnum , end_scol = -1 , leftcol = 0 ) 8if a: leftcol > 0 9let save_wrap = & wrap 10set nowrap 11call cursor ( 1 , 1 ) 12exe 'normal! ' .. a: leftcol .. 'zl' 13endif 14 15redraw ! 16for i in range ( 1 , a: end_lnum ) 17if a: leftcol > 0 18let col = virtcol2col ( 0 , i , a: leftcol ) 19let col += getline ( i ) ->strpart ( col - 1 , 1 , v: true ) ->len () 20call cursor ( i , col ) 21redraw 22call assert_equal ( a: leftcol , winsaveview (). leftcol ) 23else 24call cursor ( i , 1 ) 25end 26 27let end_scol = a: end_scol < 0 ? '$' ->virtcol () - a: leftcol : a: end_scol 28call assert_equal ([ a: expected [ i - 1 ] ->strcharpart ( a: leftcol )], 29 \ScreenLines ( i , end_scol )) 30endfor 31 32if a: leftcol > 0 33let & wrap = save_wrap 34endif 35endfunc 36 37func Test_listchars () 38enew ! 39set ff = unix 40set list 41 42set listchars += tab:>-,space:.,trail:< 43call append ( 0 , [ 44 \' aa ' , 45 \' bb ' , 46 \' cccc ' , 47 \'dd ee ' , 48 \' ' 49 \]) 50let expected = [ 51 \'>-------aa>-----$' , 52 \'..bb>---<<$' , 53 \'...cccc><$' , 54 \'dd........ee<<>-$' , 55 \'<$' 56 \] 57call Check_listchars ( expected , 5 ) 58call Check_listchars ( expected , 4 , -1 , 5 ) 59 60set listchars -= trail:< 61let expected = [ 62 \'>-------aa>-----$' , 63 \'..bb>---..$' , 64 \'...cccc>.$' , 65 \'dd........ee..>-$' , 66 \'.$' 67 \] 68call Check_listchars ( expected , 5 ) 69call Check_listchars ( expected , 4 , -1 , 5 ) 70 71" tab with 3rd character. 72set listchars -= tab:>- 73set listchars += tab:<=>,trail:- 74let expected = [ 75 \'<======>aa<====>$' , 76 \'..bb<==>--$' , 77 \'...cccc>-$' , 78 \'dd........ee--<>$' , 79 \'-$' 80 \] 81call Check_listchars ( expected , 5 ) 82call Check_listchars ( expected , 4 , -1 , 5 ) 83 84" tab with 3rd character and linebreak set 85set listchars -= tab:<=> 86set listchars += tab:<·> 87set linebreak 88let expected = [ 89 \'<······>aa<····>$' , 90 \'..bb<··>--$' , 91 \'...cccc>-$' , 92 \'dd........ee--<>$' , 93 \'-$' 94 \] 95call Check_listchars ( expected , 5 ) 96set nolinebreak 97set listchars -= tab:<·> 98set listchars += tab:<=> 99 100set listchars -= trail:- 101let expected = [ 102 \'<======>aa<====>$' , 103 \'..bb<==>..$' , 104 \'...cccc>.$' , 105 \'dd........ee..<>$' , 106 \'.$' 107 \] 108call Check_listchars ( expected , 5 ) 109call Check_listchars ( expected , 4 , -1 , 5 ) 110 111set listchars -= tab:<=> 112set listchars += tab:>- 113set listchars += trail:< 114set nolist 115normal ggdG 116call append ( 0 , [ 117 \' fff ' , 118 \' gg ' , 119 \' h ' , 120 \'iii ' , 121 \]) 122let l = split ( execute ( "%list" ), "\n" ) 123call assert_equal ([ 124 \'..fff>--<<$' , 125 \'>-------gg>-----$' , 126 \'.....h>-$' , 127 \'iii<<<<><<$' , 128 \'$' ], l ) 129 130" Test lead and trail 131normal ggdG 132set listchars = eol:$" Accommodate Nvim default 133set listchars += lead:>,trail:<,space:x 134set list 135 136call append ( 0 , [ 137 \' ffff ' , 138 \' gg' , 139 \'h ' , 140 \' ' , 141 \' 0 0 ' , 142 \]) 143 144let expected = [ 145 \'>>>>ffff<<<<$' , 146 \'>>>>>>>>>>gg$' , 147 \'h<<<<<<<<<<<$' , 148 \'<<<<<<<<<<<<$' , 149 \'>>>>0xx0<<<<$' , 150 \'$' 151 \] 152call Check_listchars ( expected , 6 ) 153call Check_listchars ( expected , 5 , -1 , 6 ) 154call assert_equal ( expected , split ( execute ( "%list" ), "\n" )) 155 156" In a line with only spaces, they aren't considered leading even if "trail" 157" isn't set. 158set listchars -= trail:< 159let expected = [ 160 \'>>>>ffffxxxx$' , 161 \'>>>>>>>>>>gg$' , 162 \'hxxxxxxxxxxx$' , 163 \'xxxxxxxxxxxx$' , 164 \'>>>>0xx0xxxx$' , 165 \'$' 166 \] 167call Check_listchars ( expected , 6 ) 168call Check_listchars ( expected , 5 , -1 , 6 ) 169call assert_equal ( expected , split ( execute ( "%list" ), "\n" )) 170 171" Test multispace 172normal ggdG 173set listchars = eol:$" Accommodate Nvim default 174set listchars += multispace:yYzZ 175set list 176 177call append ( 0 , [ 178 \' ffff ' , 179 \' i i gg' , 180 \' h ' , 181 \' ' , 182 \' j ' , 183 \' 0 0 ' , 184 \]) 185 186let expected = [ 187 \'yYzZffffyYzZ$' , 188 \'yYi iyYzZygg$' , 189 \' hyYzZyYzZyY$' , 190 \'yYzZyYzZyYzZ$' , 191 \'yYzZyYzZyYj $' , 192 \'yYzZ0yY0yYzZ$' , 193 \'$' 194 \] 195call Check_listchars ( expected , 7 ) 196call Check_listchars ( expected , 6 , -1 , 6 ) 197call assert_equal ( expected , split ( execute ( "%list" ), "\n" )) 198 199" Test leadmultispace + multispace 200normal ggdG 201set listchars = eol:$,multispace:yYzZ,nbsp:S 202set listchars += leadmultispace:.-+* 203set list 204 205call append ( 0 , [ 206 \' ffff ' , 207 \' i i gg' , 208 \' h ' , 209 \' ' , 210 \' j ' , 211 \' 0 0 ' , 212 \]) 213 214let expected = [ 215 \'.-+*ffffyYzZ$' , 216 \'.-i iSyYzZgg$' , 217 \' hyYzZyYzZyY$' , 218 \'yYzZyYzZyYzZ$' , 219 \'.-+*.-+*.-j $' , 220 \'.-+*0yY0yYzZ$' , 221 \'$' 222 \] 223call assert_equal ( 'eol:$,multispace:yYzZ,nbsp:S,leadmultispace:.-+*' , & listchars ) 224call Check_listchars ( expected , 7 ) 225call Check_listchars ( expected , 6 , -1 , 1 ) 226call Check_listchars ( expected , 6 , -1 , 2 ) 227call Check_listchars ( expected , 6 , -1 , 3 ) 228call Check_listchars ( expected , 6 , -1 , 6 ) 229call assert_equal ( expected , split ( execute ( "%list" ), "\n" )) 230 231" Test leadmultispace without multispace 232normal ggdG 233set listchars -= multispace:yYzZ 234set listchars += space:+,trail:>,eol:$ 235set list 236 237call append ( 0 , [ 238 \' ffff ' , 239 \' i i gg' , 240 \' h ' , 241 \' ' , 242 \' j ' , 243 \' 0 0 ' , 244 \]) 245 246let expected = [ 247 \'.-+*ffff>>>>$' , 248 \'.-i+i+++++gg$' , 249 \'+h>>>>>>>>>>$' , 250 \'>>>>>>>>>>>>$' , 251 \'.-+*.-+*.-j>$' , 252 \'.-+*0++0>>>>$' , 253 \'$' 254 \] 255call assert_equal ( 'eol:$,nbsp:S,leadmultispace:.-+*,space:+,trail:>' , & listchars ) 256call Check_listchars ( expected , 7 ) 257call Check_listchars ( expected , 6 , -1 , 1 ) 258call Check_listchars ( expected , 6 , -1 , 2 ) 259call Check_listchars ( expected , 6 , -1 , 3 ) 260call Check_listchars ( expected , 6 , -1 , 6 ) 261call assert_equal ( expected , split ( execute ( "%list" ), "\n" )) 262 263" Test leadmultispace only 264normal ggdG 265set listchars = eol:$" Accommodate Nvim default 266set listchars = leadmultispace:.-+* 267set list 268 269call append ( 0 , [ 270 \' ffff ' , 271 \' i i gg' , 272 \' h ' , 273 \' ' , 274 \' j ' , 275 \' 0 0 ' , 276 \]) 277 278let expected = [ 279 \'.-+*ffff ' , 280 \'.-i i gg' , 281 \' h ' , 282 \' ' , 283 \'.-+*.-+*.-j ' , 284 \'.-+*0 0 ' , 285 \' ' 286 \] 287call assert_equal ( 'leadmultispace:.-+*' , & listchars ) 288call Check_listchars ( expected , 6 , 12 ) 289call assert_equal ( expected , split ( execute ( "%list" ), "\n" )) 290 291" Changing the value of 'ambiwidth' twice shouldn't cause double-free when 292" "leadmultispace" is specified. 293set ambiwidth = double 294set ambiwidth & 295 296" Test leadmultispace and lead and space 297normal ggdG 298set listchars = eol:$" Accommodate Nvim default 299set listchars += lead:<,space:- 300set listchars += leadmultispace:.-+* 301set list 302 303call append ( 0 , [ 304 \' ffff ' , 305 \' i i gg' , 306 \' h ' , 307 \' ' , 308 \' j ' , 309 \' 0 0 ' , 310 \]) 311 312let expected = [ 313 \'.-+*ffff----$' , 314 \'.-i-i-----gg$' , 315 \'<h----------$' , 316 \'------------$' , 317 \'.-+*.-+*.-j-$' , 318 \'.-+*0--0----$' , 319 \'$' 320 \] 321call assert_equal ( 'eol:$,lead:<,space:-,leadmultispace:.-+*' , & listchars ) 322call Check_listchars ( expected , 7 ) 323call Check_listchars ( expected , 6 , -1 , 1 ) 324call Check_listchars ( expected , 6 , -1 , 2 ) 325call Check_listchars ( expected , 6 , -1 , 3 ) 326call Check_listchars ( expected , 6 , -1 , 6 ) 327call assert_equal ( expected , split ( execute ( "%list" ), "\n" )) 328 329" the last occurrence of 'multispace:' is used 330set listchars = eol:$" Accommodate Nvim default 331set listchars += multispace:yYzZ 332set listchars += space:x,multispace:XyY 333 334let expected = [ 335 \'XyYXffffXyYX$' , 336 \'XyixiXyYXygg$' , 337 \'xhXyYXyYXyYX$' , 338 \'XyYXyYXyYXyY$' , 339 \'XyYXyYXyYXjx$' , 340 \'XyYX0Xy0XyYX$' , 341 \'$' 342 \] 343call assert_equal ( 'eol:$,space:x,multispace:XyY' , & listchars ) 344call Check_listchars ( expected , 7 ) 345call Check_listchars ( expected , 6 , -1 , 6 ) 346call assert_equal ( expected , split ( execute ( "%list" ), "\n" )) 347 348" when using :let, multiple 'multispace:' fields can exist 349" and the last occurrence of 'multispace:' is used 350let & listchars = 'eol:$,multispace:yYzZ,space:x,multispace:XyY' 351call assert_equal ( 'eol:$,multispace:yYzZ,space:x,multispace:XyY' , & listchars ) 352call Check_listchars ( expected , 7 ) 353call Check_listchars ( expected , 6 , -1 , 6 ) 354call assert_equal ( expected , split ( execute ( "%list" ), "\n" )) 355 356" restore to single multispace: for subsequent tests 357set listchars = eol:$,space:x,multispace:XyY 358set listchars += lead:>,trail:< 359 360let expected = [ 361 \'>>>>ffff<<<<$' , 362 \'>>ixiXyYXygg$' , 363 \'>h<<<<<<<<<<$' , 364 \'<<<<<<<<<<<<$' , 365 \'>>>>>>>>>>j<$' , 366 \'>>>>0Xy0<<<<$' , 367 \'$' 368 \] 369call Check_listchars ( expected , 7 ) 370call Check_listchars ( expected , 6 , -1 , 6 ) 371call assert_equal ( expected , split ( execute ( "%list" ), "\n" )) 372 373" removing 'multispace:' 374set listchars -= multispace: 375 376let expected = [ 377 \'>>>>ffff<<<<$' , 378 \'>>ixixxxxxgg$' , 379 \'>h<<<<<<<<<<$' , 380 \'<<<<<<<<<<<<$' , 381 \'>>>>>>>>>>j<$' , 382 \'>>>>0xx0<<<<$' , 383 \'$' 384 \] 385call Check_listchars ( expected , 7 ) 386call Check_listchars ( expected , 6 , -1 , 6 ) 387call assert_equal ( expected , split ( execute ( "%list" ), "\n" )) 388 389" Test leadtab basic functionality 390normal ggdG 391set listchars = tab:>-,leadtab:+* 392set list 393call append ( 0 , [ 394 \"\ttext" , 395 \"\t\ttext" , 396 \"text\ttab" 397 \]) 398let expected = [ 399 \'+*******text ' , 400 \'+*******+*******text' , 401 \'text>---tab ' 402 \] 403call Check_listchars ( expected , 3 , 20 ) 404call assert_equal ( expected ->mapnew ({ _ , s ->trim ( s , ' ' , 2 )}) + [ ' ' ], 405 \split ( execute ( "%list" ), "\n" )) 406 407" Test leadtab with unicode characters 408normal ggdG 409set listchars = tab:>-,leadtab:├─┤ 410call append ( 0 , [ "\ttext" ]) 411let expected = [ '├──────┤text' ] 412call Check_listchars ( expected , 1 , 12 ) 413call assert_equal ( expected + [ ' ' ], split ( execute ( "%list" ), "\n" )) 414 415" Test leadtab with mixed indentation (spaces + tabs) 416normal ggdG 417set listchars = tab:>-,leadtab:+*,space:. 418call append ( 0 , [ " \t text" ]) 419let expected = [ '.+******.text' ] 420call Check_listchars ( expected , 1 , 13 ) 421call assert_equal ( expected + [ ' ' ], split ( execute ( "%list" ), "\n" )) 422 423" Test leadtab with pipe character 424normal ggdG 425let & listchars = 'tab:>-,leadtab:| ' 426call append ( 0 , [ "\ttext" ]) 427let expected = [ '| text' ] 428call Check_listchars ( expected , 1 , 12 ) 429call assert_equal ( expected + [ ' ' ], split ( execute ( "%list" ), "\n" )) 430 431" Test leadtab with unicode bar 432normal ggdG 433let & listchars = 'tab:>-,leadtab:│ ' 434call append ( 0 , [ "\ttext" ]) 435let expected = [ '│ text' ] 436call Check_listchars ( expected , 1 , 12 ) 437call assert_equal ( expected + [ ' ' ], split ( execute ( "%list" ), "\n" )) 438 439" Test leadtab vs tab distinction (leading vs non-leading) 440" In a line with only tabs, they aren't considered leading. 441normal ggdG 442set listchars = tab:>-,leadtab:+* 443call append ( 0 , [ 444 \"\tleading" , 445 \"text\tnot leading" , 446 \"\t\tmultiple leading" , 447 \"\t\t" 448 \]) 449let expected = [ 450 \'+*******leading ' , 451 \'text>---not leading ' , 452 \'+*******+*******multiple leading' , 453 \'>------->------- ' 454 \] 455call Check_listchars ( expected , 4 , 32 ) 456call assert_equal ( expected ->mapnew ({ _ , s ->trim ( s , ' ' , 2 )}) + [ ' ' ], 457 \split ( execute ( "%list" ), "\n" )) 458 459" Test leadtab with trail and space 460normal ggdG 461set listchars = tab:>-,leadtab:+*,trail:<,space:. 462call append ( 0 , [ 463 \"\ttext " , 464 \" \ttext" , 465 \"\t text " 466 \]) 467let expected = [ 468 \'+*******text<< ' , 469 \'..+*****text ' , 470 \'+*******..text<<' 471 \] 472call Check_listchars ( expected , 3 , 16 ) 473call assert_equal ( expected ->mapnew ({ _ , s ->trim ( s , ' ' , 2 )}) + [ ' ' ], 474 \split ( execute ( "%list" ), "\n" )) 475 476" Test leadtab with eol 477normal ggdG 478set listchars = tab:>-,leadtab:+*,eol:$ 479call append ( 0 , [ "\ttext" , "text\ttab" ]) 480let expected = [ 481 \'+*******text$' , 482 \'text>---tab$ ' 483 \] 484call Check_listchars ( expected , 2 , 13 ) 485call assert_equal ( expected ->mapnew ({ _ , s ->trim ( s , ' ' , 2 )}) + [ '$' ], 486 \split ( execute ( "%list" ), "\n" )) 487 488" test nbsp 489normal ggdG 490set listchars = nbsp:X,trail:Y 491set list 492" Non-breaking space 493let nbsp = nr2char ( 0xa0 ) 494call append ( 0 , [ ">" .. nbsp .. "<" ]) 495 496let expected = '>X< ' 497call Check_listchars ([ expected ], 1 ) 498 499set listchars = nbsp:X 500call Check_listchars ([ expected ], 1 ) 501 502" test extends 503normal ggdG 504set listchars = extends:Z 505set nowrap 506set nolist 507call append ( 0 , [ repeat ( 'A' , & columns + 1 ) ]) 508 509let expected = repeat ( 'A' , & columns ) 510call Check_listchars ([ expected ], 1 , & columns ) 511 512set list 513let expected = expected [: -2 ] . 'Z' 514call Check_listchars ([ expected ], 1 , & columns ) 515 516enew ! 517set listchars & ff & 518endfunc 519 520" Test that unicode listchars characters get properly inserted 521func Test_listchars_unicode () 522enew ! 523let oldencoding =& encoding 524set encoding = utf-8 525set ff = unix 526 527set listchars = eol:⇔,space:␣,multispace:≡≢≣,nbsp:≠,tab:←↔→ 528set list 529 530let nbsp = nr2char ( 0xa0 ) 531call append ( 0 , [ " a\tb c" .. nbsp .. "d " ]) 532let expected = [ '≡≢≣≡≢≣≡≢a←↔↔↔↔↔→b␣c≠d≡≢⇔' ] 533call Check_listchars ( expected , 1 ) 534call Check_listchars ( expected , 1 , -1 , 3 ) 535call Check_listchars ( expected , 1 , -1 , 13 ) 536 537set listchars = eol:\\u21d4,space:\\u2423,multispace:≡\\u2262\\U00002263,nbsp:\\U00002260,tab:←↔\\u2192 538call Check_listchars ( expected , 1 ) 539call Check_listchars ( expected , 1 , -1 , 3 ) 540call Check_listchars ( expected , 1 , -1 , 13 ) 541 542set listchars += lead:⇨,trail:⇦ 543let expected = [ '⇨⇨⇨⇨⇨⇨⇨⇨a←↔↔↔↔↔→b␣c≠d⇦⇦⇔' ] 544call Check_listchars ( expected , 1 ) 545call Check_listchars ( expected , 1 , -1 , 3 ) 546call Check_listchars ( expected , 1 , -1 , 13 ) 547 548let & encoding = oldencoding 549enew ! 550set listchars & ff & 551endfunction 552 553func Test_listchars_invalid () 554enew ! 555set ff = unix 556 557set listchars = eol:$" Accommodate Nvim default 558set list 559set ambiwidth = double 560 561" No colon 562call assert_fails ( 'set listchars=x' , 'E474:' ) 563call assert_fails ( 'set listchars=x' , 'E474:' ) 564call assert_fails ( 'set listchars=multispace' , 'E474:' ) 565call assert_fails ( 'set listchars=leadmultispace' , 'E474:' ) 566 567" Too short 568call assert_fails ( 'set listchars=space:' , 'E1511:' ) 569call assert_fails ( 'set listchars=tab:x' , 'E1511:' ) 570call assert_fails ( 'set listchars=multispace:' , 'E1511:' ) 571call assert_fails ( 'set listchars=leadmultispace:' , 'E1511:' ) 572 573" One occurrence too short 574call assert_fails ( 'set listchars=space:x,space:' , 'E1511:' ) 575call assert_fails ( 'set listchars=space:,space:x' , 'E1511:' ) 576call assert_fails ( 'set listchars=tab:xx,tab:x' , 'E1511:' ) 577call assert_fails ( 'set listchars=tab:x,tab:xx' , 'E1511:' ) 578call assert_fails ( 'set listchars=multispace:,multispace:x' , 'E1511:' ) 579call assert_fails ( 'set listchars=multispace:x,multispace:' , 'E1511:' ) 580call assert_fails ( 'set listchars=leadmultispace:,leadmultispace:x' , 'E1511:' ) 581call assert_fails ( 'set listchars=leadmultispace:x,leadmultispace:' , 'E1511:' ) 582 583" Too long 584call assert_fails ( 'set listchars=space:xx' , 'E1511:' ) 585call assert_fails ( 'set listchars=tab:xxxx' , 'E1511:' ) 586 587" Has double-width character 588call assert_fails ( 'set listchars=space:·' , 'E1512:' ) 589call assert_fails ( 'set listchars=tab:·x' , 'E1512:' ) 590call assert_fails ( 'set listchars=tab:x·' , 'E1512:' ) 591call assert_fails ( 'set listchars=tab:xx·' , 'E1512:' ) 592call assert_fails ( 'set listchars=multispace:·' , 'E1512:' ) 593call assert_fails ( 'set listchars=multispace:xxx·' , 'E1512:' ) 594call assert_fails ( 'set listchars=leadmultispace:·' , 'E1512:' ) 595call assert_fails ( 'set listchars=leadmultispace:xxx·' , 'E1512:' ) 596 597" Has control character 598call assert_fails ( "set listchars=space:\x01" , 'E1512:' ) 599call assert_fails ( "set listchars=tab:\x01x" , 'E1512:' ) 600call assert_fails ( "set listchars=tab:x\x01" , 'E1512:' ) 601call assert_fails ( "set listchars=tab:xx\x01" , 'E1512:' ) 602call assert_fails ( "set listchars=multispace:\x01" , 'E1512:' ) 603call assert_fails ( "set listchars=multispace:xxx\x01" , 'E1512:' ) 604call assert_fails ( 'set listchars=space:\\x01' , 'E1512:' ) 605call assert_fails ( 'set listchars=tab:\\x01x' , 'E1512:' ) 606call assert_fails ( 'set listchars=tab:x\\x01' , 'E1512:' ) 607call assert_fails ( 'set listchars=tab:xx\\x01' , 'E1512:' ) 608call assert_fails ( 'set listchars=multispace:\\x01' , 'E1512:' ) 609call assert_fails ( 'set listchars=multispace:xxx\\x01' , 'E1512:' ) 610call assert_fails ( "set listchars=leadmultispace:\x01" , 'E1512:' ) 611call assert_fails ( 'set listchars=leadmultispace:\\x01' , 'E1512:' ) 612call assert_fails ( "set listchars=leadmultispace:xxx\x01" , 'E1512:' ) 613call assert_fails ( 'set listchars=leadmultispace:xxx\\x01' , 'E1512:' ) 614 615enew ! 616set ambiwidth & listchars & ff & 617endfunction 618 619" Tests that space characters following composing character won't get replaced 620" by listchars. 621func Test_listchars_composing () 622enew ! 623let oldencoding =& encoding 624set encoding = utf-8 625set ff = unix 626set list 627 628set listchars = eol:$,space:_,nbsp:= 629 630let nbsp1 = nr2char ( 0xa0 ) 631let nbsp2 = nr2char ( 0x202f ) 632call append ( 0 , [ 633 \" \u3099\t \u309A" .. nbsp1 .. nbsp1 .. "\u0302" .. nbsp2 .. nbsp2 .. "\u0302" , 634 \]) 635let expected = [ 636 \"_ \u3099^I \u309A=" .. nbsp1 .. "\u0302=" .. nbsp2 .. "\u0302$" 637 \] 638call Check_listchars ( expected , 1 ) 639let & encoding = oldencoding 640enew ! 641set listchars & ff & 642endfunction 643 644" Check for the value of the 'listchars' option 645func s: CheckListCharsValue ( expected ) 646call assert_equal ( a: expected , & listchars ) 647call assert_equal ( a: expected , getwinvar ( 0 , '&listchars' )) 648endfunc 649 650" Test for using a window local value for 'listchars' 651func Test_listchars_window_local () 652 %bw ! 653set list listchars & 654let nvim_default = & listchars " Accommodate Nvim default 655new 656" set a local value for 'listchars' 657setlocal listchars = tab:+-,eol:# 658call s: CheckListCharsValue ( 'tab:+-,eol:#' ) 659" When local value is reset, global value should be used 660setlocal listchars = 661call s: CheckListCharsValue ( nvim_default ) 662" Use 'setlocal <' to copy global value 663setlocal listchars = space:.,extends:> 664setlocal listchars < 665call s: CheckListCharsValue ( nvim_default ) 666" Use 'set <' to copy global value 667setlocal listchars = space:.,extends:> 668set listchars < 669call s: CheckListCharsValue ( nvim_default ) 670" Changing global setting should not change the local setting 671setlocal listchars = space:.,extends:> 672setglobal listchars=tab:+-,eol:# 673call s: CheckListCharsValue ( 'space:.,extends:>' ) 674" when split opening a new window, local value should be copied 675split 676call s: CheckListCharsValue ( 'space:.,extends:>' ) 677" clearing local value in one window should not change the other window 678set listchars & 679call s: CheckListCharsValue ( nvim_default ) 680close 681call s: CheckListCharsValue ( 'space:.,extends:>' ) 682 683" use different values for 'listchars' items in two different windows 684call setline ( 1 , [ "\t one two " ]) 685setlocal listchars = tab:<->,lead:_,space:.,trail:@,eol:# 686split 687setlocal listchars = tab:[.],lead:#,space:_,trail:.,eol:& 688split 689set listchars = tab:+-+,lead:^,space:>,trail:<,eol:% 690call assert_equal ([ '+------+^^one>>two<<%' ], ScreenLines ( 1 , virtcol ( '$' ))) 691close 692call assert_equal ([ '[......]##one__two..&' ], ScreenLines ( 1 , virtcol ( '$' ))) 693close 694call assert_equal ([ '<------>__one..two@@#' ], ScreenLines ( 1 , virtcol ( '$' ))) 695" changing the global setting should not change the local value 696setglobal listchars=tab:[.],lead:#,space:_,trail:.,eol:& 697call assert_equal ([ '<------>__one..two@@#' ], ScreenLines ( 1 , virtcol ( '$' ))) 698set listchars < 699call assert_equal ([ '[......]##one__two..&' ], ScreenLines ( 1 , virtcol ( '$' ))) 700 701" Using setglobal in a window with local setting should not affect the 702" window. But should impact other windows using the global setting. 703enew ! |only 704call setline ( 1 , [ "\t one two " ]) 705set listchars = tab:[.],lead:#,space:_,trail:.,eol:& 706split 707setlocal listchars = tab:+-+,lead:^,space:>,trail:<,eol:% 708split 709setlocal listchars = tab:<->,lead:_,space:.,trail:@,eol:# 710setglobal listchars=tab:{.},lead:-,space:=,trail:#,eol:$ 711call assert_equal ([ '<------>__one..two@@#' ], ScreenLines ( 1 , virtcol ( '$' ))) 712close 713call assert_equal ([ '+------+^^one>>two<<%' ], ScreenLines ( 1 , virtcol ( '$' ))) 714close 715call assert_equal ([ '{......}--one==two##$' ], ScreenLines ( 1 , virtcol ( '$' ))) 716 717" Setting the global setting to the default value should not impact a window 718" using a local setting. 719split 720setlocal listchars = tab:<->,lead:_,space:.,trail:@,eol:# 721setglobal listchars=eol:$ " Accommodate Nvim default 722call assert_equal ([ '<------>__one..two@@#' ], ScreenLines ( 1 , virtcol ( '$' ))) 723close 724call assert_equal ([ '^I one two $' ], ScreenLines ( 1 , virtcol ( '$' ))) 725 726" Setting the local setting to the default value should not impact a window 727" using a global setting. 728set listchars = tab:{.},lead:-,space:=,trail:#,eol:$ 729split 730setlocal listchars = tab:<->,lead:_,space:.,trail:@,eol:# 731call assert_equal ([ '<------>__one..two@@#' ], ScreenLines ( 1 , virtcol ( '$' ))) 732setlocal listchars = eol:$ " Accommodate Nvim default 733call assert_equal ([ '^I one two $' ], ScreenLines ( 1 , virtcol ( '$' ))) 734close 735call assert_equal ([ '{......}--one==two##$' ], ScreenLines ( 1 , virtcol ( '$' ))) 736 737" Using set in a window with a local setting should change it to use the 738" global setting and also impact other windows using the global setting. 739split 740setlocal listchars = tab:<->,lead:_,space:.,trail:@,eol:# 741call assert_equal ([ '<------>__one..two@@#' ], ScreenLines ( 1 , virtcol ( '$' ))) 742set listchars = tab:+-+,lead:^,space:>,trail:<,eol:% 743call assert_equal ([ '+------+^^one>>two<<%' ], ScreenLines ( 1 , virtcol ( '$' ))) 744close 745call assert_equal ([ '+------+^^one>>two<<%' ], ScreenLines ( 1 , virtcol ( '$' ))) 746 747" Setting invalid value for a local setting should not impact the local and 748" global settings. 749split 750setlocal listchars = tab:<->,lead:_,space:.,trail:@,eol:# 751let cmd = 'setlocal listchars=tab:{.},lead:-,space:=,trail:#,eol:$,x' 752call assert_fails ( cmd , 'E474:' ) 753call assert_equal ([ '<------>__one..two@@#' ], ScreenLines ( 1 , virtcol ( '$' ))) 754close 755call assert_equal ([ '+------+^^one>>two<<%' ], ScreenLines ( 1 , virtcol ( '$' ))) 756 757" Setting invalid value for a global setting should not impact the local and 758" global settings. 759split 760setlocal listchars = tab:<->,lead:_,space:.,trail:@,eol:# 761let cmd = 'setglobal listchars=tab:{.},lead:-,space:=,trail:#,eol:$,x' 762call assert_fails ( cmd , 'E474:' ) 763call assert_equal ([ '<------>__one..two@@#' ], ScreenLines ( 1 , virtcol ( '$' ))) 764close 765call assert_equal ([ '+------+^^one>>two<<%' ], ScreenLines ( 1 , virtcol ( '$' ))) 766 767" Closing window with local lcs-multispace should not cause a memory leak. 768setlocal listchars = multispace:---+ 769split 770call s: CheckListCharsValue ( 'multispace:---+' ) 771close 772 773% bw ! 774set list & listchars & 775endfunc 776 777func Test_listchars_foldcolumn () 778CheckScreendump 779 780let lines =<< trim END 781call setline(1, ['aaa', '', 'a', 'aaaaaa']) 782vsplit 783vsplit 784windo set signcolumn=yes foldcolumn=1 winminwidth=0 nowrap list listchars=extends:>,precedes:< 785END 786call writefile ( lines , 'XTest_listchars' , 'D' ) 787 788let buf = RunVimInTerminal ( '-S XTest_listchars' , { 'rows' : 10 , 'cols' : 60 }) 789 790call term_sendkeys ( buf , "13\<C-W>>" ) 791call VerifyScreenDump ( buf , 'Test_listchars_01' , {}) 792call term_sendkeys ( buf , "\<C-W>>" ) 793call VerifyScreenDump ( buf , 'Test_listchars_02' , {}) 794call term_sendkeys ( buf , "\<C-W>>" ) 795call VerifyScreenDump ( buf , 'Test_listchars_03' , {}) 796call term_sendkeys ( buf , "\<C-W>>" ) 797call VerifyScreenDump ( buf , 'Test_listchars_04' , {}) 798call term_sendkeys ( buf , "\<C-W>>" ) 799call VerifyScreenDump ( buf , 'Test_listchars_05' , {}) 800call term_sendkeys ( buf , "\<C-W>h" ) 801call term_sendkeys ( buf , ":set nowrap foldcolumn=4\<CR>" ) 802call term_sendkeys ( buf , "15\<C-W><" ) 803call VerifyScreenDump ( buf , 'Test_listchars_06' , {}) 804call term_sendkeys ( buf , "4\<C-W><" ) 805call VerifyScreenDump ( buf , 'Test_listchars_07' , {}) 806 807" clean up 808call StopVimInTerminal ( buf ) 809endfunc 810 811func Test_listchars_precedes_with_wide_char () 812new 813setlocal nowrap list listchars = eol:$,precedes:! 814call setline ( 1 , '123口456' ) 815call assert_equal ([ '123口456$ ' ], ScreenLines ( 1 , 10 )) 816let attr = screenattr ( 1 , 9 ) 817 818normal ! zl 819call assert_equal ([ '!3口456$ ' ], ScreenLines ( 1 , 10 )) 820call assert_equal ( attr , screenattr ( 1 , 1 )) 821normal ! zl 822call assert_equal ([ '!口456$ ' ], ScreenLines ( 1 , 10 )) 823call assert_equal ( attr , screenattr ( 1 , 1 )) 824normal ! zl 825call assert_equal ([ '!<456$ ' ], ScreenLines ( 1 , 10 )) 826call assert_equal ( attr , screenattr ( 1 , 1 )) 827call assert_equal ( attr , screenattr ( 1 , 2 )) 828normal ! zl 829call assert_equal ([ '!456$ ' ], ScreenLines ( 1 , 10 )) 830call assert_equal ( attr , screenattr ( 1 , 1 )) 831normal ! zl 832call assert_equal ([ '!56$ ' ], ScreenLines ( 1 , 10 )) 833call assert_equal ( attr , screenattr ( 1 , 1 )) 834normal ! zl 835call assert_equal ([ '!6$ ' ], ScreenLines ( 1 , 10 )) 836call assert_equal ( attr , screenattr ( 1 , 1 )) 837 838bw ! 839endfunc 840 841func Test_listchars_precedes_with_tab () 842new 843setlocal nowrap list listchars = eol:$,precedes:!,tab:<-> 844call setline ( 1 , "1234\t56" ) 845let expected_line = '1234<-->56$ ' 846call assert_equal ([ expected_line ], ScreenLines ( 1 , 12 )) 847let expected_attrs = mapnew ( range ( 1 , 12 ), 'screenattr(1, v:val)' ) 848let attr = expected_attrs [ -2 ] 849 850for i in range ( 8 ) 851normal ! zl 852let expected_line = '!' .. expected_line [ 2 :] .. ' ' 853let expected_attrs = [ attr ] + expected_attrs [ 2 :] + expected_attrs [ -1 :] 854call assert_equal ([ expected_line ], ScreenLines ( 1 , 12 )) 855let attrs = mapnew ( range ( 1 , 12 ), 'screenattr(1, v:val)' ) 856call assert_equal ( expected_attrs , attrs ) 857endfor 858 859bw ! 860endfunc 861 862" vim: shiftwidth=2 sts=2 expandtab