view src/testdir/test_window_id.vim @ 8536:09041d2fd7d0 v7.4.1558

commit https://github.com/vim/vim/commit/9cdf86b86f5fdb5a45b682f336846f9d9a9c6f1f Author: Bram Moolenaar <Bram@vim.org> Date: Sun Mar 13 19:04:51 2016 +0100 patch 7.4.1558 Problem: It is not easy to find out what windows display a buffer. Solution: Add win_findbuf().
author Christian Brabandt <cb@256bit.org>
date Sun, 13 Mar 2016 19:15:05 +0100
parents 485d4d8a97f6
children 6c4d610fce0a
line wrap: on
line source

" Test using the window ID.

func Test_win_getid()
  edit one
  let id1 = win_getid()
  split two
  let id2 = win_getid()
  let bufnr2 = bufnr('%')
  split three
  let id3 = win_getid()
  tabnew
  edit four
  let id4 = win_getid()
  split five
  let id5 = win_getid()
  let bufnr5 = bufnr('%')
  tabnext

  wincmd w
  call assert_equal("two", expand("%"))
  call assert_equal(id2, win_getid())
  let nr2 = winnr()
  wincmd w
  call assert_equal("one", expand("%"))
  call assert_equal(id1, win_getid())
  let nr1 = winnr()
  wincmd w
  call assert_equal("three", expand("%"))
  call assert_equal(id3, win_getid())
  let nr3 = winnr()
  tabnext
  call assert_equal("five", expand("%"))
  call assert_equal(id5, win_getid())
  let nr5 = winnr()
  wincmd w
  call assert_equal("four", expand("%"))
  call assert_equal(id4, win_getid())
  let nr4 = winnr()
  tabnext

  exe nr1 . "wincmd w"
  call assert_equal(id1, win_getid())
  exe nr2 . "wincmd w"
  call assert_equal(id2, win_getid())
  exe nr3 . "wincmd w"
  call assert_equal(id3, win_getid())
  tabnext
  exe nr4 . "wincmd w"
  call assert_equal(id4, win_getid())
  exe nr5 . "wincmd w"
  call assert_equal(id5, win_getid())

  call win_gotoid(id2)
  call assert_equal("two", expand("%"))
  call win_gotoid(id4)
  call assert_equal("four", expand("%"))
  call win_gotoid(id1)
  call assert_equal("one", expand("%"))
  call win_gotoid(id5)
  call assert_equal("five", expand("%"))

  call assert_equal(0, win_id2win(9999))
  call assert_equal(nr5, win_id2win(id5))
  call assert_equal(0, win_id2win(id1))
  tabnext
  call assert_equal(nr1, win_id2win(id1))

  call assert_equal([0, 0], win_id2tabwin(9999))
  call assert_equal([1, nr2], win_id2tabwin(id2))
  call assert_equal([2, nr4], win_id2tabwin(id4))

  call assert_equal([], win_findbuf(9999))
  call assert_equal([id2], win_findbuf(bufnr2))
  call win_gotoid(id5)
  split
  call assert_equal(sort([id5, win_getid()]), sort(win_findbuf(bufnr5)))

  only!
endfunc