1" Tests for window cmd (:wincmd, :split, :vsplit, :resize and etc...) 2 3so check.vim 4 5func Test_window_cmd_ls0_with_split() 6 set ls=0 7 set splitbelow 8 split 9 quit 10 call assert_equal(0, &lines - &cmdheight - winheight(0)) 11 new | only! 12 " 13 set splitbelow&vim 14 botright split 15 quit 16 call assert_equal(0, &lines - &cmdheight - winheight(0)) 17 new | only! 18 set ls&vim 19endfunc 20 21func Test_window_cmd_cmdwin_with_vsp() 22 let efmt = 'Expected 0 but got %d (in ls=%d, %s window)' 23 for v in range(0, 2) 24 exec "set ls=" . v 25 vsplit 26 call feedkeys("q:\<CR>") 27 let ac = &lines - (&cmdheight + winheight(0) + !!v) 28 let emsg = printf(efmt, ac, v, 'left') 29 call assert_equal(0, ac, emsg) 30 wincmd w 31 let ac = &lines - (&cmdheight + winheight(0) + !!v) 32 let emsg = printf(efmt, ac, v, 'right') 33 call assert_equal(0, ac, emsg) 34 new | only! 35 endfor 36 set ls&vim 37endfunc 38 39function Test_window_cmd_wincmd_gf() 40 let fname = 'test_gf.txt' 41 let swp_fname = '.' . fname . '.swp' 42 call writefile([], fname) 43 call writefile([], swp_fname) 44 function s:swap_exists() 45 let v:swapchoice = s:swap_choice 46 endfunc 47 " Remove the catch-all that runtest.vim adds 48 au! SwapExists 49 augroup test_window_cmd_wincmd_gf 50 autocmd! 51 exec "autocmd SwapExists " . fname . " call s:swap_exists()" 52 augroup END 53 54 call setline(1, fname) 55 " (E)dit anyway 56 let s:swap_choice = 'e' 57 wincmd gf 58 call assert_equal(2, tabpagenr()) 59 call assert_equal(fname, bufname("%")) 60 quit! 61 62 " (Q)uit 63 let s:swap_choice = 'q' 64 wincmd gf 65 call assert_equal(1, tabpagenr()) 66 call assert_notequal(fname, bufname("%")) 67 new | only! 68 69 call delete(fname) 70 call delete(swp_fname) 71 augroup! test_window_cmd_wincmd_gf 72endfunc 73 74func Test_window_quit() 75 e Xa 76 split Xb 77 call assert_equal(2, '$'->winnr()) 78 call assert_equal('Xb', bufname(winbufnr(1))) 79 call assert_equal('Xa', bufname(winbufnr(2))) 80 81 wincmd q 82 call assert_equal(1, winnr('$')) 83 call assert_equal('Xa', bufname(winbufnr(1))) 84 85 bw Xa Xb 86endfunc 87 88func Test_window_horizontal_split() 89 call assert_equal(1, winnr('$')) 90 3wincmd s 91 call assert_equal(2, winnr('$')) 92 call assert_equal(3, winheight(0)) 93 call assert_equal(winwidth(1), 2->winwidth()) 94 95 call assert_fails('botright topleft wincmd s', 'E442:') 96 bw 97endfunc 98 99func Test_window_vertical_split() 100 call assert_equal(1, winnr('$')) 101 3wincmd v 102 call assert_equal(2, winnr('$')) 103 call assert_equal(3, winwidth(0)) 104 call assert_equal(winheight(1), winheight(2)) 105 106 call assert_fails('botright topleft wincmd v', 'E442:') 107 bw 108endfunc 109 110" Test the ":wincmd ^" and "<C-W>^" commands. 111func Test_window_split_edit_alternate() 112 113 " Test for failure when the alternate buffer/file no longer exists. 114 edit Xfoo | %bw 115 call assert_fails(':wincmd ^', 'E23') 116 117 " Test for the expected behavior when we have two named buffers. 118 edit Xfoo | edit Xbar 119 wincmd ^ 120 call assert_equal('Xfoo', bufname(winbufnr(1))) 121 call assert_equal('Xbar', bufname(winbufnr(2))) 122 only 123 124 " Test for the expected behavior when the alternate buffer is not named. 125 enew | let l:nr1 = bufnr('%') 126 edit Xfoo | let l:nr2 = bufnr('%') 127 wincmd ^ 128 call assert_equal(l:nr1, winbufnr(1)) 129 call assert_equal(l:nr2, winbufnr(2)) 130 only 131 132 " FIXME: this currently fails on AppVeyor, but passes locally 133 if !has('win32') 134 " Test the Normal mode command. 135 call feedkeys("\<C-W>\<C-^>", 'tx') 136 call assert_equal(l:nr2, winbufnr(1)) 137 call assert_equal(l:nr1, winbufnr(2)) 138 endif 139 140 %bw! 141endfunc 142 143" Test the ":[count]wincmd ^" and "[count]<C-W>^" commands. 144func Test_window_split_edit_bufnr() 145 146 %bwipeout 147 let l:nr = bufnr('%') + 1 148 call assert_fails(':execute "normal! ' . l:nr . '\<C-W>\<C-^>"', 'E92') 149 call assert_fails(':' . l:nr . 'wincmd ^', 'E16') 150 call assert_fails(':0wincmd ^', 'E16') 151 152 edit Xfoo | edit Xbar | edit Xbaz 153 let l:foo_nr = bufnr('Xfoo') 154 let l:bar_nr = bufnr('Xbar') 155 let l:baz_nr = bufnr('Xbaz') 156 157 " FIXME: this currently fails on AppVeyor, but passes locally 158 if !has('win32') 159 call feedkeys(l:foo_nr . "\<C-W>\<C-^>", 'tx') 160 call assert_equal('Xfoo', bufname(winbufnr(1))) 161 call assert_equal('Xbaz', bufname(winbufnr(2))) 162 only 163 164 call feedkeys(l:bar_nr . "\<C-W>\<C-^>", 'tx') 165 call assert_equal('Xbar', bufname(winbufnr(1))) 166 call assert_equal('Xfoo', bufname(winbufnr(2))) 167 only 168 169 execute l:baz_nr . 'wincmd ^' 170 call assert_equal('Xbaz', bufname(winbufnr(1))) 171 call assert_equal('Xbar', bufname(winbufnr(2))) 172 endif 173 174 %bw! 175endfunc 176 177func Test_window_preview() 178 CheckFeature quickfix 179 180 " Open a preview window 181 pedit Xa 182 call assert_equal(2, winnr('$')) 183 call assert_equal(0, &previewwindow) 184 185 " Go to the preview window 186 wincmd P 187 call assert_equal(1, &previewwindow) 188 189 " Close preview window 190 wincmd z 191 call assert_equal(1, winnr('$')) 192 call assert_equal(0, &previewwindow) 193 194 call assert_fails('wincmd P', 'E441:') 195endfunc 196 197func Test_window_preview_from_help() 198 CheckFeature quickfix 199 200 filetype on 201 call writefile(['/* some C code */'], 'Xpreview.c') 202 help 203 pedit Xpreview.c 204 wincmd P 205 call assert_equal(1, &previewwindow) 206 call assert_equal('c', &filetype) 207 wincmd z 208 209 filetype off 210 close 211 call delete('Xpreview.c') 212endfunc 213 214func Test_window_exchange() 215 e Xa 216 217 " Nothing happens with window exchange when there is 1 window 218 wincmd x 219 call assert_equal(1, winnr('$')) 220 221 split Xb 222 split Xc 223 224 call assert_equal('Xc', bufname(winbufnr(1))) 225 call assert_equal('Xb', bufname(winbufnr(2))) 226 call assert_equal('Xa', bufname(winbufnr(3))) 227 228 " Exchange current window 1 with window 3 229 3wincmd x 230 call assert_equal('Xa', bufname(winbufnr(1))) 231 call assert_equal('Xb', bufname(winbufnr(2))) 232 call assert_equal('Xc', bufname(winbufnr(3))) 233 234 " Exchange window with next when at the top window 235 wincmd x 236 call assert_equal('Xb', bufname(winbufnr(1))) 237 call assert_equal('Xa', bufname(winbufnr(2))) 238 call assert_equal('Xc', bufname(winbufnr(3))) 239 240 " Exchange window with next when at the middle window 241 wincmd j 242 wincmd x 243 call assert_equal('Xb', bufname(winbufnr(1))) 244 call assert_equal('Xc', bufname(winbufnr(2))) 245 call assert_equal('Xa', bufname(winbufnr(3))) 246 247 " Exchange window with next when at the bottom window. 248 " When there is no next window, it exchanges with the previous window. 249 wincmd j 250 wincmd x 251 call assert_equal('Xb', bufname(winbufnr(1))) 252 call assert_equal('Xa', bufname(winbufnr(2))) 253 call assert_equal('Xc', bufname(winbufnr(3))) 254 255 bw Xa Xb Xc 256endfunc 257 258func Test_window_rotate() 259 e Xa 260 split Xb 261 split Xc 262 call assert_equal('Xc', bufname(winbufnr(1))) 263 call assert_equal('Xb', bufname(winbufnr(2))) 264 call assert_equal('Xa', bufname(winbufnr(3))) 265 266 " Rotate downwards 267 wincmd r 268 call assert_equal('Xa', bufname(winbufnr(1))) 269 call assert_equal('Xc', bufname(winbufnr(2))) 270 call assert_equal('Xb', bufname(winbufnr(3))) 271 272 2wincmd r 273 call assert_equal('Xc', bufname(winbufnr(1))) 274 call assert_equal('Xb', bufname(winbufnr(2))) 275 call assert_equal('Xa', bufname(winbufnr(3))) 276 277 " Rotate upwards 278 wincmd R 279 call assert_equal('Xb', bufname(winbufnr(1))) 280 call assert_equal('Xa', bufname(winbufnr(2))) 281 call assert_equal('Xc', bufname(winbufnr(3))) 282 283 2wincmd R 284 call assert_equal('Xc', bufname(winbufnr(1))) 285 call assert_equal('Xb', bufname(winbufnr(2))) 286 call assert_equal('Xa', bufname(winbufnr(3))) 287 288 bot vsplit 289 call assert_fails('wincmd R', 'E443:') 290 291 bw Xa Xb Xc 292endfunc 293 294func Test_window_height() 295 e Xa 296 split Xb 297 298 let [wh1, wh2] = [winheight(1), winheight(2)] 299 " Active window (1) should have the same height or 1 more 300 " than the other window. 301 call assert_inrange(wh2, wh2 + 1, wh1) 302 303 wincmd - 304 call assert_equal(wh1 - 1, winheight(1)) 305 call assert_equal(wh2 + 1, winheight(2)) 306 307 wincmd + 308 call assert_equal(wh1, winheight(1)) 309 call assert_equal(wh2, 2->winheight()) 310 311 2wincmd _ 312 call assert_equal(2, winheight(1)) 313 call assert_equal(wh1 + wh2 - 2, winheight(2)) 314 315 wincmd = 316 call assert_equal(wh1, winheight(1)) 317 call assert_equal(wh2, winheight(2)) 318 319 2wincmd _ 320 set winfixheight 321 split Xc 322 let [wh1, wh2, wh3] = [winheight(1), winheight(2), winheight(3)] 323 call assert_equal(2, winheight(2)) 324 call assert_inrange(wh3, wh3 + 1, wh1) 325 3wincmd + 326 call assert_equal(2, winheight(2)) 327 call assert_equal(wh1 + 3, winheight(1)) 328 call assert_equal(wh3 - 3, winheight(3)) 329 wincmd = 330 call assert_equal(2, winheight(2)) 331 call assert_equal(wh1, winheight(1)) 332 call assert_equal(wh3, winheight(3)) 333 334 wincmd j 335 set winfixheight& 336 337 wincmd = 338 let [wh1, wh2, wh3] = [winheight(1), winheight(2), winheight(3)] 339 " Current window (2) should have the same height or 1 more 340 " than the other windows. 341 call assert_inrange(wh1, wh1 + 1, wh2) 342 call assert_inrange(wh3, wh3 + 1, wh2) 343 344 bw Xa Xb Xc 345endfunc 346 347func Test_window_width() 348 e Xa 349 vsplit Xb 350 351 let [ww1, ww2] = [winwidth(1), winwidth(2)] 352 " Active window (1) should have the same width or 1 more 353 " than the other window. 354 call assert_inrange(ww2, ww2 + 1, ww1) 355 356 wincmd < 357 call assert_equal(ww1 - 1, winwidth(1)) 358 call assert_equal(ww2 + 1, winwidth(2)) 359 360 wincmd > 361 call assert_equal(ww1, winwidth(1)) 362 call assert_equal(ww2, winwidth(2)) 363 364 2wincmd | 365 call assert_equal(2, winwidth(1)) 366 call assert_equal(ww1 + ww2 - 2, winwidth(2)) 367 368 wincmd = 369 call assert_equal(ww1, winwidth(1)) 370 call assert_equal(ww2, winwidth(2)) 371 372 2wincmd | 373 set winfixwidth 374 vsplit Xc 375 let [ww1, ww2, ww3] = [winwidth(1), winwidth(2), winwidth(3)] 376 call assert_equal(2, winwidth(2)) 377 call assert_inrange(ww3, ww3 + 1, ww1) 378 3wincmd > 379 call assert_equal(2, winwidth(2)) 380 call assert_equal(ww1 + 3, winwidth(1)) 381 call assert_equal(ww3 - 3, winwidth(3)) 382 wincmd = 383 call assert_equal(2, winwidth(2)) 384 call assert_equal(ww1, winwidth(1)) 385 call assert_equal(ww3, winwidth(3)) 386 387 wincmd l 388 set winfixwidth& 389 390 wincmd = 391 let [ww1, ww2, ww3] = [winwidth(1), winwidth(2), winwidth(3)] 392 " Current window (2) should have the same width or 1 more 393 " than the other windows. 394 call assert_inrange(ww1, ww1 + 1, ww2) 395 call assert_inrange(ww3, ww3 + 1, ww2) 396 397 bw Xa Xb Xc 398endfunc 399 400func Test_equalalways_on_close() 401 set equalalways 402 vsplit 403 windo split 404 split 405 wincmd J 406 " now we have a frame top-left with two windows, a frame top-right with two 407 " windows and a frame at the bottom, full-width. 408 let height_1 = winheight(1) 409 let height_2 = winheight(2) 410 let height_3 = winheight(3) 411 let height_4 = winheight(4) 412 " closing the bottom window causes all windows to be resized. 413 close 414 call assert_notequal(height_1, winheight(1)) 415 call assert_notequal(height_2, winheight(2)) 416 call assert_notequal(height_3, winheight(3)) 417 call assert_notequal(height_4, winheight(4)) 418 call assert_equal(winheight(1), winheight(3)) 419 call assert_equal(winheight(2), winheight(4)) 420 421 1wincmd w 422 split 423 4wincmd w 424 resize + 5 425 " left column has three windows, equalized heights. 426 " right column has two windows, top one a bit higher 427 let height_1 = winheight(1) 428 let height_2 = winheight(2) 429 let height_4 = winheight(4) 430 let height_5 = winheight(5) 431 3wincmd w 432 " closing window in left column equalizes heights in left column but not in 433 " the right column 434 close 435 call assert_notequal(height_1, winheight(1)) 436 call assert_notequal(height_2, winheight(2)) 437 call assert_equal(height_4, winheight(3)) 438 call assert_equal(height_5, winheight(4)) 439 440 only 441 set equalalways& 442endfunc 443 444func Test_win_screenpos() 445 CheckFeature quickfix 446 447 call assert_equal(1, winnr('$')) 448 split 449 vsplit 450 10wincmd _ 451 30wincmd | 452 call assert_equal([1, 1], win_screenpos(1)) 453 call assert_equal([1, 32], win_screenpos(2)) 454 call assert_equal([12, 1], win_screenpos(3)) 455 call assert_equal([0, 0], win_screenpos(4)) 456 only 457endfunc 458 459func Test_window_jump_tag() 460 CheckFeature quickfix 461 462 help 463 /iccf 464 call assert_match('^|iccf|', getline('.')) 465 call assert_equal(2, winnr('$')) 466 2wincmd } 467 call assert_equal(3, winnr('$')) 468 call assert_match('^|iccf|', getline('.')) 469 wincmd k 470 call assert_match('\*iccf\*', getline('.')) 471 call assert_equal(2, winheight(0)) 472 473 wincmd z 474 set previewheight=4 475 help 476 /bugs 477 wincmd } 478 wincmd k 479 call assert_match('\*bugs\*', getline('.')) 480 call assert_equal(4, winheight(0)) 481 set previewheight& 482 483 %bw! 484endfunc 485 486func Test_window_newtab() 487 e Xa 488 489 call assert_equal(1, tabpagenr('$')) 490 call assert_equal("\nAlready only one window", execute('wincmd T')) 491 492 split Xb 493 split Xc 494 495 wincmd T 496 call assert_equal(2, tabpagenr('$')) 497 call assert_equal(['Xb', 'Xa'], map(tabpagebuflist(1), 'bufname(v:val)')) 498 call assert_equal(['Xc' ], map(2->tabpagebuflist(), 'bufname(v:val)')) 499 500 %bw! 501endfunc 502 503func Test_next_split_all() 504 " This was causing an illegal memory access. 505 n x 506 norm axxx 507 split 508 split 509 s/x 510 s/x 511 all 512 bwipe! 513endfunc 514 515" Tests for adjusting window and contents 516func GetScreenStr(row) 517 let str = "" 518 for c in range(1,3) 519 let str .= nr2char(screenchar(a:row, c)) 520 endfor 521 return str 522endfunc 523 524func Test_window_contents() 525 enew! | only | new 526 call setline(1, range(1,256)) 527 528 exe "norm! \<C-W>t\<C-W>=1Gzt\<C-W>w\<C-W>+" 529 redraw 530 let s3 = GetScreenStr(1) 531 wincmd p 532 call assert_equal(1, line("w0")) 533 call assert_equal('1 ', s3) 534 535 exe "norm! \<C-W>t\<C-W>=50Gzt\<C-W>w\<C-W>+" 536 redraw 537 let s3 = GetScreenStr(1) 538 wincmd p 539 call assert_equal(50, line("w0")) 540 call assert_equal('50 ', s3) 541 542 exe "norm! \<C-W>t\<C-W>=59Gzt\<C-W>w\<C-W>+" 543 redraw 544 let s3 = GetScreenStr(1) 545 wincmd p 546 call assert_equal(59, line("w0")) 547 call assert_equal('59 ', s3) 548 549 %d 550 call setline(1, ['one', 'two', 'three']) 551 call assert_equal(1, line('w0')) 552 call assert_equal(3, line('w$')) 553 554 bwipeout! 555 call test_garbagecollect_now() 556endfunc 557 558func Test_window_colon_command() 559 " This was reading invalid memory. 560 exe "norm! v\<C-W>:\<C-U>echo v:version" 561endfunc 562 563func Test_access_freed_mem() 564 call assert_equal(&columns, winwidth(0)) 565 " This was accessing freed memory 566 au * 0 vs xxx 567 arg 0 568 argadd 569 call assert_fails("all", "E249:") 570 au! 571 bwipe xxx 572 call assert_equal(&columns, winwidth(0)) 573endfunc 574 575func Test_insert_cleared_on_switch_to_term() 576 CheckFeature terminal 577 578 set showmode 579 terminal 580 wincmd p 581 582 call feedkeys("i\<C-O>", 'ntx') 583 redraw 584 585 " The "-- (insert) --" indicator should be visible. 586 let chars = map(range(1, &columns), 'nr2char(screenchar(&lines, v:val))') 587 let str = trim(join(chars, '')) 588 call assert_equal('-- (insert) --', str) 589 590 call feedkeys("\<C-W>p", 'ntx') 591 redraw 592 593 " The "-- (insert) --" indicator should have been cleared. 594 let chars = map(range(1, &columns), 'nr2char(screenchar(&lines, v:val))') 595 let str = trim(join(chars, '')) 596 call assert_equal('', str) 597 598 set showmode& 599 %bw! 600endfunc 601 602func Test_visual_cleared_after_window_split() 603 new | only! 604 let smd_save = &showmode 605 set showmode 606 let ls_save = &laststatus 607 set laststatus=1 608 call setline(1, ['a', 'b', 'c', 'd', '']) 609 norm! G 610 exe "norm! kkvk" 611 redraw 612 exe "norm! \<C-W>v" 613 redraw 614 " check if '-- VISUAL --' disappeared from command line 615 let columns = range(1, &columns) 616 let cmdlinechars = map(columns, 'nr2char(screenchar(&lines, v:val))') 617 let cmdline = join(cmdlinechars, '') 618 let cmdline_ltrim = substitute(cmdline, '^\s*', "", "") 619 let mode_shown = substitute(cmdline_ltrim, '\s*$', "", "") 620 call assert_equal('', mode_shown) 621 let &showmode = smd_save 622 let &laststatus = ls_save 623 bwipe! 624endfunc 625 626func Test_winrestcmd() 627 2split 628 3vsplit 629 let a = winrestcmd() 630 call assert_equal(2, winheight(0)) 631 call assert_equal(3, winwidth(0)) 632 wincmd = 633 call assert_notequal(2, winheight(0)) 634 call assert_notequal(3, winwidth(0)) 635 exe a 636 call assert_equal(2, winheight(0)) 637 call assert_equal(3, winwidth(0)) 638 only 639endfunc 640 641func Fun_RenewFile() 642 " Need to wait a bit for the timestamp to be older. 643 let old_ftime = getftime("tmp.txt") 644 while getftime("tmp.txt") == old_ftime 645 sleep 100m 646 silent execute '!echo "1" > tmp.txt' 647 endwhile 648 sp 649 wincmd p 650 edit! tmp.txt 651endfunc 652 653func Test_window_prevwin() 654 " Can we make this work on MS-Windows? 655 if !has('unix') 656 return 657 endif 658 659 set hidden autoread 660 call writefile(['2'], 'tmp.txt') 661 new tmp.txt 662 q 663 call Fun_RenewFile() 664 call assert_equal(2, winnr()) 665 wincmd p 666 call assert_equal(1, winnr()) 667 wincmd p 668 q 669 call Fun_RenewFile() 670 call assert_equal(2, winnr()) 671 wincmd p 672 call assert_equal(1, winnr()) 673 wincmd p 674 " reset 675 q 676 call delete('tmp.txt') 677 set hidden&vim autoread&vim 678 delfunc Fun_RenewFile 679endfunc 680 681func Test_relative_cursor_position_in_one_line_window() 682 new 683 only 684 call setline(1, range(1, 10000)) 685 normal 50% 686 let lnum = getcurpos()[1] 687 split 688 split 689 " make third window take as many lines as possible, other windows will 690 " become one line 691 3wincmd w 692 for i in range(1, &lines - 6) 693 wincmd + 694 redraw! 695 endfor 696 697 " first and second window should show cursor line 698 let wininfo = getwininfo() 699 call assert_equal(lnum, wininfo[0].topline) 700 call assert_equal(lnum, wininfo[1].topline) 701 702 only! 703 bwipe! 704endfunc 705 706func Test_relative_cursor_position_after_move_and_resize() 707 let so_save = &so 708 set so=0 709 enew 710 call setline(1, range(1, 10000)) 711 normal 50% 712 split 713 1wincmd w 714 " Move cursor to first line in window 715 normal H 716 redraw! 717 " Reduce window height to two lines 718 let height = winheight(0) 719 while winheight(0) > 2 720 wincmd - 721 redraw! 722 endwhile 723 " move cursor to second/last line in window 724 normal j 725 " restore previous height 726 while winheight(0) < height 727 wincmd + 728 redraw! 729 endwhile 730 " make window two lines again 731 while winheight(0) > 2 732 wincmd - 733 redraw! 734 endwhile 735 736 " cursor should be at bottom line 737 let info = getwininfo(win_getid())[0] 738 call assert_equal(info.topline + 1, getcurpos()[1]) 739 740 only! 741 bwipe! 742 let &so = so_save 743endfunc 744 745func Test_relative_cursor_position_after_resize() 746 let so_save = &so 747 set so=0 748 enew 749 call setline(1, range(1, 10000)) 750 normal 50% 751 split 752 1wincmd w 753 let winid1 = win_getid() 754 let info = getwininfo(winid1)[0] 755 " Move cursor to second line in window 756 exe "normal " . (info.topline + 1) . "G" 757 redraw! 758 let lnum = getcurpos()[1] 759 760 " Make the window only two lines high, cursor should end up in top line 761 2wincmd w 762 exe (info.height - 2) . "wincmd +" 763 redraw! 764 let info = getwininfo(winid1)[0] 765 call assert_equal(lnum, info.topline) 766 767 only! 768 bwipe! 769 let &so = so_save 770endfunc 771 772func Test_relative_cursor_second_line_after_resize() 773 let so_save = &so 774 set so=0 775 enew 776 call setline(1, range(1, 10000)) 777 normal 50% 778 split 779 1wincmd w 780 let winid1 = win_getid() 781 let info = getwininfo(winid1)[0] 782 783 " Make the window only two lines high 784 2wincmd _ 785 786 " Move cursor to second line in window 787 normal H 788 normal j 789 790 " Make window size bigger, then back to 2 lines 791 for i in range(1, 10) 792 wincmd + 793 redraw! 794 endfor 795 for i in range(1, 10) 796 wincmd - 797 redraw! 798 endfor 799 800 " cursor should end up in bottom line 801 let info = getwininfo(winid1)[0] 802 call assert_equal(info.topline + 1, getcurpos()[1]) 803 804 only! 805 bwipe! 806 let &so = so_save 807endfunc 808 809func Test_split_noscroll() 810 let so_save = &so 811 enew 812 call setline(1, range(1, 8)) 813 normal 100% 814 split 815 816 1wincmd w 817 let winid1 = win_getid() 818 let info1 = getwininfo(winid1)[0] 819 820 2wincmd w 821 let winid2 = win_getid() 822 let info2 = getwininfo(winid2)[0] 823 824 call assert_equal(1, info1.topline) 825 call assert_equal(1, info2.topline) 826 827 " window that fits all lines by itself, but not when split: closing other 828 " window should restore fraction. 829 only! 830 call setline(1, range(1, &lines - 10)) 831 exe &lines / 4 832 let winid1 = win_getid() 833 let info1 = getwininfo(winid1)[0] 834 call assert_equal(1, info1.topline) 835 new 836 redraw 837 close 838 let info1 = getwininfo(winid1)[0] 839 call assert_equal(1, info1.topline) 840 841 bwipe! 842 let &so = so_save 843endfunc 844 845" Tests for the winnr() function 846func Test_winnr() 847 only | tabonly 848 call assert_equal(1, winnr('j')) 849 call assert_equal(1, winnr('k')) 850 call assert_equal(1, winnr('h')) 851 call assert_equal(1, winnr('l')) 852 853 " create a set of horizontally and vertically split windows 854 leftabove new | wincmd p 855 leftabove new | wincmd p 856 rightbelow new | wincmd p 857 rightbelow new | wincmd p 858 leftabove vnew | wincmd p 859 leftabove vnew | wincmd p 860 rightbelow vnew | wincmd p 861 rightbelow vnew | wincmd p 862 863 call assert_equal(8, winnr('j')) 864 call assert_equal(2, winnr('k')) 865 call assert_equal(4, winnr('h')) 866 call assert_equal(6, winnr('l')) 867 call assert_equal(9, winnr('2j')) 868 call assert_equal(1, winnr('2k')) 869 call assert_equal(3, winnr('2h')) 870 call assert_equal(7, winnr('2l')) 871 872 " Error cases 873 call assert_fails("echo winnr('0.2k')", 'E15:') 874 call assert_equal(2, winnr('-2k')) 875 call assert_fails("echo winnr('-2xj')", 'E15:') 876 call assert_fails("echo winnr('j2j')", 'E15:') 877 call assert_fails("echo winnr('ll')", 'E15:') 878 call assert_fails("echo winnr('5')", 'E15:') 879 call assert_equal(4, winnr('0h')) 880 881 tabnew 882 call assert_equal(8, tabpagewinnr(1, 'j')) 883 call assert_equal(2, 1->tabpagewinnr('k')) 884 call assert_equal(4, tabpagewinnr(1, 'h')) 885 call assert_equal(6, tabpagewinnr(1, 'l')) 886 887 only | tabonly 888endfunc 889 890func Test_winrestview() 891 split runtest.vim 892 normal 50% 893 let view = winsaveview() 894 close 895 split runtest.vim 896 eval view->winrestview() 897 call assert_equal(view, winsaveview()) 898 899 bwipe! 900endfunc 901 902func Test_win_splitmove() 903 CheckFeature quickfix 904 905 edit a 906 leftabove split b 907 leftabove vsplit c 908 leftabove split d 909 call assert_equal(0, win_splitmove(winnr(), winnr('l'))) 910 call assert_equal(bufname(winbufnr(1)), 'c') 911 call assert_equal(bufname(winbufnr(2)), 'd') 912 call assert_equal(bufname(winbufnr(3)), 'b') 913 call assert_equal(bufname(winbufnr(4)), 'a') 914 call assert_equal(0, win_splitmove(winnr(), winnr('j'), {'vertical': 1})) 915 call assert_equal(0, win_splitmove(winnr(), winnr('j'), {'vertical': 1})) 916 call assert_equal(bufname(winbufnr(1)), 'c') 917 call assert_equal(bufname(winbufnr(2)), 'b') 918 call assert_equal(bufname(winbufnr(3)), 'd') 919 call assert_equal(bufname(winbufnr(4)), 'a') 920 call assert_equal(0, win_splitmove(winnr(), winnr('k'), {'vertical': 1})) 921 call assert_equal(bufname(winbufnr(1)), 'd') 922 call assert_equal(bufname(winbufnr(2)), 'c') 923 call assert_equal(bufname(winbufnr(3)), 'b') 924 call assert_equal(bufname(winbufnr(4)), 'a') 925 call assert_equal(0, win_splitmove(winnr(), winnr('j'), {'rightbelow': v:true})) 926 call assert_equal(bufname(winbufnr(1)), 'c') 927 call assert_equal(bufname(winbufnr(2)), 'b') 928 call assert_equal(bufname(winbufnr(3)), 'a') 929 call assert_equal(bufname(winbufnr(4)), 'd') 930 only | bd 931 932 call assert_fails('call win_splitmove(winnr(), 123)', 'E957:') 933 call assert_fails('call win_splitmove(123, winnr())', 'E957:') 934 call assert_fails('call win_splitmove(winnr(), winnr())', 'E957:') 935 936 tabnew 937 call assert_fails('call win_splitmove(1, win_getid(1, 1))', 'E957:') 938 tabclose 939endfunc 940 941" Test for the :only command 942func Test_window_only() 943 new 944 set modified 945 new 946 call assert_fails('only', 'E445:') 947 only! 948 " Test for :only with a count 949 let wid = win_getid() 950 new 951 new 952 3only 953 call assert_equal(1, winnr('$')) 954 call assert_equal(wid, win_getid()) 955 call assert_fails('close', 'E444:') 956 call assert_fails('%close', 'E16:') 957endfunc 958 959" Test for errors with :wincmd 960func Test_wincmd_errors() 961 call assert_fails('wincmd g', 'E474:') 962 call assert_fails('wincmd ab', 'E474:') 963endfunc 964 965" Test for errors with :winpos 966func Test_winpos_errors() 967 if !has("gui_running") && !has('win32') 968 call assert_fails('winpos', 'E188:') 969 endif 970 call assert_fails('winpos 10', 'E466:') 971endfunc 972 973" Test for +cmd in a :split command 974func Test_split_cmd() 975 split +set\ readonly 976 call assert_equal(1, &readonly) 977 call assert_equal(2, winnr('$')) 978 close 979endfunc 980 981" vim: shiftwidth=2 sts=2 expandtab 982