1" Test using the window ID.
2
3func Test_win_getid()
4  edit one
5  let id1 = win_getid()
6  let w:one = 'one'
7  split two
8  let id2 = win_getid()
9  let bufnr2 = bufnr('%')
10  let w:two = 'two'
11  split three
12  let id3 = win_getid()
13  let w:three = 'three'
14  tabnew
15  edit four
16  let id4 = win_getid()
17  let w:four = 'four'
18  split five
19  let id5 = win_getid()
20  let bufnr5 = bufnr('%')
21  let w:five = 'five'
22  tabnext
23
24  wincmd w
25  call assert_equal("two", expand("%"))
26  call assert_equal(id2, win_getid())
27  let nr2 = winnr()
28  wincmd w
29  call assert_equal("one", expand("%"))
30  call assert_equal(id1, win_getid())
31  let nr1 = winnr()
32  wincmd w
33  call assert_equal("three", expand("%"))
34  call assert_equal(id3, win_getid())
35  let nr3 = winnr()
36  call assert_equal('one', getwinvar(id1, 'one'))
37  call assert_equal('two', getwinvar(id2, 'two'))
38  call assert_equal('three', getwinvar(id3, 'three'))
39  tabnext
40  call assert_equal("five", expand("%"))
41  call assert_equal(id5, win_getid())
42  let nr5 = winnr()
43  wincmd w
44  call assert_equal("four", expand("%"))
45  call assert_equal(id4, win_getid())
46  let nr4 = winnr()
47  call assert_equal('four', getwinvar(id4, 'four'))
48  call assert_equal('five', getwinvar(id5, 'five'))
49  call settabwinvar(1, id2, 'two', '2')
50  call setwinvar(id4, 'four', '4')
51  tabnext
52  call assert_equal('4', gettabwinvar(2, id4, 'four'))
53  call assert_equal('five', gettabwinvar(2, id5, 'five'))
54  call assert_equal('2', getwinvar(id2, 'two'))
55
56  exe nr1 . "wincmd w"
57  call assert_equal(id1, win_getid())
58  exe nr2 . "wincmd w"
59  call assert_equal(id2, win_getid())
60  exe nr3 . "wincmd w"
61  call assert_equal(id3, win_getid())
62  tabnext
63  exe nr4 . "wincmd w"
64  call assert_equal(id4, win_getid())
65  exe nr5 . "wincmd w"
66  call assert_equal(id5, win_getid())
67
68  call win_gotoid(id2)
69  call assert_equal("two", expand("%"))
70  call win_gotoid(id4)
71  call assert_equal("four", expand("%"))
72  call win_gotoid(id1)
73  call assert_equal("one", expand("%"))
74  call win_gotoid(id5)
75  call assert_equal("five", expand("%"))
76
77  call assert_equal(0, win_id2win(9999))
78  call assert_equal(nr5, win_id2win(id5))
79  call assert_equal(0, win_id2win(id1))
80  tabnext
81  call assert_equal(nr1, win_id2win(id1))
82
83  call assert_equal([0, 0], win_id2tabwin(9999))
84  call assert_equal([1, nr2], win_id2tabwin(id2))
85  call assert_equal([2, nr4], win_id2tabwin(id4))
86
87  call assert_equal([], win_findbuf(9999))
88  call assert_equal([id2], win_findbuf(bufnr2))
89  call win_gotoid(id5)
90  split
91  call assert_equal(sort([id5, win_getid()]), sort(win_findbuf(bufnr5)))
92
93  only!
94endfunc
95