blob: fa3ebd757e22923ef6861fc897ad84b66521102c [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()
6 split two
7 let id2 = win_getid()
Bram Moolenaar9cdf86b2016-03-13 19:04:51 +01008 let bufnr2 = bufnr('%')
Bram Moolenaar86edef62016-03-13 18:07:30 +01009 split three
10 let id3 = win_getid()
11 tabnew
12 edit four
13 let id4 = win_getid()
14 split five
15 let id5 = win_getid()
Bram Moolenaar9cdf86b2016-03-13 19:04:51 +010016 let bufnr5 = bufnr('%')
Bram Moolenaar86edef62016-03-13 18:07:30 +010017 tabnext
18
19 wincmd w
20 call assert_equal("two", expand("%"))
21 call assert_equal(id2, win_getid())
22 let nr2 = winnr()
23 wincmd w
24 call assert_equal("one", expand("%"))
25 call assert_equal(id1, win_getid())
26 let nr1 = winnr()
27 wincmd w
28 call assert_equal("three", expand("%"))
29 call assert_equal(id3, win_getid())
30 let nr3 = winnr()
31 tabnext
32 call assert_equal("five", expand("%"))
33 call assert_equal(id5, win_getid())
34 let nr5 = winnr()
35 wincmd w
36 call assert_equal("four", expand("%"))
37 call assert_equal(id4, win_getid())
38 let nr4 = winnr()
39 tabnext
40
41 exe nr1 . "wincmd w"
42 call assert_equal(id1, win_getid())
43 exe nr2 . "wincmd w"
44 call assert_equal(id2, win_getid())
45 exe nr3 . "wincmd w"
46 call assert_equal(id3, win_getid())
47 tabnext
48 exe nr4 . "wincmd w"
49 call assert_equal(id4, win_getid())
50 exe nr5 . "wincmd w"
51 call assert_equal(id5, win_getid())
52
53 call win_gotoid(id2)
54 call assert_equal("two", expand("%"))
55 call win_gotoid(id4)
56 call assert_equal("four", expand("%"))
57 call win_gotoid(id1)
58 call assert_equal("one", expand("%"))
59 call win_gotoid(id5)
60 call assert_equal("five", expand("%"))
61
62 call assert_equal(0, win_id2win(9999))
63 call assert_equal(nr5, win_id2win(id5))
64 call assert_equal(0, win_id2win(id1))
65 tabnext
66 call assert_equal(nr1, win_id2win(id1))
67
68 call assert_equal([0, 0], win_id2tabwin(9999))
69 call assert_equal([1, nr2], win_id2tabwin(id2))
70 call assert_equal([2, nr4], win_id2tabwin(id4))
71
Bram Moolenaar9cdf86b2016-03-13 19:04:51 +010072 call assert_equal([], win_findbuf(9999))
73 call assert_equal([id2], win_findbuf(bufnr2))
74 call win_gotoid(id5)
75 split
76 call assert_equal(sort([id5, win_getid()]), sort(win_findbuf(bufnr5)))
77
Bram Moolenaar86edef62016-03-13 18:07:30 +010078 only!
79endfunc