blob: d10d831650da81f48fcdb6da35db4675dffa85bb [file] [log] [blame]
Bram Moolenaar86edef62016-03-13 18:07:30 +01001" Test using the window ID.
2
3func Test_win_getid()
4 edit one
5 let id1 = win_getid()
Bram Moolenaar888ccac2016-06-04 18:49:36 +02006 let w:one = 'one'
Bram Moolenaar86edef62016-03-13 18:07:30 +01007 split two
8 let id2 = win_getid()
Bram Moolenaar9cdf86b2016-03-13 19:04:51 +01009 let bufnr2 = bufnr('%')
Bram Moolenaar888ccac2016-06-04 18:49:36 +020010 let w:two = 'two'
Bram Moolenaar86edef62016-03-13 18:07:30 +010011 split three
12 let id3 = win_getid()
Bram Moolenaar888ccac2016-06-04 18:49:36 +020013 let w:three = 'three'
Bram Moolenaar86edef62016-03-13 18:07:30 +010014 tabnew
15 edit four
16 let id4 = win_getid()
Bram Moolenaar888ccac2016-06-04 18:49:36 +020017 let w:four = 'four'
Bram Moolenaar86edef62016-03-13 18:07:30 +010018 split five
19 let id5 = win_getid()
Bram Moolenaar9cdf86b2016-03-13 19:04:51 +010020 let bufnr5 = bufnr('%')
Bram Moolenaar888ccac2016-06-04 18:49:36 +020021 let w:five = 'five'
Bram Moolenaar86edef62016-03-13 18:07:30 +010022 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()
Bram Moolenaar888ccac2016-06-04 18:49:36 +020036 call assert_equal('one', getwinvar(id1, 'one'))
37 call assert_equal('two', getwinvar(id2, 'two'))
38 call assert_equal('three', getwinvar(id3, 'three'))
Bram Moolenaar86edef62016-03-13 18:07:30 +010039 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()
Bram Moolenaar888ccac2016-06-04 18:49:36 +020047 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')
Bram Moolenaar86edef62016-03-13 18:07:30 +010051 tabnext
Bram Moolenaar888ccac2016-06-04 18:49:36 +020052 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'))
Bram Moolenaar86edef62016-03-13 18:07:30 +010055
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
Bram Moolenaar9cdf86b2016-03-13 19:04:51 +010087 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
Bram Moolenaar86edef62016-03-13 18:07:30 +010093 only!
94endfunc
Bram Moolenaar8e639052016-11-13 14:31:40 +010095
96func Test_win_getid_curtab()
97 tabedit X
98 tabfirst
99 copen
100 only
101 call assert_equal(win_getid(1), win_getid(1, 1))
102 tabclose!
103endfunc
Bram Moolenaar0f6b4f02018-08-21 16:56:34 +0200104
105func Test_winlayout()
106 let w1 = win_getid()
107 call assert_equal(['leaf', w1], winlayout())
108
109 split
110 let w2 = win_getid()
111 call assert_equal(['col', [['leaf', w2], ['leaf', w1]]], winlayout())
112
113 split
114 let w3 = win_getid()
115 call assert_equal(['col', [['leaf', w3], ['leaf', w2], ['leaf', w1]]], winlayout())
116
117 2wincmd w
118 vsplit
119 let w4 = win_getid()
120 call assert_equal(['col', [['leaf', w3], ['row', [['leaf', w4], ['leaf', w2]]], ['leaf', w1]]], winlayout())
121
122 only!
123endfunc