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