blob: 396a49b55f05b3353ffa66f3b0fb5080f159555d [file] [log] [blame]
Bram Moolenaar86edef62016-03-13 18:07:30 +01001" Test using the window ID.
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02002
Bram Moolenaar5a4c3082019-12-01 15:23:11 +01003source check.vim
Bram Moolenaar86edef62016-03-13 18:07:30 +01004
5func Test_win_getid()
6 edit one
7 let id1 = win_getid()
Bram Moolenaar888ccac2016-06-04 18:49:36 +02008 let w:one = 'one'
Bram Moolenaar86edef62016-03-13 18:07:30 +01009 split two
10 let id2 = win_getid()
Bram Moolenaar9cdf86b2016-03-13 19:04:51 +010011 let bufnr2 = bufnr('%')
Bram Moolenaar888ccac2016-06-04 18:49:36 +020012 let w:two = 'two'
Bram Moolenaar86edef62016-03-13 18:07:30 +010013 split three
14 let id3 = win_getid()
Bram Moolenaar888ccac2016-06-04 18:49:36 +020015 let w:three = 'three'
Bram Moolenaar86edef62016-03-13 18:07:30 +010016 tabnew
17 edit four
18 let id4 = win_getid()
Bram Moolenaar888ccac2016-06-04 18:49:36 +020019 let w:four = 'four'
Bram Moolenaar86edef62016-03-13 18:07:30 +010020 split five
21 let id5 = win_getid()
Bram Moolenaar9cdf86b2016-03-13 19:04:51 +010022 let bufnr5 = bufnr('%')
Bram Moolenaar888ccac2016-06-04 18:49:36 +020023 let w:five = 'five'
Bram Moolenaar86edef62016-03-13 18:07:30 +010024 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()
Bram Moolenaar888ccac2016-06-04 18:49:36 +020038 call assert_equal('one', getwinvar(id1, 'one'))
39 call assert_equal('two', getwinvar(id2, 'two'))
40 call assert_equal('three', getwinvar(id3, 'three'))
Bram Moolenaar86edef62016-03-13 18:07:30 +010041 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()
Bram Moolenaar888ccac2016-06-04 18:49:36 +020049 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')
Bram Moolenaar86edef62016-03-13 18:07:30 +010053 tabnext
Bram Moolenaar888ccac2016-06-04 18:49:36 +020054 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'))
Bram Moolenaar86edef62016-03-13 18:07:30 +010057
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("%"))
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020072 eval id4->win_gotoid()
Bram Moolenaar86edef62016-03-13 18:07:30 +010073 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))
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020080 call assert_equal(nr5, id5->win_id2win())
Bram Moolenaar86edef62016-03-13 18:07:30 +010081 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))
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020086 call assert_equal([1, nr2], id2->win_id2tabwin())
Bram Moolenaar86edef62016-03-13 18:07:30 +010087 call assert_equal([2, nr4], win_id2tabwin(id4))
88
Bram Moolenaar9cdf86b2016-03-13 19:04:51 +010089 call assert_equal([], win_findbuf(9999))
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020090 call assert_equal([id2], bufnr2->win_findbuf())
Bram Moolenaar9cdf86b2016-03-13 19:04:51 +010091 call win_gotoid(id5)
92 split
93 call assert_equal(sort([id5, win_getid()]), sort(win_findbuf(bufnr5)))
94
Bram Moolenaar99fa7212020-04-26 15:59:55 +020095 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
Bram Moolenaar86edef62016-03-13 18:07:30 +010099 only!
100endfunc
Bram Moolenaar8e639052016-11-13 14:31:40 +0100101
102func Test_win_getid_curtab()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100103 CheckFeature quickfix
104
Bram Moolenaar8e639052016-11-13 14:31:40 +0100105 tabedit X
106 tabfirst
107 copen
108 only
Bram Moolenaarf92e58c2019-09-08 21:51:41 +0200109 call assert_equal(win_getid(1), 1->win_getid( 1))
Bram Moolenaar8e639052016-11-13 14:31:40 +0100110 tabclose!
111endfunc
Bram Moolenaar0f6b4f02018-08-21 16:56:34 +0200112
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!
Bram Moolenaarf92e58c2019-09-08 21:51:41 +0200131
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
Bram Moolenaar99fa7212020-04-26 15:59:55 +0200138
139 call assert_equal([], winlayout(-1))
Bram Moolenaar0f6b4f02018-08-21 16:56:34 +0200140endfunc
Bram Moolenaar99fa7212020-04-26 15:59:55 +0200141
142" vim: shiftwidth=2 sts=2 expandtab