display_spec.lua (23758B)
1 local n = require('test.functional.testnvim')() 2 local Screen = require('test.functional.ui.screen') 3 4 local clear = n.clear 5 local exec = n.exec 6 local feed = n.feed 7 local command = n.command 8 9 describe('display', function() 10 before_each(clear) 11 12 -- oldtest: Test_display_scroll_at_topline() 13 it('scroll when modified at topline vim-patch:8.2.1488', function() 14 local screen = Screen.new(20, 4) 15 command([[call setline(1, repeat('a', 21))]]) 16 feed('O') 17 screen:expect([[ 18 ^ | 19 aaaaaaaaaaaaaaaaaaaa| 20 a | 21 {5:-- INSERT --} | 22 ]]) 23 end) 24 25 -- oldtest: Test_display_scroll_update_visual() 26 it('scrolling when modified at topline in Visual mode vim-patch:8.2.4626', function() 27 local screen = Screen.new(60, 8) 28 exec([[ 29 set scrolloff=0 30 call setline(1, repeat(['foo'], 10)) 31 call sign_define('foo', { 'text': '>' }) 32 call sign_place(1, 'bar', 'foo', bufnr(), { 'lnum': 2 }) 33 call sign_place(2, 'bar', 'foo', bufnr(), { 'lnum': 1 }) 34 autocmd CursorMoved * if getcurpos()[1] == 2 | call sign_unplace('bar', { 'id': 1 }) | endif 35 ]]) 36 feed('VG7kk') 37 screen:expect([[ 38 {7: }^f{17:oo} | 39 {7: }foo |*6 40 {5:-- VISUAL LINE --} | 41 ]]) 42 end) 43 44 -- oldtest: Test_display_scroll_setline() 45 it('scrolling with sign_unplace() and setline() in CursorMoved', function() 46 local screen = Screen.new(20, 15) 47 exec([[ 48 setlocal scrolloff=5 signcolumn=yes 49 call setline(1, range(1, 100)) 50 call sign_define('foo', #{text: '>'}) 51 call sign_place(1, 'bar', 'foo', bufnr(), #{lnum: 71}) 52 call sign_place(2, 'bar', 'foo', bufnr(), #{lnum: 72}) 53 call sign_place(3, 'bar', 'foo', bufnr(), #{lnum: 73}) 54 call sign_place(4, 'bar', 'foo', bufnr(), #{lnum: 74}) 55 call sign_place(5, 'bar', 'foo', bufnr(), #{lnum: 75}) 56 normal! G 57 autocmd CursorMoved * if line('.') == 79 58 \ | call sign_unplace('bar', #{id: 4}) 59 \ | call setline(80, repeat('foo', 15)) 60 \ | elseif line('.') == 78 61 \ | call setline(72, repeat('bar', 10)) 62 \ | elseif line('.') == 77 63 \ | call sign_unplace('bar', #{id: 2}) 64 \ | endif 65 ]]) 66 screen:expect([[ 67 {7: }87 | 68 {7: }88 | 69 {7: }89 | 70 {7: }90 | 71 {7: }91 | 72 {7: }92 | 73 {7: }93 | 74 {7: }94 | 75 {7: }95 | 76 {7: }96 | 77 {7: }97 | 78 {7: }98 | 79 {7: }99 | 80 {7: }^100 | 81 | 82 ]]) 83 feed('19k') 84 screen:expect([[ 85 {7:> }75 | 86 {7: }76 | 87 {7: }77 | 88 {7: }78 | 89 {7: }79 | 90 {7: }80 | 91 {7: }^81 | 92 {7: }82 | 93 {7: }83 | 94 {7: }84 | 95 {7: }85 | 96 {7: }86 | 97 {7: }87 | 98 {7: }88 | 99 | 100 ]]) 101 feed('k') 102 screen:expect([[ 103 {7:> }75 | 104 {7: }76 | 105 {7: }77 | 106 {7: }78 | 107 {7: }79 | 108 {7: }^80 | 109 {7: }81 | 110 {7: }82 | 111 {7: }83 | 112 {7: }84 | 113 {7: }85 | 114 {7: }86 | 115 {7: }87 | 116 {7: }88 | 117 | 118 ]]) 119 feed('k') 120 screen:expect([[ 121 {7: }74 | 122 {7:> }75 | 123 {7: }76 | 124 {7: }77 | 125 {7: }78 | 126 {7: }^79 | 127 {7: }foofoofoofoofoofoo|*2 128 {7: }foofoofoo | 129 {7: }81 | 130 {7: }82 | 131 {7: }83 | 132 {7: }84 | 133 {7: }85 | 134 | 135 ]]) 136 feed('k') 137 screen:expect([[ 138 {7:> }73 | 139 {7: }74 | 140 {7:> }75 | 141 {7: }76 | 142 {7: }77 | 143 {7: }^78 | 144 {7: }79 | 145 {7: }foofoofoofoofoofoo|*2 146 {7: }foofoofoo | 147 {7: }81 | 148 {7: }82 | 149 {7: }83 | 150 {7: }84 | 151 | 152 ]]) 153 feed('k') 154 screen:expect([[ 155 {7: }barbarbarbarbarbar| 156 {7: }barbarbarbar | 157 {7:> }73 | 158 {7: }74 | 159 {7:> }75 | 160 {7: }76 | 161 {7: }^77 | 162 {7: }78 | 163 {7: }79 | 164 {7: }foofoofoofoofoofoo|*2 165 {7: }foofoofoo | 166 {7: }81 | 167 {7: }82 | 168 | 169 ]]) 170 end) 171 172 -- oldtest: Test_display_hit_enter_setline() 173 it('using setline() at hit-enter prompt', function() 174 local screen = Screen.new(40, 8) 175 exec([[ 176 call setline(1, range(1, 100)) 177 ]]) 178 screen:expect([[ 179 ^1 | 180 2 | 181 3 | 182 4 | 183 5 | 184 6 | 185 7 | 186 | 187 ]]) 188 feed([[:echo "abc\ndef\nghi"<CR>]]) 189 screen:expect([[ 190 1 | 191 2 | 192 3 | 193 {3: }| 194 abc | 195 def | 196 ghi | 197 {6:Press ENTER or type command to continue}^ | 198 ]]) 199 feed([[:call setline(2, repeat('foo', 35))<CR>]]) 200 screen:expect([[ 201 ^1 | 202 foofoofoofoofoofoofoofoofoofoofoofoofoof| 203 oofoofoofoofoofoofoofoofoofoofoofoofoofo| 204 ofoofoofoofoofoofoofoofoo | 205 3 | 206 4 | 207 5 | 208 | 209 ]]) 210 end) 211 212 local function run_test_display_lastline(euro) 213 local screen = Screen.new(75, 10) 214 exec([[ 215 call setline(1, ['aaa', 'b'->repeat(200)]) 216 set display=truncate 217 218 vsplit 219 100wincmd < 220 ]]) 221 local fillchar = '@' 222 if euro then 223 command('set fillchars=lastline:€') 224 fillchar = '€' 225 end 226 screen:expect((([[ 227 ^a│aaa | 228 a│bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|*2 229 b│bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb | 230 b│{1:~ }|*3 231 {1:@}│{1:~ }| 232 {3:< }{2:[No Name] [+] }| 233 | 234 ]]):gsub('@', fillchar))) 235 236 command('set display=lastline') 237 screen:expect_unchanged() 238 239 command('100wincmd >') 240 screen:expect((([[ 241 ^aaa │a| 242 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb│a|*2 243 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb │b| 244 {1:~ }│b|*3 245 {1:~ }│{1:@}| 246 {3:[No Name] [+] }{2:<}| 247 | 248 ]]):gsub('@', fillchar))) 249 250 command('set display=truncate') 251 screen:expect_unchanged() 252 253 command('close') 254 command('3split') 255 screen:expect((([[ 256 ^aaa | 257 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb| 258 {1:@@@ }| 259 {3:[No Name] [+] }| 260 aaa | 261 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|*2 262 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb | 263 {2:[No Name] [+] }| 264 | 265 ]]):gsub('@', fillchar))) 266 267 command('close') 268 command('2vsplit') 269 screen:expect((([[ 270 ^aa│aaa | 271 a │bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb| 272 bb│bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb| 273 bb│bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb | 274 bb│{1:~ }|*3 275 {1:@@}│{1:~ }| 276 {3:< }{2:[No Name] [+] }| 277 | 278 ]]):gsub('@', fillchar))) 279 end 280 281 -- oldtest: Test_display_lastline() 282 it('display "lastline" works correctly', function() 283 run_test_display_lastline() 284 end) 285 it('display "lastline" works correctly with multibyte fillchar', function() 286 run_test_display_lastline(true) 287 end) 288 289 -- oldtest: Test_display_long_lastline() 290 it('"lastline" shows correct text when end of wrapped line is deleted', function() 291 local screen = Screen.new(35, 14) 292 exec([[ 293 set display=lastline smoothscroll scrolloff=0 294 call setline(1, [ 295 \'aaaaa'->repeat(150), 296 \'bbbbb '->repeat(7) .. 'ccccc '->repeat(7) .. 'ddddd '->repeat(7) 297 \]) 298 ]]) 299 feed('736|') 300 screen:expect([[ 301 {1:<<<}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| 302 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|*11 303 ^aaaaaaaaaaaaaaa | 304 | 305 ]]) 306 -- The correct part of the last line is moved into view. 307 feed('D') 308 screen:expect([[ 309 {1:<<<}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| 310 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|*10 311 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa^a| 312 bbbbb bbbbb bbbbb bbbbb bbbbb bb{1:@@@}| 313 | 314 ]]) 315 -- "w_skipcol" does not change because the topline is still long enough 316 -- to maintain the current skipcol. 317 feed('g04l11gkD') 318 screen:expect([[ 319 {1:<<<}^a | 320 bbbbb bbbbb bbbbb bbbbb bbbbb bbbbb| 321 bbbbb ccccc ccccc ccccc ccccc cccc| 322 c ccccc ccccc ddddd ddddd ddddd ddd| 323 dd ddddd ddddd ddddd | 324 {1:~ }|*8 325 | 326 ]]) 327 -- "w_skipcol" is reset to bring the entire topline into view because 328 -- the line length is now smaller than the current skipcol + marker. 329 feed('x') 330 screen:expect([[ 331 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|*9 332 aa^a | 333 bbbbb bbbbb bbbbb bbbbb bbbbb bbbbb| 334 bbbbb ccccc ccccc ccccc ccccc cccc| 335 c ccccc ccccc ddddd ddddd ddddd {1:@@@}| 336 | 337 ]]) 338 end) 339 340 -- oldtest: Test_display_cursor_long_line() 341 it("correctly shows line that doesn't fit in the window", function() 342 local screen = Screen.new(75, 8) 343 exec([[ 344 call setline(1, ['a', 'b ' .. 'bbbbb'->repeat(150), 'c']) 345 norm $j 346 ]]) 347 screen:expect([[ 348 {1:<<<}bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb| 349 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|*5 350 b^b | 351 | 352 ]]) 353 -- FIXME: moving the cursor above the topline does not set w_skipcol 354 -- correctly with cpo+=n and zero scrolloff (curs_columns() extra == 1). 355 exec('set number cpo+=n scrolloff=0') 356 feed('$0') 357 screen:expect([[ 358 {1:<<<}b^bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb| 359 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|*6 360 | 361 ]]) 362 -- Going to the start of the line with "b" did not set w_skipcol correctly with 'smoothscroll'. 363 exec('set smoothscroll') 364 feed('$b') 365 screen:expect([[ 366 {8: 2 }b ^bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb| 367 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|*6 368 | 369 ]]) 370 -- Same for "ge". 371 feed('$ge') 372 screen:expect([[ 373 {8: 2 }^b bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb| 374 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|*6 375 | 376 ]]) 377 end) 378 379 -- oldtest: Test_change_wrapped_line_cpo_dollar() 380 it('changing wrapped line with cpo+=$', function() 381 local screen = Screen.new(45, 10) 382 exec([[ 383 set cpoptions+=$ laststatus=0 384 call setline(1, ['foo', 'bar', 385 \ repeat('x', 25) .. '!!()!!' .. repeat('y', 25), 386 \ 'FOO', 'BAR']) 387 inoremap <F2> <Cmd>call setline(1, repeat('z', 30))<CR> 388 inoremap <F3> <Cmd>call setline(1, 'foo')<CR> 389 vsplit 390 call cursor(3, 1) 391 ]]) 392 393 local s1 = [[ 394 foo │foo | 395 bar │bar | 396 ^xxxxxxxxxxxxxxxxxxxxxx│xxxxxxxxxxxxxxxxxxxxxx| 397 xxx!!()!!yyyyyyyyyyyyy│xxx!!()!!yyyyyyyyyyyyy| 398 yyyyyyyyyyyy │yyyyyyyyyyyy | 399 FOO │FOO | 400 BAR │BAR | 401 {1:~ }│{1:~ }|*2 402 | 403 ]] 404 screen:expect(s1) 405 feed('ct!') 406 local s2 = [[ 407 foo │foo | 408 bar │bar | 409 ^xxxxxxxxxxxxxxxxxxxxxx│!!()!!yyyyyyyyyyyyyyyy| 410 xx$!!()!!yyyyyyyyyyyyy│yyyyyyyyy | 411 yyyyyyyyyyyy │FOO | 412 FOO │BAR | 413 BAR │{1:~ }| 414 {1:~ }│{1:~ }|*2 415 {5:-- INSERT --} | 416 ]] 417 screen:expect(s2) 418 feed('<F2>') 419 screen:expect([[ 420 zzzzzzzzzzzzzzzzzzzzzz│zzzzzzzzzzzzzzzzzzzzzz| 421 zzzzzzzz │zzzzzzzz | 422 bar │bar | 423 ^xxxxxxxxxxxxxxxxxxxxxx│!!()!!yyyyyyyyyyyyyyyy| 424 xx$!!()!!yyyyyyyyyyyyy│yyyyyyyyy | 425 yyyyyyyyyyyy │FOO | 426 FOO │BAR | 427 BAR │{1:~ }| 428 {1:~ }│{1:~ }| 429 {5:-- INSERT --} | 430 ]]) 431 feed('<F3>') 432 screen:expect(s2) 433 feed('y') 434 screen:expect([[ 435 foo │foo | 436 bar │bar | 437 y^xxxxxxxxxxxxxxxxxxxxx│y!!()!!yyyyyyyyyyyyyyy| 438 xx$!!()!!yyyyyyyyyyyyy│yyyyyyyyyy | 439 yyyyyyyyyyyy │FOO | 440 FOO │BAR | 441 BAR │{1:~ }| 442 {1:~ }│{1:~ }|*2 443 {5:-- INSERT --} | 444 ]]) 445 feed('y') 446 screen:expect([[ 447 foo │foo | 448 bar │bar | 449 yy^xxxxxxxxxxxxxxxxxxxx│yy!!()!!yyyyyyyyyyyyyy| 450 xx$!!()!!yyyyyyyyyyyyy│yyyyyyyyyyy | 451 yyyyyyyyyyyy │FOO | 452 FOO │BAR | 453 BAR │{1:~ }| 454 {1:~ }│{1:~ }|*2 455 {5:-- INSERT --} | 456 ]]) 457 feed('<Esc>') 458 screen:expect([[ 459 foo │foo | 460 bar │bar | 461 y^y!!()!!yyyyyyyyyyyyyy│yy!!()!!yyyyyyyyyyyyyy| 462 yyyyyyyyyyy │yyyyyyyyyyy | 463 FOO │FOO | 464 BAR │BAR | 465 {1:~ }│{1:~ }|*3 466 | 467 ]]) 468 469 command('silent undo') 470 screen:expect(s1) 471 command('source test/old/testdir/samples/matchparen.vim') 472 feed('ct(') 473 screen:expect([[ 474 foo │foo | 475 bar │bar | 476 ^xxxxxxxxxxxxxxxxxxxxxx│()!!yyyyyyyyyyyyyyyyyy| 477 xxx!$()!!yyyyyyyyyyyyy│yyyyyyy | 478 yyyyyyyyyyyy │FOO | 479 FOO │BAR | 480 BAR │{1:~ }| 481 {1:~ }│{1:~ }|*2 482 {5:-- INSERT --} | 483 ]]) 484 feed('y') 485 screen:expect([[ 486 foo │foo | 487 bar │bar | 488 y^xxxxxxxxxxxxxxxxxxxxx│y()!!yyyyyyyyyyyyyyyyy| 489 xxx!$()!!yyyyyyyyyyyyy│yyyyyyyy | 490 yyyyyyyyyyyy │FOO | 491 FOO │BAR | 492 BAR │{1:~ }| 493 {1:~ }│{1:~ }|*2 494 {5:-- INSERT --} | 495 ]]) 496 feed('y') 497 screen:expect([[ 498 foo │foo | 499 bar │bar | 500 yy^xxxxxxxxxxxxxxxxxxxx│yy()!!yyyyyyyyyyyyyyyy| 501 xxx!$()!!yyyyyyyyyyyyy│yyyyyyyyy | 502 yyyyyyyyyyyy │FOO | 503 FOO │BAR | 504 BAR │{1:~ }| 505 {1:~ }│{1:~ }|*2 506 {5:-- INSERT --} | 507 ]]) 508 feed('<Esc>') 509 screen:expect([[ 510 foo │foo | 511 bar │bar | 512 y^y()!!yyyyyyyyyyyyyyyy│yy()!!yyyyyyyyyyyyyyyy| 513 yyyyyyyyy │yyyyyyyyy | 514 FOO │FOO | 515 BAR │BAR | 516 {1:~ }│{1:~ }|*3 517 | 518 ]]) 519 520 command('silent undo') 521 screen:expect(s1) 522 feed('f(azz<CR>zz<Esc>k0') 523 screen:expect([[ 524 foo │foo | 525 bar │bar | 526 ^xxxxxxxxxxxxxxxxxxxxxx│xxxxxxxxxxxxxxxxxxxxxx| 527 xxx!!(zz │xxx!!(zz | 528 zz)!!yyyyyyyyyyyyyyyyy│zz)!!yyyyyyyyyyyyyyyyy| 529 yyyyyyyy │yyyyyyyy | 530 FOO │FOO | 531 BAR │BAR | 532 {1:~ }│{1:~ }| 533 | 534 ]]) 535 feed('ct(') 536 screen:expect([[ 537 foo │foo | 538 bar │bar | 539 ^xxxxxxxxxxxxxxxxxxxxxx│(zz | 540 xxx!$(zz │zz)!!yyyyyyyyyyyyyyyyy| 541 zz)!!yyyyyyyyyyyyyyyyy│yyyyyyyy | 542 yyyyyyyy │FOO | 543 FOO │BAR | 544 BAR │{1:~ }| 545 {1:~ }│{1:~ }| 546 {5:-- INSERT --} | 547 ]]) 548 feed('y') 549 screen:expect([[ 550 foo │foo | 551 bar │bar | 552 y^xxxxxxxxxxxxxxxxxxxxx│y(zz | 553 xxx!$(zz │zz)!!yyyyyyyyyyyyyyyyy| 554 zz)!!yyyyyyyyyyyyyyyyy│yyyyyyyy | 555 yyyyyyyy │FOO | 556 FOO │BAR | 557 BAR │{1:~ }| 558 {1:~ }│{1:~ }| 559 {5:-- INSERT --} | 560 ]]) 561 feed('y') 562 screen:expect([[ 563 foo │foo | 564 bar │bar | 565 yy^xxxxxxxxxxxxxxxxxxxx│yy(zz | 566 xxx!$(zz │zz)!!yyyyyyyyyyyyyyyyy| 567 zz)!!yyyyyyyyyyyyyyyyy│yyyyyyyy | 568 yyyyyyyy │FOO | 569 FOO │BAR | 570 BAR │{1:~ }| 571 {1:~ }│{1:~ }| 572 {5:-- INSERT --} | 573 ]]) 574 feed('<Esc>') 575 screen:expect([[ 576 foo │foo | 577 bar │bar | 578 y^y(zz │yy(zz | 579 zz)!!yyyyyyyyyyyyyyyyy│zz)!!yyyyyyyyyyyyyyyyy| 580 yyyyyyyy │yyyyyyyy | 581 FOO │FOO | 582 BAR │BAR | 583 {1:~ }│{1:~ }|*2 584 | 585 ]]) 586 end) 587 end)