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