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