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