blob: 9c92faeea5f6718d88b959cf93b09f0f7ca1729d [file] [log] [blame]
Bram Moolenaar86edef62016-03-13 18:07:30 +01001" Test using the window ID.
Bram Moolenaar5a4c3082019-12-01 15:23:11 +01002source check.vim
Bram Moolenaar86edef62016-03-13 18:07:30 +01003
4func Test_win_getid()
5 edit one
6 let id1 = win_getid()
Bram Moolenaar888ccac2016-06-04 18:49:36 +02007 let w:one = 'one'
Bram Moolenaar86edef62016-03-13 18:07:30 +01008 split two
9 let id2 = win_getid()
Bram Moolenaar9cdf86b2016-03-13 19:04:51 +010010 let bufnr2 = bufnr('%')
Bram Moolenaar888ccac2016-06-04 18:49:36 +020011 let w:two = 'two'
Bram Moolenaar86edef62016-03-13 18:07:30 +010012 split three
13 let id3 = win_getid()
Bram Moolenaar888ccac2016-06-04 18:49:36 +020014 let w:three = 'three'
Bram Moolenaar86edef62016-03-13 18:07:30 +010015 tabnew
16 edit four
17 let id4 = win_getid()
Bram Moolenaar888ccac2016-06-04 18:49:36 +020018 let w:four = 'four'
Bram Moolenaar86edef62016-03-13 18:07:30 +010019 split five
20 let id5 = win_getid()
Bram Moolenaar9cdf86b2016-03-13 19:04:51 +010021 let bufnr5 = bufnr('%')
Bram Moolenaar888ccac2016-06-04 18:49:36 +020022 let w:five = 'five'
Bram Moolenaar86edef62016-03-13 18:07:30 +010023 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()
Bram Moolenaar888ccac2016-06-04 18:49:36 +020037 call assert_equal('one', getwinvar(id1, 'one'))
38 call assert_equal('two', getwinvar(id2, 'two'))
39 call assert_equal('three', getwinvar(id3, 'three'))
Bram Moolenaar86edef62016-03-13 18:07:30 +010040 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()
Bram Moolenaar888ccac2016-06-04 18:49:36 +020048 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')
Bram Moolenaar86edef62016-03-13 18:07:30 +010052 tabnext
Bram Moolenaar888ccac2016-06-04 18:49:36 +020053 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'))
Bram Moolenaar86edef62016-03-13 18:07:30 +010056
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("%"))
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020071 eval id4->win_gotoid()
Bram Moolenaar86edef62016-03-13 18:07:30 +010072 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))
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020079 call assert_equal(nr5, id5->win_id2win())
Bram Moolenaar86edef62016-03-13 18:07:30 +010080 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))
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020085 call assert_equal([1, nr2], id2->win_id2tabwin())
Bram Moolenaar86edef62016-03-13 18:07:30 +010086 call assert_equal([2, nr4], win_id2tabwin(id4))
87
Bram Moolenaar9cdf86b2016-03-13 19:04:51 +010088 call assert_equal([], win_findbuf(9999))
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020089 call assert_equal([id2], bufnr2->win_findbuf())
Bram Moolenaar9cdf86b2016-03-13 19:04:51 +010090 call win_gotoid(id5)
91 split
92 call assert_equal(sort([id5, win_getid()]), sort(win_findbuf(bufnr5)))
93
Bram Moolenaar86edef62016-03-13 18:07:30 +010094 only!
95endfunc
Bram Moolenaar8e639052016-11-13 14:31:40 +010096
97func Test_win_getid_curtab()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +010098 CheckFeature quickfix
99
Bram Moolenaar8e639052016-11-13 14:31:40 +0100100 tabedit X
101 tabfirst
102 copen
103 only
Bram Moolenaarf92e58c2019-09-08 21:51:41 +0200104 call assert_equal(win_getid(1), 1->win_getid( 1))
Bram Moolenaar8e639052016-11-13 14:31:40 +0100105 tabclose!
106endfunc
Bram Moolenaar0f6b4f02018-08-21 16:56:34 +0200107
108func Test_winlayout()
109 let w1 = win_getid()
110 call assert_equal(['leaf', w1], winlayout())
111
112 split
113 let w2 = win_getid()
114 call assert_equal(['col', [['leaf', w2], ['leaf', w1]]], winlayout())
115
116 split
117 let w3 = win_getid()
118 call assert_equal(['col', [['leaf', w3], ['leaf', w2], ['leaf', w1]]], winlayout())
119
120 2wincmd w
121 vsplit
122 let w4 = win_getid()
123 call assert_equal(['col', [['leaf', w3], ['row', [['leaf', w4], ['leaf', w2]]], ['leaf', w1]]], winlayout())
124
125 only!
Bram Moolenaarf92e58c2019-09-08 21:51:41 +0200126
127 let w1 = win_getid()
128 call assert_equal(['leaf', w1], winlayout(1))
129 tabnew
130 let w2 = win_getid()
131 call assert_equal(['leaf', w2], 2->winlayout())
132 tabclose
Bram Moolenaar0f6b4f02018-08-21 16:56:34 +0200133endfunc