robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f33364a41d
master
1" Test for breakindent 2" 3" Note: if you get strange failures when adding new tests, it might be that 4" while the test is run, the breakindent caching gets in its way. 5" It helps to change the tabstop setting and force a redraw (e.g. see 6" Test_breakindent08()) 7source check.vim 8CheckOption breakindent 9 10source view_util.vim 11source screendump.vim 12 13func SetUp () 14let s: input = "\tabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP" 15endfunc 16 17func s: screen_lines ( lnum , width ) abort 18return ScreenLines ([ a: lnum , a: lnum + 2 ], a: width ) 19endfunc 20 21func s: screen_lines2 ( lnums , lnume , width ) abort 22return ScreenLines ([ a: lnums , a: lnume ], a: width ) 23endfunc 24 25func s: compare_lines ( expect , actual ) 26call assert_equal ( join ( a: expect , "\n" ), join ( a: actual , "\n" )) 27endfunc 28 29func s: test_windows (...) 30call NewWindow ( 10 , 20 ) 31setl ts = 4 sw = 4 sts = 4 breakindent 32put =s:input 33exe get ( a: 000 , 0 , '' ) 34endfunc 35 36func s: close_windows (...) 37call CloseWindow () 38exe get ( a: 000 , 0 , '' ) 39endfunc 40 41func Test_breakindent01 () 42" simple breakindent test 43call s: test_windows ( 'setl briopt=min:0' ) 44let lines = s: screen_lines ( line ( '.' ), 8 ) 45let expect = [ 46 \" abcd" , 47 \" qrst" , 48 \" GHIJ" , 49 \] 50call s: compare_lines ( expect , lines ) 51call s: close_windows () 52endfunc 53 54func Test_breakindent01_vartabs () 55" like 01 but with vartabs feature 56if ! has ( "vartabs" ) 57return 58endif 59call s: test_windows ( 'setl briopt=min:0 vts=4' ) 60let lines = s: screen_lines ( line ( '.' ), 8 ) 61let expect = [ 62 \" abcd" , 63 \" qrst" , 64 \" GHIJ" , 65 \] 66call s: compare_lines ( expect , lines ) 67call s: close_windows ( 'set vts&' ) 68endfunc 69 70func Test_breakindent02 () 71" simple breakindent test with showbreak set 72set sbr = >> 73call s: test_windows ( 'setl briopt=min:0 sbr=' ) 74let lines = s: screen_lines ( line ( '.' ), 8 ) 75let expect = [ 76 \" abcd" , 77 \" >>qr" , 78 \" >>EF" , 79 \] 80call s: compare_lines ( expect , lines ) 81call s: close_windows ( 'set sbr=' ) 82endfunc 83 84func Test_breakindent02_vartabs () 85if ! has ( "vartabs" ) 86return 87endif 88" simple breakindent test with showbreak set 89call s: test_windows ( 'setl briopt=min:0 sbr=>> vts=4' ) 90let lines = s: screen_lines ( line ( '.' ), 8 ) 91let expect = [ 92 \" abcd" , 93 \" >>qr" , 94 \" >>EF" , 95 \] 96call s: compare_lines ( expect , lines ) 97call s: close_windows ( 'set sbr= vts&' ) 98endfunc 99 100func Test_breakindent03 () 101" simple breakindent test with showbreak set and briopt including sbr 102call s: test_windows ( 'setl briopt=sbr,min:0 sbr=++' ) 103let lines = s: screen_lines ( line ( '.' ), 8 ) 104let expect = [ 105\" abcd" , 106\"++ qrst" , 107\"++ GHIJ" , 108\] 109call s: compare_lines ( expect , lines ) 110" clean up 111call s: close_windows ( 'set sbr=' ) 112endfunc 113 114func Test_breakindent03_vartabs () 115" simple breakindent test with showbreak set and briopt including sbr 116if ! has ( "vartabs" ) 117return 118endif 119call s: test_windows ( 'setl briopt=sbr,min:0 sbr=++ vts=4' ) 120let lines = s: screen_lines ( line ( '.' ), 8 ) 121let expect = [ 122 \" abcd" , 123 \"++ qrst" , 124 \"++ GHIJ" , 125 \] 126call s: compare_lines ( expect , lines ) 127" clean up 128call s: close_windows ( 'set sbr= vts&' ) 129endfunc 130 131func Test_breakindent04 () 132" breakindent set with min width 18 133set sbr = <<< 134call s: test_windows ( 'setl sbr=NONE briopt=min:18' ) 135let lines = s: screen_lines ( line ( '.' ), 8 ) 136let expect = [ 137 \" abcd" , 138 \" qrstuv" , 139 \" IJKLMN" , 140 \] 141call s: compare_lines ( expect , lines ) 142" clean up 143call s: close_windows ( 'set sbr=' ) 144set sbr = 145endfunc 146 147func Test_breakindent04_vartabs () 148" breakindent set with min width 18 149if ! has ( "vartabs" ) 150return 151endif 152call s: test_windows ( 'setl sbr= briopt=min:18 vts=4' ) 153let lines = s: screen_lines ( line ( '.' ), 8 ) 154let expect = [ 155 \" abcd" , 156 \" qrstuv" , 157 \" IJKLMN" , 158 \] 159call s: compare_lines ( expect , lines ) 160" clean up 161call s: close_windows ( 'set sbr= vts&' ) 162endfunc 163 164func Test_breakindent05 () 165" breakindent set and shift by 2 166call s: test_windows ( 'setl briopt=shift:2,min:0' ) 167let lines = s: screen_lines ( line ( '.' ), 8 ) 168let expect = [ 169 \" abcd" , 170 \" qr" , 171 \" EF" , 172 \] 173call s: compare_lines ( expect , lines ) 174call s: close_windows () 175endfunc 176 177func Test_breakindent05_vartabs () 178" breakindent set and shift by 2 179if ! has ( "vartabs" ) 180return 181endif 182call s: test_windows ( 'setl briopt=shift:2,min:0 vts=4' ) 183let lines = s: screen_lines ( line ( '.' ), 8 ) 184let expect = [ 185 \" abcd" , 186 \" qr" , 187 \" EF" , 188 \] 189call s: compare_lines ( expect , lines ) 190call s: close_windows ( 'set vts&' ) 191endfunc 192 193func Test_breakindent06 () 194" breakindent set and shift by -1 195call s: test_windows ( 'setl briopt=shift:-1,min:0' ) 196let lines = s: screen_lines ( line ( '.' ), 8 ) 197let expect = [ 198 \" abcd" , 199 \" qrstu" , 200 \" HIJKL" , 201 \] 202call s: compare_lines ( expect , lines ) 203call s: close_windows () 204endfunc 205 206func Test_breakindent06_vartabs () 207" breakindent set and shift by -1 208if ! has ( "vartabs" ) 209return 210endif 211call s: test_windows ( 'setl briopt=shift:-1,min:0 vts=4' ) 212let lines = s: screen_lines ( line ( '.' ), 8 ) 213let expect = [ 214 \" abcd" , 215 \" qrstu" , 216 \" HIJKL" , 217 \] 218call s: compare_lines ( expect , lines ) 219call s: close_windows ( 'set vts&' ) 220endfunc 221 222func Test_breakindent07 () 223" breakindent set and shift by 1, Number set sbr=? and briopt:sbr 224call s: test_windows ( 'setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4 cpo+=n' ) 225let lines = s: screen_lines ( line ( '.' ), 10 ) 226let expect = [ 227 \" 2 ab" , 228 \"? m" , 229 \"? x" , 230 \] 231call s: compare_lines ( expect , lines ) 232" clean up 233call s: close_windows ( 'set sbr= cpo-=n' ) 234endfunc 235 236func Test_breakindent07_vartabs () 237if ! has ( "vartabs" ) 238return 239endif 240" breakindent set and shift by 1, Number set sbr=? and briopt:sbr 241call s: test_windows ( 'setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4 cpo+=n vts=4' ) 242let lines = s: screen_lines ( line ( '.' ), 10 ) 243let expect = [ 244 \" 2 ab" , 245 \"? m" , 246 \"? x" , 247 \] 248call s: compare_lines ( expect , lines ) 249" clean up 250call s: close_windows ( 'set sbr= cpo-=n vts&' ) 251endfunc 252 253func Test_breakindent07a () 254" breakindent set and shift by 1, Number set sbr=? and briopt:sbr 255call s: test_windows ( 'setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4' ) 256let lines = s: screen_lines ( line ( '.' ), 10 ) 257let expect = [ 258 \" 2 ab" , 259 \" ? m" , 260 \" ? x" , 261 \] 262call s: compare_lines ( expect , lines ) 263" clean up 264call s: close_windows ( 'set sbr=' ) 265endfunc 266 267func Test_breakindent07a_vartabs () 268if ! has ( "vartabs" ) 269return 270endif 271" breakindent set and shift by 1, Number set sbr=? and briopt:sbr 272call s: test_windows ( 'setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4 vts=4' ) 273let lines = s: screen_lines ( line ( '.' ), 10 ) 274let expect = [ 275 \" 2 ab" , 276 \" ? m" , 277 \" ? x" , 278 \] 279call s: compare_lines ( expect , lines ) 280" clean up 281call s: close_windows ( 'set sbr= vts&' ) 282endfunc 283 284func Test_breakindent08 () 285" breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr 286call s: test_windows ( 'setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list cpo+=n ts=4' ) 287" make sure, cache is invalidated! 288set ts = 8 289redraw ! 290set ts = 4 291redraw ! 292let lines = s: screen_lines ( line ( '.' ), 10 ) 293let expect = [ 294 \" 2 ^Iabcd" , 295 \"# opq" , 296 \"# BCD" , 297 \] 298call s: compare_lines ( expect , lines ) 299call s: close_windows ( 'set sbr= cpo-=n' ) 300endfunc 301 302func Test_breakindent08_vartabs () 303if ! has ( "vartabs" ) 304return 305endif 306" breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr 307call s: test_windows ( 'setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list cpo+=n ts=4 vts=4' ) 308" make sure, cache is invalidated! 309set ts = 8 310redraw ! 311set ts = 4 312redraw ! 313let lines = s: screen_lines ( line ( '.' ), 10 ) 314let expect = [ 315 \" 2 ^Iabcd" , 316 \"# opq" , 317 \"# BCD" , 318 \] 319call s: compare_lines ( expect , lines ) 320call s: close_windows ( 'set sbr= cpo-=n vts&' ) 321endfunc 322 323func Test_breakindent08a () 324" breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr 325call s: test_windows ( 'setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list' ) 326let lines = s: screen_lines ( line ( '.' ), 10 ) 327let expect = [ 328 \" 2 ^Iabcd" , 329 \" # opq" , 330 \" # BCD" , 331 \] 332call s: compare_lines ( expect , lines ) 333call s: close_windows ( 'set sbr=' ) 334endfunc 335 336func Test_breakindent08a_vartabs () 337if ! has ( "vartabs" ) 338return 339endif 340" breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr 341call s: test_windows ( 'setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list vts=4' ) 342let lines = s: screen_lines ( line ( '.' ), 10 ) 343let expect = [ 344 \" 2 ^Iabcd" , 345 \" # opq" , 346 \" # BCD" , 347 \] 348call s: compare_lines ( expect , lines ) 349call s: close_windows ( 'set sbr= vts&' ) 350endfunc 351 352func Test_breakindent09 () 353" breakindent set and shift by 1, Number and list set sbr=# 354call s: test_windows ( 'setl briopt=shift:1,min:0 nu nuw=4 sbr=# list' ) 355let lines = s: screen_lines ( line ( '.' ), 10 ) 356let expect = [ 357 \" 2 ^Iabcd" , 358 \" #op" , 359 \" #AB" , 360 \] 361call s: compare_lines ( expect , lines ) 362call s: close_windows ( 'set sbr=' ) 363endfunc 364 365func Test_breakindent09_vartabs () 366if ! has ( "vartabs" ) 367return 368endif 369" breakindent set and shift by 1, Number and list set sbr=# 370call s: test_windows ( 'setl briopt=shift:1,min:0 nu nuw=4 sbr=# list vts=4' ) 371let lines = s: screen_lines ( line ( '.' ), 10 ) 372let expect = [ 373 \" 2 ^Iabcd" , 374 \" #op" , 375 \" #AB" , 376 \] 377call s: compare_lines ( expect , lines ) 378call s: close_windows ( 'set sbr= vts&' ) 379endfunc 380 381func Test_breakindent10 () 382" breakindent set, Number set sbr=~ 383call s: test_windows ( 'setl cpo+=n sbr=~ nu nuw=4 nolist briopt=sbr,min:0' ) 384" make sure, cache is invalidated! 385set ts = 8 386redraw ! 387set ts = 4 388redraw ! 389let lines = s: screen_lines ( line ( '.' ), 10 ) 390let expect = [ 391 \" 2 ab" , 392 \"~ mn" , 393 \"~ yz" , 394 \] 395call s: compare_lines ( expect , lines ) 396call s: close_windows ( 'set sbr= cpo-=n' ) 397endfunc 398 399func Test_breakindent10_vartabs () 400if ! has ( "vartabs" ) 401return 402endif 403" breakindent set, Number set sbr=~ 404call s: test_windows ( 'setl cpo+=n sbr=~ nu nuw=4 nolist briopt=sbr,min:0 vts=4' ) 405" make sure, cache is invalidated! 406set ts = 8 407redraw ! 408set ts = 4 409redraw ! 410let lines = s: screen_lines ( line ( '.' ), 10 ) 411let expect = [ 412 \" 2 ab" , 413 \"~ mn" , 414 \"~ yz" , 415 \] 416call s: compare_lines ( expect , lines ) 417call s: close_windows ( 'set sbr= cpo-=n vts&' ) 418endfunc 419 420func Test_breakindent11 () 421" test strdisplaywidth() 422call s: test_windows ( 'setl cpo-=n sbr=>> nu nuw=4 nolist briopt= ts=4' ) 423let text = getline ( 2 ) 424let width = strlen ( text [ 1 :]) + indent ( 2 ) + strlen ( & sbr ) * 3 " text wraps 3 times 425call assert_equal ( width , strdisplaywidth ( text )) 426call s: close_windows ( 'set sbr=' ) 427call assert_equal ( 4 , strdisplaywidth ( "\t" , 4 )) 428endfunc 429 430func Test_breakindent11_vartabs () 431if ! has ( "vartabs" ) 432return 433endif 434" test strdisplaywidth() 435call s: test_windows ( 'setl cpo-=n sbr=>> nu nuw=4 nolist briopt= ts=4 vts=4' ) 436let text = getline ( 2 ) 437let width = strlen ( text [ 1 :]) + 2 ->indent () + strlen ( & sbr ) * 3 " text wraps 3 times 438call assert_equal ( width , text ->strdisplaywidth ()) 439call s: close_windows ( 'set sbr= vts&' ) 440endfunc 441 442func Test_breakindent12 () 443" test breakindent with long indent 444let s: input = "\t\t\t\t\t{" 445call s: test_windows ( 'setl breakindent linebreak briopt=min:10 nu numberwidth=3 ts=4 list listchars=tab:>-' ) 446let lines = s: screen_lines ( 2 , 16 ) 447let expect = [ 448 \" 2 >--->--->--->" , 449 \" ---{ " , 450 \"~ " , 451 \] 452call s: compare_lines ( expect , lines ) 453call s: close_windows ( 'set nuw=4 listchars&' ) 454endfunc 455 456func Test_breakindent12_vartabs () 457if ! has ( "vartabs" ) 458return 459endif 460" test breakindent with long indent 461let s: input = "\t\t\t\t\t{" 462call s: test_windows ( 'setl breakindent linebreak briopt=min:10 nu numberwidth=3 ts=4 list listchars=tab:>- vts=4' ) 463let lines = s: screen_lines ( 2 , 16 ) 464let expect = [ 465 \" 2 >--->--->--->" , 466 \" ---{ " , 467 \"~ " , 468 \] 469call s: compare_lines ( expect , lines ) 470call s: close_windows ( 'set nuw=4 listchars& vts&' ) 471endfunc 472 473func Test_breakindent13 () 474let s: input = "" 475call s: test_windows ( 'setl breakindent briopt=min:10 ts=8' ) 476vert resize 20 477call setline ( 1 , [ " a\tb\tc\td\te" , " z y x w v" ]) 4781 479norm ! fbgj"ayl 4802 481norm ! fygj"byl 482call assert_equal ( 'd' , @a) 483call assert_equal ( 'w' , @b) 484call s: close_windows () 485endfunc 486 487func Test_breakindent13_vartabs () 488if ! has ( "vartabs" ) 489return 490endif 491let s: input = "" 492call s: test_windows ( 'setl breakindent briopt=min:10 ts=8 vts=8' ) 493vert resize 20 494call setline ( 1 , [ " a\tb\tc\td\te" , " z y x w v" ]) 4951 496norm ! fbgj"ayl 4972 498norm ! fygj"byl 499call assert_equal ( 'd' , @a) 500call assert_equal ( 'w' , @b) 501call s: close_windows ( 'set vts&' ) 502endfunc 503 504func Test_breakindent14 () 505let s: input = "" 506call s: test_windows ( 'setl breakindent briopt= ts=8' ) 507vert resize 30 508norm ! 3a1234567890 509norm ! a abcde 510exec "norm! 0\<C-V>tex" 511let lines = s: screen_lines ( line ( '.' ), 8 ) 512let expect = [ 513 \"e " , 514 \"~ " , 515 \"~ " , 516 \] 517call s: compare_lines ( expect , lines ) 518call s: close_windows () 519endfunc 520 521func Test_breakindent14_vartabs () 522if ! has ( "vartabs" ) 523return 524endif 525let s: input = "" 526call s: test_windows ( 'setl breakindent briopt= ts=8 vts=8' ) 527vert resize 30 528norm ! 3a1234567890 529norm ! a abcde 530exec "norm! 0\<C-V>tex" 531let lines = s: screen_lines ( line ( '.' ), 8 ) 532let expect = [ 533 \"e " , 534 \"~ " , 535 \"~ " , 536 \] 537call s: compare_lines ( expect , lines ) 538call s: close_windows ( 'set vts&' ) 539endfunc 540 541func Test_breakindent15 () 542let s: input = "" 543call s: test_windows ( 'setl breakindent briopt= ts=8 sw=8' ) 544vert resize 30 545norm ! 4a1234567890 546exe "normal! >>\<C-V>3f0x" 547let lines = s: screen_lines ( line ( '.' ), 20 ) 548let expect = [ 549 \" 1234567890 " , 550 \"~ " , 551 \"~ " , 552 \] 553call s: compare_lines ( expect , lines ) 554call s: close_windows () 555endfunc 556 557func Test_breakindent15_vartabs () 558if ! has ( "vartabs" ) 559return 560endif 561let s: input = "" 562call s: test_windows ( 'setl breakindent briopt= ts=8 sw=8 vts=8' ) 563vert resize 30 564norm ! 4a1234567890 565exe "normal! >>\<C-V>3f0x" 566let lines = s: screen_lines ( line ( '.' ), 20 ) 567let expect = [ 568 \" 1234567890 " , 569 \"~ " , 570 \"~ " , 571 \] 572call s: compare_lines ( expect , lines ) 573call s: close_windows ( 'set vts&' ) 574endfunc 575 576func Test_breakindent16 () 577" Check that overlong lines are indented correctly. 578let s: input = "" 579call s: test_windows ( 'setl breakindent briopt=min:0 ts=4' ) 580call setline ( 1 , "\t" . repeat ( "1234567890" , 10 )) 581resize 6 582norm ! 1gg$ 583redraw ! 584let lines = s: screen_lines ( 1 , 10 ) 585let expect = [ 586 \"<<< 789012" , 587 \" 345678" , 588 \" 901234" , 589 \] 590call s: compare_lines ( expect , lines ) 591let lines = s: screen_lines ( 4 , 10 ) 592let expect = [ 593 \" 567890" , 594 \" 123456" , 595 \" 7890 " , 596 \] 597call s: compare_lines ( expect , lines ) 598call s: close_windows () 599endfunc 600 601func Test_breakindent16_vartabs () 602if ! has ( "vartabs" ) 603return 604endif 605" Check that overlong lines are indented correctly. 606let s: input = "" 607call s: test_windows ( 'setl breakindent briopt=min:0 ts=4 vts=4' ) 608call setline ( 1 , "\t" . repeat ( "1234567890" , 10 )) 609resize 6 610norm ! 1gg$ 611redraw ! 612let lines = s: screen_lines ( 1 , 10 ) 613let expect = [ 614 \"<<< 789012" , 615 \" 345678" , 616 \" 901234" , 617 \] 618call s: compare_lines ( expect , lines ) 619let lines = s: screen_lines ( 4 , 10 ) 620let expect = [ 621 \" 567890" , 622 \" 123456" , 623 \" 7890 " , 624 \] 625call s: compare_lines ( expect , lines ) 626call s: close_windows ( 'set vts&' ) 627endfunc 628 629func Test_breakindent17_vartabs () 630if ! has ( "vartabs" ) 631return 632endif 633let s: input = "" 634call s: test_windows ( 'setl breakindent list listchars=tab:<-> showbreak=+++' ) 635call setline ( 1 , "\t" . repeat ( 'a' , 63 )) 636vert resize 30 637norm ! 1gg$ 638redraw ! 639let lines = s: screen_lines ( 1 , 30 ) 640let expect = [ 641 \"<-->aaaaaaaaaaaaaaaaaaaaaaaaaa" , 642 \" +++aaaaaaaaaaaaaaaaaaaaaaa" , 643 \" +++aaaaaaaaaaaaaa " , 644 \] 645call s: compare_lines ( expect , lines ) 646call s: close_windows ( 'set breakindent& list& listchars& showbreak&' ) 647endfunc 648 649func Test_breakindent18_vartabs () 650if ! has ( "vartabs" ) 651return 652endif 653let s: input = "" 654call s: test_windows ( 'setl breakindent list listchars=tab:<->' ) 655call setline ( 1 , "\t" . repeat ( 'a' , 63 )) 656vert resize 30 657norm ! 1gg$ 658redraw ! 659let lines = s: screen_lines ( 1 , 30 ) 660let expect = [ 661 \"<-->aaaaaaaaaaaaaaaaaaaaaaaaaa" , 662 \" aaaaaaaaaaaaaaaaaaaaaaaaaa" , 663 \" aaaaaaaaaaa " , 664 \] 665call s: compare_lines ( expect , lines ) 666call s: close_windows ( 'set breakindent& list& listchars&' ) 667endfunc 668 669func Test_breakindent19_sbr_nextpage () 670let s: input = "" 671call s: test_windows ( 'setl breakindent briopt=shift:2,sbr,min:18 sbr=>' ) 672call setline ( 1 , repeat ( 'a' , 200 )) 673norm ! 1gg 674redraw ! 675let lines = s: screen_lines ( 1 , 20 ) 676let expect = [ 677 \"aaaaaaaaaaaaaaaaaaaa" , 678 \"> aaaaaaaaaaaaaaaaaa" , 679 \"> aaaaaaaaaaaaaaaaaa" , 680 \] 681call s: compare_lines ( expect , lines ) 682" Scroll down one screen line 683setl scrolloff = 5 684norm ! 5gj 685let lines = s: screen_lines ( 1 , 20 ) 686let expect = [ 687 \"aaaaaaaaaaaaaaaaaaaa" , 688 \"> aaaaaaaaaaaaaaaaaa" , 689 \"> aaaaaaaaaaaaaaaaaa" , 690 \] 691call s: compare_lines ( expect , lines ) 692redraw ! 693" moving the cursor doesn't change the text offset 694norm ! l 695redraw ! 696let lines = s: screen_lines ( 1 , 20 ) 697call s: compare_lines ( expect , lines ) 698 699setl breakindent briopt = min:18sbr = > 700norm ! 5gj 701let lines = s: screen_lines ( 1 , 20 ) 702let expect = [ 703 \">aaaaaaaaaaaaaaaaaaa" , 704 \">aaaaaaaaaaaaaaaaaaa" , 705 \">aaaaaaaaaaaaaaaaaaa" , 706 \] 707call s: compare_lines ( expect , lines ) 708call s: close_windows ( 'set breakindent& briopt& sbr&' ) 709endfunc 710 711func Test_breakindent20_cpo_n_nextpage () 712let s: input = "" 713call s: test_windows ( 'setl breakindent briopt=min:14 cpo+=n number' ) 714call setline ( 1 , repeat ( 'abcdefghijklmnopqrst' , 10 )) 715norm ! 1gg 716redraw ! 717let lines = s: screen_lines ( 1 , 20 ) 718let expect = [ 719 \" 1 abcdefghijklmnop" , 720 \" qrstabcdefghijkl" , 721 \" mnopqrstabcdefgh" , 722 \] 723call s: compare_lines ( expect , lines ) 724" Scroll down one screen line 725setl scrolloff = 5 726norm ! 6gj 727redraw ! 728let lines = s: screen_lines ( 1 , 20 ) 729let expect = [ 730 \"<<< qrstabcdefghijkl" , 731 \" mnopqrstabcdefgh" , 732 \" ijklmnopqrstabcd" , 733 \] 734call s: compare_lines ( expect , lines ) 735 736setl briopt += shift:2 737norm ! 1gg 738let lines = s: screen_lines ( 1 , 20 ) 739let expect = [ 740 \" 1 abcdefghijklmnop" , 741 \" qrstabcdefghij" , 742 \" klmnopqrstabcd" , 743 \] 744call s: compare_lines ( expect , lines ) 745" Scroll down one screen line 746norm ! 6gj 747let lines = s: screen_lines ( 1 , 20 ) 748let expect = [ 749 \"<<< qrstabcdefghij" , 750 \" klmnopqrstabcd" , 751 \" efghijklmnopqr" , 752 \] 753call s: compare_lines ( expect , lines ) 754 755call s: close_windows ( 'set breakindent& briopt& cpo& number&' ) 756endfunc 757 758func Test_breakindent20_list () 759call s: test_windows ( 'setl breakindent breakindentopt= linebreak' ) 760" default: 761call setline ( 1 , [ ' 1. Congress shall make no law' , 762 \' 2.) Congress shall make no law' , 763 \' 3.] Congress shall make no law' ]) 764norm ! 1gg 765redraw ! 766let lines = s: screen_lines2 ( 1 , 6 , 20 ) 767let expect = [ 768 \" 1. Congress " , 769 \"shall make no law " , 770 \" 2.) Congress " , 771 \"shall make no law " , 772 \" 3.] Congress " , 773 \"shall make no law " , 774 \] 775call s: compare_lines ( expect , lines ) 776" set minimum text width 777setl briopt = min:5 778redraw ! 779let lines = s: screen_lines2 ( 1 , 6 , 20 ) 780let expect = [ 781 \" 1. Congress " , 782 \" shall make no law " , 783 \" 2.) Congress " , 784 \" shall make no law " , 785 \" 3.] Congress " , 786 \" shall make no law " , 787 \] 788call s: compare_lines ( expect , lines ) 789" set additional handing indent 790setl briopt += list:4 791redraw ! 792let expect = [ 793 \" 1. Congress " , 794 \" shall make no " , 795 \" law " , 796 \" 2.) Congress " , 797 \" shall make no " , 798 \" law " , 799 \" 3.] Congress " , 800 \" shall make no " , 801 \" law " , 802 \] 803let lines = s: screen_lines2 ( 1 , 9 , 20 ) 804call s: compare_lines ( expect , lines ) 805 806" reset linebreak option 807" Note: it indents by one additional 808" space, because of the leading space. 809setl linebreak & vim list listchars = eol:$,space:_ 810redraw ! 811let expect = [ 812 \"__1.__Congress_shall" , 813 \" _make_no_law$ " , 814 \"__2.)_Congress_shall" , 815 \" _make_no_law$ " , 816 \"__3.]_Congress_shall" , 817 \" _make_no_law$ " , 818 \] 819let lines = s: screen_lines2 ( 1 , 6 , 20 ) 820call s: compare_lines ( expect , lines ) 821 822" check formatlistpat indent 823setl briopt = min:5,list:-1 824setl linebreak list & vim listchars & vim 825let & l: flp = '^\s*\d\+\.\?[\]:)}\t ]\s*' 826redraw ! 827let expect = [ 828 \" 1. Congress " , 829 \" shall make no " , 830 \" law " , 831 \" 2.) Congress " , 832 \" shall make no " , 833 \" law " , 834 \" 3.] Congress " , 835 \" shall make no " , 836 \" law " , 837 \] 838let lines = s: screen_lines2 ( 1 , 9 , 20 ) 839call s: compare_lines ( expect , lines ) 840 841" check with TABs 842call setline ( 1 , [ "\t1.\tCongress shall make no law" , 843 \"\t2.) Congress shall make no law" , 844 \"\t3.] Congress shall make no law" ]) 845setl tabstop = 4 list listchars = tab:<-> 846norm ! 1gg 847redraw ! 848let expect = [ 849 \"<-->1.<>Congress " , 850 \" shall make " , 851 \" no law " , 852 \"<-->2.) Congress " , 853 \" shall make " , 854 \" no law " , 855 \"<-->3.] Congress " , 856 \" shall make " , 857 \" no law " , 858 \] 859let lines = s: screen_lines2 ( 1 , 9 , 20 ) 860call s: compare_lines ( expect , lines ) 861 862setl tabstop = 2 nolist 863redraw ! 864let expect = [ 865 \" 1. Congress " , 866 \" shall make no " , 867 \" law " , 868 \" 2.) Congress " , 869 \" shall make no " , 870 \" law " , 871 \" 3.] Congress " , 872 \" shall make no " , 873 \" law " , 874 \] 875let lines = s: screen_lines2 ( 1 , 9 , 20 ) 876call s: compare_lines ( expect , lines ) 877 878setl tabstop & list listchars = space:_ 879redraw ! 880let expect = [ 881 \"^I1.^ICongress_ " , 882 \" shall_make_no_" , 883 \" law " , 884 \"^I2.)_Congress_ " , 885 \" shall_make_no_" , 886 \" law " , 887 \"^I3.]_Congress_ " , 888 \" shall_make_no_" , 889 \" law " , 890 \] 891let lines = s: screen_lines2 ( 1 , 9 , 20 ) 892call s: compare_lines ( expect , lines ) 893 894" check formatlistpat indent with different list levels 895let & l: flp = '^\s*\(\*\|•\)\+\s\+' 896setl list & vim listchars & vim 897 %delete _ 898call setline ( 1 , [ '* Congress shall make no law' , 899 \'••• Congress shall make no law' , 900 \'**** Congress shall make no law' ]) 901norm ! 1gg 902redraw ! 903let expect = [ 904 \"* Congress shall " , 905 \" make no law " , 906 \"••• Congress shall " , 907 \" make no law " , 908 \"**** Congress shall " , 909 \" make no law " , 910 \] 911let lines = s: screen_lines2 ( 1 , 6 , 20 ) 912call s: compare_lines ( expect , lines ) 913 914" check formatlistpat indent with different list level 915" showbreak and sbr 916setl briopt = min:5,sbr,list:-1 917setl showbreak = > 918redraw ! 919let expect = [ 920 \"* Congress shall " , 921 \"> make no law " , 922 \"••• Congress shall " , 923 \"> make no law " , 924 \"**** Congress shall " , 925 \"> make no law " , 926 \] 927let lines = s: screen_lines2 ( 1 , 6 , 20 ) 928call s: compare_lines ( expect , lines ) 929 930" check formatlistpat indent with different list level 931" showbreak sbr and shift 932setl briopt = min:5,sbr,list:-1,shift:2 933setl showbreak = > 934redraw ! 935let expect = [ 936 \"* Congress shall " , 937 \"> make no law " , 938 \"••• Congress shall " , 939 \"> make no law " , 940 \"**** Congress shall " , 941 \"> make no law " , 942 \] 943let lines = s: screen_lines2 ( 1 , 6 , 20 ) 944call s: compare_lines ( expect , lines ) 945 946" check breakindent works if breakindentopt=list:-1 947" for a non list content 948 %delete _ 949call setline ( 1 , [ ' Congress shall make no law' , 950 \' Congress shall make no law' , 951 \' Congress shall make no law' ]) 952norm ! 1gg 953setl briopt = min:5,list:-1 954setl showbreak = 955redraw ! 956let expect = [ 957 \" Congress shall " , 958 \" make no law " , 959 \" Congress shall " , 960 \" make no law " , 961 \" Congress shall " , 962 \" make no law " , 963 \] 964let lines = s: screen_lines2 ( 1 , 6 , 20 ) 965call s: compare_lines ( expect , lines ) 966 967call s: close_windows ( 'set breakindent& briopt& linebreak& list& listchars& showbreak&' ) 968endfunc 969 970" The following used to crash Vim. This is fixed by 8.2.3391. 971" This is a regression introduced by 8.2.2903. 972func Test_window_resize_with_linebreak () 973new 97453 vnew 975setl linebreak 976setl showbreak = >> 977setl breakindent 978setl breakindentopt = shift:4 979call setline ( 1 , "\naaaaaaaaa\n\na\naaaaa\n¯aaaaaaaaaa\naaaaaaaaaaaa\naaa\n\"a:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - aaaaaaaa\"\naaaaaaaa\n\"a" ) 980redraw ! 981call assert_equal ([ " >>aa^@\"a: " ], ScreenLines ( 2 , 14 )) 982vertical resize 52 983redraw ! 984call assert_equal ([ " >>aaa^@\"a:" ], ScreenLines ( 2 , 14 )) 985set linebreak & showbreak & breakindent & breakindentopt & 986 %bw ! 987endfunc 988 989func Test_cursor_position_with_showbreak () 990CheckScreendump 991 992let lines =<< trim END 993vim9script 994&signcolumn = 'yes' 995&showbreak = '++' 996&breakindentopt = 'shift:2' 997var leftcol: number = win_getid()->getwininfo()->get(0, {})->get('textoff') 998repeat('x', &columns - leftcol - 1)->setline(1) 999'second line'->setline(2) 1000END 1001call writefile ( lines , 'XscriptShowbreak' , 'D' ) 1002let buf = RunVimInTerminal ( '-S XscriptShowbreak' , #{ rows : 6 }) 1003 1004call term_sendkeys ( buf , "AX" ) 1005call VerifyScreenDump ( buf , 'Test_cursor_position_with_showbreak_1' , {}) 1006" No line wraps, so changing 'showbreak' should lead to the same screen. 1007call term_sendkeys ( buf , "\<C-\>\<C-O>:setlocal showbreak=+\<CR>" ) 1008call VerifyScreenDump ( buf , 'Test_cursor_position_with_showbreak_1' , {}) 1009" No line wraps, so setting 'breakindent' should lead to the same screen. 1010call term_sendkeys ( buf , "\<C-\>\<C-O>:setlocal breakindent\<CR>" ) 1011call VerifyScreenDump ( buf , 'Test_cursor_position_with_showbreak_1' , {}) 1012" The first line now wraps because of "eol" in 'listchars'. 1013call term_sendkeys ( buf , "\<C-\>\<C-O>:setlocal list\<CR>" ) 1014call VerifyScreenDump ( buf , 'Test_cursor_position_with_showbreak_2' , {}) 1015call term_sendkeys ( buf , "\<C-\>\<C-O>:setlocal nobreakindent\<CR>" ) 1016call VerifyScreenDump ( buf , 'Test_cursor_position_with_showbreak_3' , {}) 1017 1018call StopVimInTerminal ( buf ) 1019endfunc 1020 1021func Test_visual_starts_before_skipcol () 1022CheckScreendump 1023 1024let lines =<< trim END 10251new 1026setlocal breakindent 1027call setline(1, "\t" .. join(range(100))) 1028END 1029call writefile ( lines , 'XvisualStartsBeforeSkipcol' , 'D' ) 1030let buf = RunVimInTerminal ( '-S XvisualStartsBeforeSkipcol' , #{ rows : 6 }) 1031 1032call term_sendkeys ( buf , "v$" ) 1033call WaitForAssert ({ ->assert_match ( 'VISUAL.*\d' , term_getline ( buf , 6 ))}, 1000 ) 1034call VerifyScreenDump ( buf , 'Test_visual_starts_before_skipcol_1' , {}) 1035call term_sendkeys ( buf , "\<Esc>:setlocal showbreak=+++\<CR>gv" ) 1036call VerifyScreenDump ( buf , 'Test_visual_starts_before_skipcol_2' , {}) 1037call term_sendkeys ( buf , "\<Esc>:setlocal breakindentopt+=sbr\<CR>gv" ) 1038call VerifyScreenDump ( buf , 'Test_visual_starts_before_skipcol_3' , {}) 1039call term_sendkeys ( buf , "\<Esc>:setlocal nobreakindent\<CR>gv" ) 1040call VerifyScreenDump ( buf , 'Test_visual_starts_before_skipcol_4' , {}) 1041 1042call StopVimInTerminal ( buf ) 1043endfunc 1044 1045func Test_no_spurious_match () 1046let s: input = printf ( '- y %s y %s' , repeat ( 'x' , 50 ), repeat ( 'x' , 50 )) 1047call s: test_windows ( 'setl breakindent breakindentopt=list:-1 formatlistpat=^- hls' ) 1048let @/= '\%>3v[y]' 1049redraw ! 1050call searchcount (). total ->assert_equal ( 1 ) 1051 1052" cleanup 1053set hls & vim 1054bwipeout ! 1055endfunc 1056 1057func Test_no_extra_indent () 1058call s: test_windows ( 'setl breakindent breakindentopt=list:-1,min:10' ) 1059 %d 1060let & l: formatlistpat = '^\s*\d\+\.\s\+' 1061let text = 'word ' 1062let len = text ->strcharlen () 1063let line1 = text ->repeat (( winwidth ( 0 ) / len ) * 2 ) 1064let line2 = repeat ( ' ' , 2 ) .. '1. ' .. line1 1065call setline ( 1 , [ line2 ]) 1066redraw ! 1067" 1) matches formatlist pattern, so indent 1068let expect = [ 1069 \" 1. word word word " , 1070 \" word word word " , 1071 \" word word " , 1072 \"~ " , 1073 \] 1074let lines = s: screen_lines2 ( 1 , 4 , 20 ) 1075call s: compare_lines ( expect , lines ) 1076" 2) change formatlist pattern 1077" -> indent adjusted 1078let & l: formatlistpat = '^\s*\d\+\.' 1079let expect = [ 1080 \" 1. word word word " , 1081 \" word word word " , 1082 \" word word " , 1083 \"~ " , 1084 \] 1085let lines = s: screen_lines2 ( 1 , 4 , 20 ) 1086" 3) no local formatlist pattern, 1087" so use global one -> indent 1088let g_flp = & g: flp 1089let & g: formatlistpat = '^\s*\d\+\.\s\+' 1090let & l: formatlistpat = '' 1091let expect = [ 1092 \" 1. word word word " , 1093 \" word word word " , 1094 \" word word " , 1095 \"~ " , 1096 \] 1097let lines = s: screen_lines2 ( 1 , 4 , 20 ) 1098call s: compare_lines ( expect , lines ) 1099let & g: flp = g_flp 1100let & l: formatlistpat = '^\s*\d\+\.' 1101" 4) add something in front, no additional indent 1102norm ! gg0 1103exe ":norm! 5iword \<esc>" 1104redraw ! 1105let expect = [ 1106 \"word word word word " , 1107 \"word 1. word word " , 1108 \"word word word word " , 1109 \"word word " , 1110 \"~ " , 1111 \] 1112let lines = s: screen_lines2 ( 1 , 5 , 20 ) 1113call s: compare_lines ( expect , lines ) 1114bwipeout ! 1115endfunc 1116 1117func Test_breakindent_column () 1118call s: test_windows ( 'setl breakindent breakindentopt=column:10' ) 1119redraw ! 1120" 1) default: does not indent, too wide :( 1121let expect = [ 1122 \" " , 1123 \" abcdefghijklmnop" , 1124 \"qrstuvwxyzABCDEFGHIJ" , 1125 \"KLMNOP " 1126 \] 1127let lines = s: screen_lines2 ( 1 , 4 , 20 ) 1128call s: compare_lines ( expect , lines ) 1129" 2) lower min value, so that breakindent works 1130setl breakindentopt += min:5 1131redraw ! 1132let expect = [ 1133 \" " , 1134 \" abcdefghijklmnop" , 1135 \" qrstuvwxyz" , 1136 \" ABCDEFGHIJ" , 1137 \" KLMNOP " 1138 \] 1139let lines = s: screen_lines2 ( 1 , 5 , 20 ) 1140" 3) set shift option -> no influence 1141setl breakindentopt += shift:5 1142redraw ! 1143let expect = [ 1144 \" " , 1145 \" abcdefghijklmnop" , 1146 \" qrstuvwxyz" , 1147 \" ABCDEFGHIJ" , 1148 \" KLMNOP " 1149 \] 1150let lines = s: screen_lines2 ( 1 , 5 , 20 ) 1151call s: compare_lines ( expect , lines ) 1152" 4) add showbreak value 1153setl showbreak = ++ 1154redraw ! 1155let expect = [ 1156 \" " , 1157 \" abcdefghijklmnop" , 1158 \" ++qrstuvwx" , 1159 \" ++yzABCDEF" , 1160 \" ++GHIJKLMN" , 1161 \" ++OP " 1162 \] 1163let lines = s: screen_lines2 ( 1 , 6 , 20 ) 1164call s: compare_lines ( expect , lines ) 1165bwipeout ! 1166endfunc 1167 1168func Test_linebreak_list () 1169" This was setting wlv.c_extra to NUL while wlv.p_extra is NULL 1170filetype plugin on 1171syntax enable 1172edit ! $VIMRUNTIME/doc/index.txt 1173/ v_P 1174 1175setlocal list 1176setlocal listchars = tab:>- 1177setlocal linebreak 1178setlocal nowrap 1179setlocal filetype = help 1180redraw ! 1181 1182bwipe ! 1183endfunc 1184 1185func Test_breakindent_change_display_uhex () 1186call s: test_windows ( 'setl briopt=min:0 list listchars=eol:$' ) 1187redraw ! 1188let lines = s: screen_lines ( line ( '.' ), 20 ) 1189let expect = [ 1190 \"^Iabcdefghijklmnopqr" , 1191 \" stuvwxyzABCDEFGHIJ" , 1192 \" KLMNOP$ " 1193 \] 1194call s: compare_lines ( expect , lines ) 1195set display += uhex 1196redraw ! 1197let lines = s: screen_lines ( line ( '.' ), 20 ) 1198let expect = [ 1199 \"<09>abcdefghijklmnop" , 1200 \" qrstuvwxyzABCDEF" , 1201 \" GHIJKLMNOP$ " 1202 \] 1203call s: compare_lines ( expect , lines ) 1204set display & 1205 1206call s: close_windows () 1207endfunc 1208 1209func Test_breakindent_list_split () 121010 new 121161 vsplit 1212setlocal tabstop = 8 breakindent list listchars = tab:<->,eol:$ 1213put =s:input 121430 vsplit 1215setlocal listchars = eol:$ 1216let expect = [ 1217 \"^IabcdefghijklmnopqrstuvwxyzAB|<------>abcdefghijklmnopqrstuv" , 1218 \" CDEFGHIJKLMNOP$ | wxyzABCDEFGHIJKLMNOP$ " , 1219 \"~ |~ " 1220 \] 1221redraw ! 1222let lines = s: screen_lines ( line ( '.' ), 61 ) 1223call s: compare_lines ( expect , lines ) 1224wincmd p 1225redraw ! 1226let lines = s: screen_lines ( line ( '.' ), 61 ) 1227call s: compare_lines ( expect , lines ) 1228 1229bwipe ! 1230endfunc 1231 1232func Test_breakindent_min_with_signcol () 1233call s: test_windows ( 'setl briopt=min:15 signcolumn=yes' ) 1234redraw ! 1235let expect = [ 1236 \" abcdefghijklmn" , 1237 \" opqrstuvwxyzABC" , 1238 \" DEFGHIJKLMNOP " 1239 \] 1240let lines = s: screen_lines ( line ( '.' ), 20 ) 1241call s: compare_lines ( expect , lines ) 1242setl briopt = min:17 1243redraw ! 1244let expect = [ 1245 \" abcdefghijklmn" , 1246 \" opqrstuvwxyzABCDE" , 1247 \" FGHIJKLMNOP " 1248 \] 1249let lines = s: screen_lines ( line ( '.' ), 20 ) 1250call s: compare_lines ( expect , lines ) 1251setl briopt = min:19 1252redraw ! 1253let expect = [ 1254 \" abcdefghijklmn" , 1255 \" opqrstuvwxyzABCDEF" , 1256 \" GHIJKLMNOP " 1257 \] 1258let lines = s: screen_lines ( line ( '.' ), 20 ) 1259call s: compare_lines ( expect , lines ) 1260 1261call s: close_windows () 1262endfunc 1263 1264func Test_breakindent_with_double_width_wrap () 126550 vnew 1266setlocal tabstop = 8 breakindent nolist 1267call setline ( 1 , "\t" .. repeat ( 'a' , winwidth ( 0 ) - 9 ) .. '口口口' ) 1268normal ! $g0 1269call assert_equal ( 2 , winline ()) 1270call assert_equal ( 9 , wincol ()) 1271 1272bwipe ! 1273endfunc 1274 1275" vim: shiftwidth=2 sts=2 expandtab