1" Test using the window ID.
2source check.vim
3
4func Test_win_getid()
5  edit one
6  let id1 = win_getid()
7  let w:one = 'one'
8  split two
9  let id2 = win_getid()
10  let bufnr2 = bufnr('%')
11  let w:two = 'two'
12  split three
13  let id3 = win_getid()
14  let w:three = 'three'
15  tabnew
16  edit four
17  let id4 = win_getid()
18  let w:four = 'four'
19  split five
20  let id5 = win_getid()
21  let bufnr5 = bufnr('%')
22  let w:five = 'five'
23  tabnext
24
25  wincmd w
26  call assert_equal("two", expand("%"))
27  call assert_equal(id2, win_getid())
28  let nr2 = winnr()
29  wincmd w
30  call assert_equal("one", expand("%"))
31  call assert_equal(id1, win_getid())
32  let nr1 = winnr()
33  wincmd w
34  call assert_equal("three", expand("%"))
35  call assert_equal(id3, win_getid())
36  let nr3 = winnr()
37  call assert_equal('one', getwinvar(id1, 'one'))
38  call assert_equal('two', getwinvar(id2, 'two'))
39  call assert_equal('three', getwinvar(id3, 'three'))
40  tabnext
41  call assert_equal("five", expand("%"))
42  call assert_equal(id5, win_getid())
43  let nr5 = winnr()
44  wincmd w
45  call assert_equal("four", expand("%"))
46  call assert_equal(id4, win_getid())
47  let nr4 = winnr()
48  call assert_equal('four', getwinvar(id4, 'four'))
49  call assert_equal('five', getwinvar(id5, 'five'))
50  call settabwinvar(1, id2, 'two', '2')
51  call setwinvar(id4, 'four', '4')
52  tabnext
53  call assert_equal('4', gettabwinvar(2, id4, 'four'))
54  call assert_equal('five', gettabwinvar(2, id5, 'five'))
55  call assert_equal('2', getwinvar(id2, 'two'))
56
57  exe nr1 . "wincmd w"
58  call assert_equal(id1, win_getid())
59  exe nr2 . "wincmd w"
60  call assert_equal(id2, win_getid())
61  exe nr3 . "wincmd w"
62  call assert_equal(id3, win_getid())
63  tabnext
64  exe nr4 . "wincmd w"
65  call assert_equal(id4, win_getid())
66  exe nr5 . "wincmd w"
67  call assert_equal(id5, win_getid())
68
69  call win_gotoid(id2)
70  call assert_equal("two", expand("%"))
71  eval id4->win_gotoid()
72  call assert_equal("four", expand("%"))
73  call win_gotoid(id1)
74  call assert_equal("one", expand("%"))
75  call win_gotoid(id5)
76  call assert_equal("five", expand("%"))
77
78  call assert_equal(0, win_id2win(9999))
79  call assert_equal(nr5, id5->win_id2win())
80  call assert_equal(0, win_id2win(id1))
81  tabnext
82  call assert_equal(nr1, win_id2win(id1))
83
84  call assert_equal([0, 0], win_id2tabwin(9999))
85  call assert_equal([1, nr2], id2->win_id2tabwin())
86  call assert_equal([2, nr4], win_id2tabwin(id4))
87
88  call assert_equal([], win_findbuf(9999))
89  call assert_equal([id2], bufnr2->win_findbuf())
90  call win_gotoid(id5)
91  split
92  call assert_equal(sort([id5, win_getid()]), sort(win_findbuf(bufnr5)))
93
94  call assert_fails('let w = win_getid([])', 'E745:')
95  call assert_equal(0, win_getid(-1))
96  call assert_equal(-1, win_getid(1, -1))
97
98  only!
99endfunc
100
101func Test_win_getid_curtab()
102  CheckFeature quickfix
103
104  tabedit X
105  tabfirst
106  copen
107  only
108  call assert_equal(win_getid(1), 1->win_getid( 1))
109  tabclose!
110endfunc
111
112func Test_winlayout()
113  let w1 = win_getid()
114  call assert_equal(['leaf', w1], winlayout())
115
116  split
117  let w2 = win_getid()
118  call assert_equal(['col', [['leaf', w2], ['leaf', w1]]], winlayout())
119
120  split
121  let w3 = win_getid()
122  call assert_equal(['col', [['leaf', w3], ['leaf', w2], ['leaf', w1]]], winlayout())
123
124  2wincmd w
125  vsplit
126  let w4 = win_getid()
127  call assert_equal(['col', [['leaf', w3], ['row', [['leaf', w4], ['leaf', w2]]], ['leaf', w1]]], winlayout())
128
129  only!
130
131  let w1 = win_getid()
132  call assert_equal(['leaf', w1], winlayout(1))
133  tabnew
134  let w2 = win_getid()
135  call assert_equal(['leaf', w2], 2->winlayout())
136  tabclose
137
138  call assert_equal([], winlayout(-1))
139endfunc
140
141" vim: shiftwidth=2 sts=2 expandtab
142