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 " Open a preview window 179 pedit Xa 180 call assert_equal(2, winnr('$')) 181 call assert_equal(0, &previewwindow) 182 183 " Go to the preview window 184 wincmd P 185 call assert_equal(1, &previewwindow) 186 187 " Close preview window 188 wincmd z 189 call assert_equal(1, winnr('$')) 190 call assert_equal(0, &previewwindow) 191 192 call assert_fails('wincmd P', 'E441:') 193endfunc 194 195func Test_window_preview_from_help() 196 filetype on 197 call writefile(['/* some C code */'], 'Xpreview.c') 198 help 199 pedit Xpreview.c 200 wincmd P 201 call assert_equal(1, &previewwindow) 202 call assert_equal('c', &filetype) 203 wincmd z 204 205 filetype off 206 close 207 call delete('Xpreview.c') 208endfunc 209 210func Test_window_exchange() 211 e Xa 212 213 " Nothing happens with window exchange when there is 1 window 214 wincmd x 215 call assert_equal(1, winnr('$')) 216 217 split Xb 218 split Xc 219 220 call assert_equal('Xc', bufname(winbufnr(1))) 221 call assert_equal('Xb', bufname(winbufnr(2))) 222 call assert_equal('Xa', bufname(winbufnr(3))) 223 224 " Exchange current window 1 with window 3 225 3wincmd x 226 call assert_equal('Xa', bufname(winbufnr(1))) 227 call assert_equal('Xb', bufname(winbufnr(2))) 228 call assert_equal('Xc', bufname(winbufnr(3))) 229 230 " Exchange window with next when at the top window 231 wincmd x 232 call assert_equal('Xb', bufname(winbufnr(1))) 233 call assert_equal('Xa', bufname(winbufnr(2))) 234 call assert_equal('Xc', bufname(winbufnr(3))) 235 236 " Exchange window with next when at the middle window 237 wincmd j 238 wincmd x 239 call assert_equal('Xb', bufname(winbufnr(1))) 240 call assert_equal('Xc', bufname(winbufnr(2))) 241 call assert_equal('Xa', bufname(winbufnr(3))) 242 243 " Exchange window with next when at the bottom window. 244 " When there is no next window, it exchanges with the previous window. 245 wincmd j 246 wincmd x 247 call assert_equal('Xb', bufname(winbufnr(1))) 248 call assert_equal('Xa', bufname(winbufnr(2))) 249 call assert_equal('Xc', bufname(winbufnr(3))) 250 251 bw Xa Xb Xc 252endfunc 253 254func Test_window_rotate() 255 e Xa 256 split Xb 257 split Xc 258 call assert_equal('Xc', bufname(winbufnr(1))) 259 call assert_equal('Xb', bufname(winbufnr(2))) 260 call assert_equal('Xa', bufname(winbufnr(3))) 261 262 " Rotate downwards 263 wincmd r 264 call assert_equal('Xa', bufname(winbufnr(1))) 265 call assert_equal('Xc', bufname(winbufnr(2))) 266 call assert_equal('Xb', bufname(winbufnr(3))) 267 268 2wincmd r 269 call assert_equal('Xc', bufname(winbufnr(1))) 270 call assert_equal('Xb', bufname(winbufnr(2))) 271 call assert_equal('Xa', bufname(winbufnr(3))) 272 273 " Rotate upwards 274 wincmd R 275 call assert_equal('Xb', bufname(winbufnr(1))) 276 call assert_equal('Xa', bufname(winbufnr(2))) 277 call assert_equal('Xc', bufname(winbufnr(3))) 278 279 2wincmd R 280 call assert_equal('Xc', bufname(winbufnr(1))) 281 call assert_equal('Xb', bufname(winbufnr(2))) 282 call assert_equal('Xa', bufname(winbufnr(3))) 283 284 bot vsplit 285 call assert_fails('wincmd R', 'E443:') 286 287 bw Xa Xb Xc 288endfunc 289 290func Test_window_height() 291 e Xa 292 split Xb 293 294 let [wh1, wh2] = [winheight(1), winheight(2)] 295 " Active window (1) should have the same height or 1 more 296 " than the other window. 297 call assert_inrange(wh2, wh2 + 1, wh1) 298 299 wincmd - 300 call assert_equal(wh1 - 1, winheight(1)) 301 call assert_equal(wh2 + 1, winheight(2)) 302 303 wincmd + 304 call assert_equal(wh1, winheight(1)) 305 call assert_equal(wh2, 2->winheight()) 306 307 2wincmd _ 308 call assert_equal(2, winheight(1)) 309 call assert_equal(wh1 + wh2 - 2, winheight(2)) 310 311 wincmd = 312 call assert_equal(wh1, winheight(1)) 313 call assert_equal(wh2, winheight(2)) 314 315 2wincmd _ 316 set winfixheight 317 split Xc 318 let [wh1, wh2, wh3] = [winheight(1), winheight(2), winheight(3)] 319 call assert_equal(2, winheight(2)) 320 call assert_inrange(wh3, wh3 + 1, wh1) 321 3wincmd + 322 call assert_equal(2, winheight(2)) 323 call assert_equal(wh1 + 3, winheight(1)) 324 call assert_equal(wh3 - 3, winheight(3)) 325 wincmd = 326 call assert_equal(2, winheight(2)) 327 call assert_equal(wh1, winheight(1)) 328 call assert_equal(wh3, winheight(3)) 329 330 wincmd j 331 set winfixheight& 332 333 wincmd = 334 let [wh1, wh2, wh3] = [winheight(1), winheight(2), winheight(3)] 335 " Current window (2) should have the same height or 1 more 336 " than the other windows. 337 call assert_inrange(wh1, wh1 + 1, wh2) 338 call assert_inrange(wh3, wh3 + 1, wh2) 339 340 bw Xa Xb Xc 341endfunc 342 343func Test_window_width() 344 e Xa 345 vsplit Xb 346 347 let [ww1, ww2] = [winwidth(1), winwidth(2)] 348 " Active window (1) should have the same width or 1 more 349 " than the other window. 350 call assert_inrange(ww2, ww2 + 1, ww1) 351 352 wincmd < 353 call assert_equal(ww1 - 1, winwidth(1)) 354 call assert_equal(ww2 + 1, winwidth(2)) 355 356 wincmd > 357 call assert_equal(ww1, winwidth(1)) 358 call assert_equal(ww2, winwidth(2)) 359 360 2wincmd | 361 call assert_equal(2, winwidth(1)) 362 call assert_equal(ww1 + ww2 - 2, winwidth(2)) 363 364 wincmd = 365 call assert_equal(ww1, winwidth(1)) 366 call assert_equal(ww2, winwidth(2)) 367 368 2wincmd | 369 set winfixwidth 370 vsplit Xc 371 let [ww1, ww2, ww3] = [winwidth(1), winwidth(2), winwidth(3)] 372 call assert_equal(2, winwidth(2)) 373 call assert_inrange(ww3, ww3 + 1, ww1) 374 3wincmd > 375 call assert_equal(2, winwidth(2)) 376 call assert_equal(ww1 + 3, winwidth(1)) 377 call assert_equal(ww3 - 3, winwidth(3)) 378 wincmd = 379 call assert_equal(2, winwidth(2)) 380 call assert_equal(ww1, winwidth(1)) 381 call assert_equal(ww3, winwidth(3)) 382 383 wincmd l 384 set winfixwidth& 385 386 wincmd = 387 let [ww1, ww2, ww3] = [winwidth(1), winwidth(2), winwidth(3)] 388 " Current window (2) should have the same width or 1 more 389 " than the other windows. 390 call assert_inrange(ww1, ww1 + 1, ww2) 391 call assert_inrange(ww3, ww3 + 1, ww2) 392 393 bw Xa Xb Xc 394endfunc 395 396func Test_equalalways_on_close() 397 set equalalways 398 vsplit 399 windo split 400 split 401 wincmd J 402 " now we have a frame top-left with two windows, a frame top-right with two 403 " windows and a frame at the bottom, full-width. 404 let height_1 = winheight(1) 405 let height_2 = winheight(2) 406 let height_3 = winheight(3) 407 let height_4 = winheight(4) 408 " closing the bottom window causes all windows to be resized. 409 close 410 call assert_notequal(height_1, winheight(1)) 411 call assert_notequal(height_2, winheight(2)) 412 call assert_notequal(height_3, winheight(3)) 413 call assert_notequal(height_4, winheight(4)) 414 call assert_equal(winheight(1), winheight(3)) 415 call assert_equal(winheight(2), winheight(4)) 416 417 1wincmd w 418 split 419 4wincmd w 420 resize + 5 421 " left column has three windows, equalized heights. 422 " right column has two windows, top one a bit higher 423 let height_1 = winheight(1) 424 let height_2 = winheight(2) 425 let height_4 = winheight(4) 426 let height_5 = winheight(5) 427 3wincmd w 428 " closing window in left column equalizes heights in left column but not in 429 " the right column 430 close 431 call assert_notequal(height_1, winheight(1)) 432 call assert_notequal(height_2, winheight(2)) 433 call assert_equal(height_4, winheight(3)) 434 call assert_equal(height_5, winheight(4)) 435 436 only 437 set equalalways& 438endfunc 439 440func Test_win_screenpos() 441 call assert_equal(1, winnr('$')) 442 split 443 vsplit 444 10wincmd _ 445 30wincmd | 446 call assert_equal([1, 1], win_screenpos(1)) 447 call assert_equal([1, 32], win_screenpos(2)) 448 call assert_equal([12, 1], win_screenpos(3)) 449 call assert_equal([0, 0], win_screenpos(4)) 450 only 451endfunc 452 453func Test_window_jump_tag() 454 help 455 /iccf 456 call assert_match('^|iccf|', getline('.')) 457 call assert_equal(2, winnr('$')) 458 2wincmd } 459 call assert_equal(3, winnr('$')) 460 call assert_match('^|iccf|', getline('.')) 461 wincmd k 462 call assert_match('\*iccf\*', getline('.')) 463 call assert_equal(2, winheight(0)) 464 465 wincmd z 466 set previewheight=4 467 help 468 /bugs 469 wincmd } 470 wincmd k 471 call assert_match('\*bugs\*', getline('.')) 472 call assert_equal(4, winheight(0)) 473 set previewheight& 474 475 %bw! 476endfunc 477 478func Test_window_newtab() 479 e Xa 480 481 call assert_equal(1, tabpagenr('$')) 482 call assert_equal("\nAlready only one window", execute('wincmd T')) 483 484 split Xb 485 split Xc 486 487 wincmd T 488 call assert_equal(2, tabpagenr('$')) 489 call assert_equal(['Xb', 'Xa'], map(tabpagebuflist(1), 'bufname(v:val)')) 490 call assert_equal(['Xc' ], map(2->tabpagebuflist(), 'bufname(v:val)')) 491 492 %bw! 493endfunc 494 495func Test_next_split_all() 496 " This was causing an illegal memory access. 497 n x 498 norm axxx 499 split 500 split 501 s/x 502 s/x 503 all 504 bwipe! 505endfunc 506 507" Tests for adjusting window and contents 508func GetScreenStr(row) 509 let str = "" 510 for c in range(1,3) 511 let str .= nr2char(screenchar(a:row, c)) 512 endfor 513 return str 514endfunc 515 516func Test_window_contents() 517 enew! | only | new 518 call setline(1, range(1,256)) 519 520 exe "norm! \<C-W>t\<C-W>=1Gzt\<C-W>w\<C-W>+" 521 redraw 522 let s3 = GetScreenStr(1) 523 wincmd p 524 call assert_equal(1, line("w0")) 525 call assert_equal('1 ', s3) 526 527 exe "norm! \<C-W>t\<C-W>=50Gzt\<C-W>w\<C-W>+" 528 redraw 529 let s3 = GetScreenStr(1) 530 wincmd p 531 call assert_equal(50, line("w0")) 532 call assert_equal('50 ', s3) 533 534 exe "norm! \<C-W>t\<C-W>=59Gzt\<C-W>w\<C-W>+" 535 redraw 536 let s3 = GetScreenStr(1) 537 wincmd p 538 call assert_equal(59, line("w0")) 539 call assert_equal('59 ', s3) 540 541 bwipeout! 542 call test_garbagecollect_now() 543endfunc 544 545func Test_window_colon_command() 546 " This was reading invalid memory. 547 exe "norm! v\<C-W>:\<C-U>echo v:version" 548endfunc 549 550func Test_access_freed_mem() 551 call assert_equal(&columns, winwidth(0)) 552 " This was accessing freed memory 553 au * 0 vs xxx 554 arg 0 555 argadd 556 call assert_fails("all", "E249:") 557 au! 558 bwipe xxx 559 call assert_equal(&columns, winwidth(0)) 560endfunc 561 562func Test_insert_cleared_on_switch_to_term() 563 CheckFeature terminal 564 565 set showmode 566 terminal 567 wincmd p 568 569 call feedkeys("i\<C-O>", 'ntx') 570 redraw 571 572 " The "-- (insert) --" indicator should be visible. 573 let chars = map(range(1, &columns), 'nr2char(screenchar(&lines, v:val))') 574 let str = trim(join(chars, '')) 575 call assert_equal('-- (insert) --', str) 576 577 call feedkeys("\<C-W>p", 'ntx') 578 redraw 579 580 " The "-- (insert) --" indicator should have been cleared. 581 let chars = map(range(1, &columns), 'nr2char(screenchar(&lines, v:val))') 582 let str = trim(join(chars, '')) 583 call assert_equal('', str) 584 585 set showmode& 586 %bw! 587endfunc 588 589func Test_visual_cleared_after_window_split() 590 new | only! 591 let smd_save = &showmode 592 set showmode 593 let ls_save = &laststatus 594 set laststatus=1 595 call setline(1, ['a', 'b', 'c', 'd', '']) 596 norm! G 597 exe "norm! kkvk" 598 redraw 599 exe "norm! \<C-W>v" 600 redraw 601 " check if '-- VISUAL --' disappeared from command line 602 let columns = range(1, &columns) 603 let cmdlinechars = map(columns, 'nr2char(screenchar(&lines, v:val))') 604 let cmdline = join(cmdlinechars, '') 605 let cmdline_ltrim = substitute(cmdline, '^\s*', "", "") 606 let mode_shown = substitute(cmdline_ltrim, '\s*$', "", "") 607 call assert_equal('', mode_shown) 608 let &showmode = smd_save 609 let &laststatus = ls_save 610 bwipe! 611endfunc 612 613func Test_winrestcmd() 614 2split 615 3vsplit 616 let a = winrestcmd() 617 call assert_equal(2, winheight(0)) 618 call assert_equal(3, winwidth(0)) 619 wincmd = 620 call assert_notequal(2, winheight(0)) 621 call assert_notequal(3, winwidth(0)) 622 exe a 623 call assert_equal(2, winheight(0)) 624 call assert_equal(3, winwidth(0)) 625 only 626endfunc 627 628func Fun_RenewFile() 629 " Need to wait a bit for the timestamp to be older. 630 let old_ftime = getftime("tmp.txt") 631 while getftime("tmp.txt") == old_ftime 632 sleep 100m 633 silent execute '!echo "1" > tmp.txt' 634 endwhile 635 sp 636 wincmd p 637 edit! tmp.txt 638endfunc 639 640func Test_window_prevwin() 641 " Can we make this work on MS-Windows? 642 if !has('unix') 643 return 644 endif 645 646 set hidden autoread 647 call writefile(['2'], 'tmp.txt') 648 new tmp.txt 649 q 650 call Fun_RenewFile() 651 call assert_equal(2, winnr()) 652 wincmd p 653 call assert_equal(1, winnr()) 654 wincmd p 655 q 656 call Fun_RenewFile() 657 call assert_equal(2, winnr()) 658 wincmd p 659 call assert_equal(1, winnr()) 660 wincmd p 661 " reset 662 q 663 call delete('tmp.txt') 664 set hidden&vim autoread&vim 665 delfunc Fun_RenewFile 666endfunc 667 668func Test_relative_cursor_position_in_one_line_window() 669 new 670 only 671 call setline(1, range(1, 10000)) 672 normal 50% 673 let lnum = getcurpos()[1] 674 split 675 split 676 " make third window take as many lines as possible, other windows will 677 " become one line 678 3wincmd w 679 for i in range(1, &lines - 6) 680 wincmd + 681 redraw! 682 endfor 683 684 " first and second window should show cursor line 685 let wininfo = getwininfo() 686 call assert_equal(lnum, wininfo[0].topline) 687 call assert_equal(lnum, wininfo[1].topline) 688 689 only! 690 bwipe! 691endfunc 692 693func Test_relative_cursor_position_after_move_and_resize() 694 let so_save = &so 695 set so=0 696 enew 697 call setline(1, range(1, 10000)) 698 normal 50% 699 split 700 1wincmd w 701 " Move cursor to first line in window 702 normal H 703 redraw! 704 " Reduce window height to two lines 705 let height = winheight(0) 706 while winheight(0) > 2 707 wincmd - 708 redraw! 709 endwhile 710 " move cursor to second/last line in window 711 normal j 712 " restore previous height 713 while winheight(0) < height 714 wincmd + 715 redraw! 716 endwhile 717 " make window two lines again 718 while winheight(0) > 2 719 wincmd - 720 redraw! 721 endwhile 722 723 " cursor should be at bottom line 724 let info = getwininfo(win_getid())[0] 725 call assert_equal(info.topline + 1, getcurpos()[1]) 726 727 only! 728 bwipe! 729 let &so = so_save 730endfunc 731 732func Test_relative_cursor_position_after_resize() 733 let so_save = &so 734 set so=0 735 enew 736 call setline(1, range(1, 10000)) 737 normal 50% 738 split 739 1wincmd w 740 let winid1 = win_getid() 741 let info = getwininfo(winid1)[0] 742 " Move cursor to second line in window 743 exe "normal " . (info.topline + 1) . "G" 744 redraw! 745 let lnum = getcurpos()[1] 746 747 " Make the window only two lines high, cursor should end up in top line 748 2wincmd w 749 exe (info.height - 2) . "wincmd +" 750 redraw! 751 let info = getwininfo(winid1)[0] 752 call assert_equal(lnum, info.topline) 753 754 only! 755 bwipe! 756 let &so = so_save 757endfunc 758 759func Test_relative_cursor_second_line_after_resize() 760 let so_save = &so 761 set so=0 762 enew 763 call setline(1, range(1, 10000)) 764 normal 50% 765 split 766 1wincmd w 767 let winid1 = win_getid() 768 let info = getwininfo(winid1)[0] 769 770 " Make the window only two lines high 771 2wincmd _ 772 773 " Move cursor to second line in window 774 normal H 775 normal j 776 777 " Make window size bigger, then back to 2 lines 778 for i in range(1, 10) 779 wincmd + 780 redraw! 781 endfor 782 for i in range(1, 10) 783 wincmd - 784 redraw! 785 endfor 786 787 " cursor should end up in bottom line 788 let info = getwininfo(winid1)[0] 789 call assert_equal(info.topline + 1, getcurpos()[1]) 790 791 only! 792 bwipe! 793 let &so = so_save 794endfunc 795 796func Test_split_noscroll() 797 let so_save = &so 798 enew 799 call setline(1, range(1, 8)) 800 normal 100% 801 split 802 803 1wincmd w 804 let winid1 = win_getid() 805 let info1 = getwininfo(winid1)[0] 806 807 2wincmd w 808 let winid2 = win_getid() 809 let info2 = getwininfo(winid2)[0] 810 811 call assert_equal(1, info1.topline) 812 call assert_equal(1, info2.topline) 813 814 " window that fits all lines by itself, but not when split: closing other 815 " window should restore fraction. 816 only! 817 call setline(1, range(1, &lines - 10)) 818 exe &lines / 4 819 let winid1 = win_getid() 820 let info1 = getwininfo(winid1)[0] 821 call assert_equal(1, info1.topline) 822 new 823 redraw 824 close 825 let info1 = getwininfo(winid1)[0] 826 call assert_equal(1, info1.topline) 827 828 bwipe! 829 let &so = so_save 830endfunc 831 832" Tests for the winnr() function 833func Test_winnr() 834 only | tabonly 835 call assert_equal(1, winnr('j')) 836 call assert_equal(1, winnr('k')) 837 call assert_equal(1, winnr('h')) 838 call assert_equal(1, winnr('l')) 839 840 " create a set of horizontally and vertically split windows 841 leftabove new | wincmd p 842 leftabove new | wincmd p 843 rightbelow new | wincmd p 844 rightbelow new | wincmd p 845 leftabove vnew | wincmd p 846 leftabove vnew | wincmd p 847 rightbelow vnew | wincmd p 848 rightbelow vnew | wincmd p 849 850 call assert_equal(8, winnr('j')) 851 call assert_equal(2, winnr('k')) 852 call assert_equal(4, winnr('h')) 853 call assert_equal(6, winnr('l')) 854 call assert_equal(9, winnr('2j')) 855 call assert_equal(1, winnr('2k')) 856 call assert_equal(3, winnr('2h')) 857 call assert_equal(7, winnr('2l')) 858 859 " Error cases 860 call assert_fails("echo winnr('0.2k')", 'E15:') 861 call assert_equal(2, winnr('-2k')) 862 call assert_fails("echo winnr('-2xj')", 'E15:') 863 call assert_fails("echo winnr('j2j')", 'E15:') 864 call assert_fails("echo winnr('ll')", 'E15:') 865 call assert_fails("echo winnr('5')", 'E15:') 866 call assert_equal(4, winnr('0h')) 867 868 tabnew 869 call assert_equal(8, tabpagewinnr(1, 'j')) 870 call assert_equal(2, 1->tabpagewinnr('k')) 871 call assert_equal(4, tabpagewinnr(1, 'h')) 872 call assert_equal(6, tabpagewinnr(1, 'l')) 873 874 only | tabonly 875endfunc 876 877func Test_winrestview() 878 split runtest.vim 879 normal 50% 880 let view = winsaveview() 881 close 882 split runtest.vim 883 eval view->winrestview() 884 call assert_equal(view, winsaveview()) 885 886 bwipe! 887endfunc 888 889func Test_win_splitmove() 890 edit a 891 leftabove split b 892 leftabove vsplit c 893 leftabove split d 894 call assert_equal(0, win_splitmove(winnr(), winnr('l'))) 895 call assert_equal(bufname(winbufnr(1)), 'c') 896 call assert_equal(bufname(winbufnr(2)), 'd') 897 call assert_equal(bufname(winbufnr(3)), 'b') 898 call assert_equal(bufname(winbufnr(4)), 'a') 899 call assert_equal(0, win_splitmove(winnr(), winnr('j'), {'vertical': 1})) 900 call assert_equal(0, win_splitmove(winnr(), winnr('j'), {'vertical': 1})) 901 call assert_equal(bufname(winbufnr(1)), 'c') 902 call assert_equal(bufname(winbufnr(2)), 'b') 903 call assert_equal(bufname(winbufnr(3)), 'd') 904 call assert_equal(bufname(winbufnr(4)), 'a') 905 call assert_equal(0, win_splitmove(winnr(), winnr('k'), {'vertical': 1})) 906 call assert_equal(bufname(winbufnr(1)), 'd') 907 call assert_equal(bufname(winbufnr(2)), 'c') 908 call assert_equal(bufname(winbufnr(3)), 'b') 909 call assert_equal(bufname(winbufnr(4)), 'a') 910 call assert_equal(0, win_splitmove(winnr(), winnr('j'), {'rightbelow': v:true})) 911 call assert_equal(bufname(winbufnr(1)), 'c') 912 call assert_equal(bufname(winbufnr(2)), 'b') 913 call assert_equal(bufname(winbufnr(3)), 'a') 914 call assert_equal(bufname(winbufnr(4)), 'd') 915 only | bd 916 917 call assert_fails('call win_splitmove(winnr(), 123)', 'E957:') 918 call assert_fails('call win_splitmove(123, winnr())', 'E957:') 919 call assert_fails('call win_splitmove(winnr(), winnr())', 'E957:') 920endfunc 921 922" vim: shiftwidth=2 sts=2 expandtab 923