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 cacheing gets in its way. 5" It helps to change the tabstop setting and force a redraw (e.g. see 6" Test_breakindent08()) 7if !exists('+breakindent') 8 finish 9endif 10 11source view_util.vim 12 13let s:input ="\tabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP" 14 15func s:screen_lines(lnum, width) abort 16 return ScreenLines([a:lnum, a:lnum + 2], a:width) 17endfunc 18 19func s:compare_lines(expect, actual) 20 call assert_equal(join(a:expect, "\n"), join(a:actual, "\n")) 21endfunc 22 23func s:test_windows(...) 24 call NewWindow(10, 20) 25 setl ts=4 sw=4 sts=4 breakindent 26 put =s:input 27 exe get(a:000, 0, '') 28endfunc 29 30func s:close_windows(...) 31 call CloseWindow() 32 exe get(a:000, 0, '') 33endfunc 34 35func Test_breakindent01() 36 " simple breakindent test 37 call s:test_windows('setl briopt=min:0') 38 let lines = s:screen_lines(line('.'),8) 39 let expect = [ 40 \ " abcd", 41 \ " qrst", 42 \ " GHIJ", 43 \ ] 44 call s:compare_lines(expect, lines) 45 call s:close_windows() 46endfunc 47 48func Test_breakindent01_vartabs() 49 " like 01 but with vartabs feature 50 if !has("vartabs") 51 return 52 endif 53 call s:test_windows('setl briopt=min:0 vts=4') 54 let lines = s:screen_lines(line('.'),8) 55 let expect = [ 56 \ " abcd", 57 \ " qrst", 58 \ " GHIJ", 59 \ ] 60 call s:compare_lines(expect, lines) 61 call s:close_windows('set vts&') 62endfunc 63 64func Test_breakindent02() 65 " simple breakindent test with showbreak set 66 call s:test_windows('setl briopt=min:0 sbr=>>') 67 let lines = s:screen_lines(line('.'),8) 68 let expect = [ 69 \ " abcd", 70 \ " >>qr", 71 \ " >>EF", 72 \ ] 73 call s:compare_lines(expect, lines) 74 call s:close_windows('set sbr=') 75endfunc 76 77func Test_breakindent02_vartabs() 78 if !has("vartabs") 79 return 80 endif 81 " simple breakindent test with showbreak set 82 call s:test_windows('setl briopt=min:0 sbr=>> vts=4') 83 let lines = s:screen_lines(line('.'),8) 84 let expect = [ 85 \ " abcd", 86 \ " >>qr", 87 \ " >>EF", 88 \ ] 89 call s:compare_lines(expect, lines) 90 call s:close_windows('set sbr= vts&') 91endfunc 92 93func Test_breakindent03() 94 " simple breakindent test with showbreak set and briopt including sbr 95 call s:test_windows('setl briopt=sbr,min:0 sbr=++') 96 let lines = s:screen_lines(line('.'),8) 97 let expect = [ 98 \ " abcd", 99 \ "++ qrst", 100 \ "++ GHIJ", 101 \ ] 102 call s:compare_lines(expect, lines) 103 " clean up 104 call s:close_windows('set sbr=') 105endfunc 106 107func Test_breakindent03_vartabs() 108 " simple breakindent test with showbreak set and briopt including sbr 109 if !has("vartabs") 110 return 111 endif 112 call s:test_windows('setl briopt=sbr,min:0 sbr=++ vts=4') 113 let lines = s:screen_lines(line('.'),8) 114 let expect = [ 115 \ " abcd", 116 \ "++ qrst", 117 \ "++ GHIJ", 118 \ ] 119 call s:compare_lines(expect, lines) 120 " clean up 121 call s:close_windows('set sbr= vts&') 122endfunc 123 124func Test_breakindent04() 125 " breakindent set with min width 18 126 call s:test_windows('setl sbr= briopt=min:18') 127 let lines = s:screen_lines(line('.'),8) 128 let expect = [ 129 \ " abcd", 130 \ " qrstuv", 131 \ " IJKLMN", 132 \ ] 133 call s:compare_lines(expect, lines) 134 " clean up 135 call s:close_windows('set sbr=') 136endfunc 137 138func Test_breakindent04_vartabs() 139 " breakindent set with min width 18 140 if !has("vartabs") 141 return 142 endif 143 call s:test_windows('setl sbr= briopt=min:18 vts=4') 144 let lines = s:screen_lines(line('.'),8) 145 let expect = [ 146 \ " abcd", 147 \ " qrstuv", 148 \ " IJKLMN", 149 \ ] 150 call s:compare_lines(expect, lines) 151 " clean up 152 call s:close_windows('set sbr= vts&') 153endfunc 154 155func Test_breakindent05() 156 " breakindent set and shift by 2 157 call s:test_windows('setl briopt=shift:2,min:0') 158 let lines = s:screen_lines(line('.'),8) 159 let expect = [ 160 \ " abcd", 161 \ " qr", 162 \ " EF", 163 \ ] 164 call s:compare_lines(expect, lines) 165 call s:close_windows() 166endfunc 167 168func Test_breakindent05_vartabs() 169 " breakindent set and shift by 2 170 if !has("vartabs") 171 return 172 endif 173 call s:test_windows('setl briopt=shift:2,min:0 vts=4') 174 let lines = s:screen_lines(line('.'),8) 175 let expect = [ 176 \ " abcd", 177 \ " qr", 178 \ " EF", 179 \ ] 180 call s:compare_lines(expect, lines) 181 call s:close_windows('set vts&') 182endfunc 183 184func Test_breakindent06() 185 " breakindent set and shift by -1 186 call s:test_windows('setl briopt=shift:-1,min:0') 187 let lines = s:screen_lines(line('.'),8) 188 let expect = [ 189 \ " abcd", 190 \ " qrstu", 191 \ " HIJKL", 192 \ ] 193 call s:compare_lines(expect, lines) 194 call s:close_windows() 195endfunc 196 197func Test_breakindent06_vartabs() 198 " breakindent set and shift by -1 199 if !has("vartabs") 200 return 201 endif 202 call s:test_windows('setl briopt=shift:-1,min:0 vts=4') 203 let lines = s:screen_lines(line('.'),8) 204 let expect = [ 205 \ " abcd", 206 \ " qrstu", 207 \ " HIJKL", 208 \ ] 209 call s:compare_lines(expect, lines) 210 call s:close_windows('set vts&') 211endfunc 212 213func Test_breakindent07() 214 " breakindent set and shift by 1, Number set sbr=? and briopt:sbr 215 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4 cpo+=n') 216 let lines = s:screen_lines(line('.'),10) 217 let expect = [ 218 \ " 2 ab", 219 \ "? m", 220 \ "? x", 221 \ ] 222 call s:compare_lines(expect, lines) 223 " clean up 224 call s:close_windows('set sbr= cpo-=n') 225endfunc 226 227func Test_breakindent07_vartabs() 228 if !has("vartabs") 229 return 230 endif 231 " breakindent set and shift by 1, Number set sbr=? and briopt:sbr 232 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4 cpo+=n vts=4') 233 let lines = s:screen_lines(line('.'),10) 234 let expect = [ 235 \ " 2 ab", 236 \ "? m", 237 \ "? x", 238 \ ] 239 call s:compare_lines(expect, lines) 240 " clean up 241 call s:close_windows('set sbr= cpo-=n vts&') 242endfunc 243 244func Test_breakindent07a() 245 " breakindent set and shift by 1, Number set sbr=? and briopt:sbr 246 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4') 247 let lines = s:screen_lines(line('.'),10) 248 let expect = [ 249 \ " 2 ab", 250 \ " ? m", 251 \ " ? x", 252 \ ] 253 call s:compare_lines(expect, lines) 254 " clean up 255 call s:close_windows('set sbr=') 256endfunc 257 258func Test_breakindent07a_vartabs() 259 if !has("vartabs") 260 return 261 endif 262 " breakindent set and shift by 1, Number set sbr=? and briopt:sbr 263 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4 vts=4') 264 let lines = s:screen_lines(line('.'),10) 265 let expect = [ 266 \ " 2 ab", 267 \ " ? m", 268 \ " ? x", 269 \ ] 270 call s:compare_lines(expect, lines) 271 " clean up 272 call s:close_windows('set sbr= vts&') 273endfunc 274 275func Test_breakindent08() 276 " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr 277 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list cpo+=n ts=4') 278 " make sure, cache is invalidated! 279 set ts=8 280 redraw! 281 set ts=4 282 redraw! 283 let lines = s:screen_lines(line('.'),10) 284 let expect = [ 285 \ " 2 ^Iabcd", 286 \ "# opq", 287 \ "# BCD", 288 \ ] 289 call s:compare_lines(expect, lines) 290 call s:close_windows('set sbr= cpo-=n') 291endfunc 292 293func Test_breakindent08_vartabs() 294 if !has("vartabs") 295 return 296 endif 297 " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr 298 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list cpo+=n ts=4 vts=4') 299 " make sure, cache is invalidated! 300 set ts=8 301 redraw! 302 set ts=4 303 redraw! 304 let lines = s:screen_lines(line('.'),10) 305 let expect = [ 306 \ " 2 ^Iabcd", 307 \ "# opq", 308 \ "# BCD", 309 \ ] 310 call s:compare_lines(expect, lines) 311 call s:close_windows('set sbr= cpo-=n vts&') 312endfunc 313 314func Test_breakindent08a() 315 " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr 316 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list') 317 let lines = s:screen_lines(line('.'),10) 318 let expect = [ 319 \ " 2 ^Iabcd", 320 \ " # opq", 321 \ " # BCD", 322 \ ] 323 call s:compare_lines(expect, lines) 324 call s:close_windows('set sbr=') 325endfunc 326 327func Test_breakindent08a_vartabs() 328 if !has("vartabs") 329 return 330 endif 331 " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr 332 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list vts=4') 333 let lines = s:screen_lines(line('.'),10) 334 let expect = [ 335 \ " 2 ^Iabcd", 336 \ " # opq", 337 \ " # BCD", 338 \ ] 339 call s:compare_lines(expect, lines) 340 call s:close_windows('set sbr= vts&') 341endfunc 342 343func Test_breakindent09() 344 " breakindent set and shift by 1, Number and list set sbr=# 345 call s:test_windows('setl briopt=shift:1,min:0 nu nuw=4 sbr=# list') 346 let lines = s:screen_lines(line('.'),10) 347 let expect = [ 348 \ " 2 ^Iabcd", 349 \ " #op", 350 \ " #AB", 351 \ ] 352 call s:compare_lines(expect, lines) 353 call s:close_windows('set sbr=') 354endfunc 355 356func Test_breakindent09_vartabs() 357 if !has("vartabs") 358 return 359 endif 360 " breakindent set and shift by 1, Number and list set sbr=# 361 call s:test_windows('setl briopt=shift:1,min:0 nu nuw=4 sbr=# list vts=4') 362 let lines = s:screen_lines(line('.'),10) 363 let expect = [ 364 \ " 2 ^Iabcd", 365 \ " #op", 366 \ " #AB", 367 \ ] 368 call s:compare_lines(expect, lines) 369 call s:close_windows('set sbr= vts&') 370endfunc 371 372func Test_breakindent10() 373 " breakindent set, Number set sbr=~ 374 call s:test_windows('setl cpo+=n sbr=~ nu nuw=4 nolist briopt=sbr,min:0') 375 " make sure, cache is invalidated! 376 set ts=8 377 redraw! 378 set ts=4 379 redraw! 380 let lines = s:screen_lines(line('.'),10) 381 let expect = [ 382 \ " 2 ab", 383 \ "~ mn", 384 \ "~ yz", 385 \ ] 386 call s:compare_lines(expect, lines) 387 call s:close_windows('set sbr= cpo-=n') 388endfunc 389 390func Test_breakindent10_vartabs() 391 if !has("vartabs") 392 return 393 endif 394 " breakindent set, Number set sbr=~ 395 call s:test_windows('setl cpo+=n sbr=~ nu nuw=4 nolist briopt=sbr,min:0 vts=4') 396 " make sure, cache is invalidated! 397 set ts=8 398 redraw! 399 set ts=4 400 redraw! 401 let lines = s:screen_lines(line('.'),10) 402 let expect = [ 403 \ " 2 ab", 404 \ "~ mn", 405 \ "~ yz", 406 \ ] 407 call s:compare_lines(expect, lines) 408 call s:close_windows('set sbr= cpo-=n vts&') 409endfunc 410 411func Test_breakindent11() 412 " test strdisplaywidth() 413 call s:test_windows('setl cpo-=n sbr=>> nu nuw=4 nolist briopt= ts=4') 414 let text = getline(2) 415 let width = strlen(text[1:])+indent(2)+strlen(&sbr)*3 " text wraps 3 times 416 call assert_equal(width, strdisplaywidth(text)) 417 call s:close_windows('set sbr=') 418endfunc 419 420func Test_breakindent11_vartabs() 421 if !has("vartabs") 422 return 423 endif 424 " test strdisplaywidth() 425 call s:test_windows('setl cpo-=n sbr=>> nu nuw=4 nolist briopt= ts=4 vts=4') 426 let text = getline(2) 427 let width = strlen(text[1:])+indent(2)+strlen(&sbr)*3 " text wraps 3 times 428 call assert_equal(width, strdisplaywidth(text)) 429 call s:close_windows('set sbr= vts&') 430endfunc 431 432func Test_breakindent12() 433 " test breakindent with long indent 434 let s:input = "\t\t\t\t\t{" 435 call s:test_windows('setl breakindent linebreak briopt=min:10 nu numberwidth=3 ts=4 list listchars=tab:>-') 436 let lines = s:screen_lines(2,16) 437 let expect = [ 438 \ " 2 >--->--->--->", 439 \ " ---{ ", 440 \ "~ ", 441 \ ] 442 call s:compare_lines(expect, lines) 443 call s:close_windows('set nuw=4 listchars=') 444endfunc 445 446func Test_breakindent12_vartabs() 447 if !has("vartabs") 448 return 449 endif 450 " test breakindent with long indent 451 let s:input = "\t\t\t\t\t{" 452 call s:test_windows('setl breakindent linebreak briopt=min:10 nu numberwidth=3 ts=4 list listchars=tab:>- vts=4') 453 let lines = s:screen_lines(2,16) 454 let expect = [ 455 \ " 2 >--->--->--->", 456 \ " ---{ ", 457 \ "~ ", 458 \ ] 459 call s:compare_lines(expect, lines) 460 call s:close_windows('set nuw=4 listchars= vts&') 461endfunc 462 463func Test_breakindent13() 464 let s:input = "" 465 call s:test_windows('setl breakindent briopt=min:10 ts=8') 466 vert resize 20 467 call setline(1, [" a\tb\tc\td\te", " z y x w v"]) 468 1 469 norm! fbgj"ayl 470 2 471 norm! fygj"byl 472 call assert_equal('d', @a) 473 call assert_equal('w', @b) 474 call s:close_windows() 475endfunc 476 477func Test_breakindent13_vartabs() 478 if !has("vartabs") 479 return 480 endif 481 let s:input = "" 482 call s:test_windows('setl breakindent briopt=min:10 ts=8 vts=8') 483 vert resize 20 484 call setline(1, [" a\tb\tc\td\te", " z y x w v"]) 485 1 486 norm! fbgj"ayl 487 2 488 norm! fygj"byl 489 call assert_equal('d', @a) 490 call assert_equal('w', @b) 491 call s:close_windows('set vts&') 492endfunc 493 494func Test_breakindent14() 495 let s:input = "" 496 call s:test_windows('setl breakindent briopt= ts=8') 497 vert resize 30 498 norm! 3a1234567890 499 norm! a abcde 500 exec "norm! 0\<C-V>tex" 501 let lines = s:screen_lines(line('.'),8) 502 let expect = [ 503 \ "e ", 504 \ "~ ", 505 \ "~ ", 506 \ ] 507 call s:compare_lines(expect, lines) 508 call s:close_windows() 509endfunc 510 511func Test_breakindent14_vartabs() 512 if !has("vartabs") 513 return 514 endif 515 let s:input = "" 516 call s:test_windows('setl breakindent briopt= ts=8 vts=8') 517 vert resize 30 518 norm! 3a1234567890 519 norm! a abcde 520 exec "norm! 0\<C-V>tex" 521 let lines = s:screen_lines(line('.'),8) 522 let expect = [ 523 \ "e ", 524 \ "~ ", 525 \ "~ ", 526 \ ] 527 call s:compare_lines(expect, lines) 528 call s:close_windows('set vts&') 529endfunc 530 531func Test_breakindent15() 532 let s:input = "" 533 call s:test_windows('setl breakindent briopt= ts=8 sw=8') 534 vert resize 30 535 norm! 4a1234567890 536 exe "normal! >>\<C-V>3f0x" 537 let lines = s:screen_lines(line('.'),20) 538 let expect = [ 539 \ " 1234567890 ", 540 \ "~ ", 541 \ "~ ", 542 \ ] 543 call s:compare_lines(expect, lines) 544 call s:close_windows() 545endfunc 546 547func Test_breakindent15_vartabs() 548 if !has("vartabs") 549 return 550 endif 551 let s:input = "" 552 call s:test_windows('setl breakindent briopt= ts=8 sw=8 vts=8') 553 vert resize 30 554 norm! 4a1234567890 555 exe "normal! >>\<C-V>3f0x" 556 let lines = s:screen_lines(line('.'),20) 557 let expect = [ 558 \ " 1234567890 ", 559 \ "~ ", 560 \ "~ ", 561 \ ] 562 call s:compare_lines(expect, lines) 563 call s:close_windows('set vts&') 564endfunc 565 566func Test_breakindent16() 567 " Check that overlong lines are indented correctly. 568 let s:input = "" 569 call s:test_windows('setl breakindent briopt=min:0 ts=4') 570 call setline(1, "\t".repeat("1234567890", 10)) 571 resize 6 572 norm! 1gg$ 573 redraw! 574 let lines = s:screen_lines(1,10) 575 let expect = [ 576 \ " 789012", 577 \ " 345678", 578 \ " 901234", 579 \ ] 580 call s:compare_lines(expect, lines) 581 let lines = s:screen_lines(4,10) 582 let expect = [ 583 \ " 567890", 584 \ " 123456", 585 \ " 7890 ", 586 \ ] 587 call s:compare_lines(expect, lines) 588 call s:close_windows() 589endfunc 590 591func Test_breakindent16_vartabs() 592 if !has("vartabs") 593 return 594 endif 595 " Check that overlong lines are indented correctly. 596 let s:input = "" 597 call s:test_windows('setl breakindent briopt=min:0 ts=4 vts=4') 598 call setline(1, "\t".repeat("1234567890", 10)) 599 resize 6 600 norm! 1gg$ 601 redraw! 602 let lines = s:screen_lines(1,10) 603 let expect = [ 604 \ " 789012", 605 \ " 345678", 606 \ " 901234", 607 \ ] 608 call s:compare_lines(expect, lines) 609 let lines = s:screen_lines(4,10) 610 let expect = [ 611 \ " 567890", 612 \ " 123456", 613 \ " 7890 ", 614 \ ] 615 call s:compare_lines(expect, lines) 616 call s:close_windows('set vts&') 617endfunc 618