1" Tests for the getbufinfo(), getwininfo() and gettabinfo() functions
2
3source check.vim
4
5func Test_getbufwintabinfo()
6  CheckFeature quickfix
7
8  edit Xtestfile1
9  edit Xtestfile2
10  let buflist = getbufinfo()
11  call assert_equal(2, len(buflist))
12  call assert_match('Xtestfile1', buflist[0].name)
13  call assert_match('Xtestfile2', getbufinfo('Xtestfile2')[0].name)
14  call assert_equal([], getbufinfo(2016))
15  edit Xtestfile1
16  hide edit Xtestfile2
17  hide enew
18  call assert_equal(3, len(getbufinfo({'bufloaded':1})))
19
20  set tabstop&vim
21  let b:editor = 'vim'
22  let l = getbufinfo('%')
23  call assert_equal(bufnr('%'), l[0].bufnr)
24  call assert_equal('vim', l[0].variables.editor)
25  call assert_notequal(-1, index(l[0].windows, '%'->bufwinid()))
26
27  let l = '%'->getbufinfo()
28  call assert_equal(bufnr('%'), l[0].bufnr)
29
30  " Test for getbufinfo() with 'bufmodified'
31  call assert_equal(0, len(getbufinfo({'bufmodified' : 1})))
32  call setbufline('Xtestfile1', 1, ["Line1"])
33  let l = getbufinfo({'bufmodified' : 1})
34  call assert_equal(1, len(l))
35  call assert_equal(bufnr('Xtestfile1'), l[0].bufnr)
36
37  if has('signs')
38    call append(0, ['Linux', 'Windows', 'Mac'])
39    sign define Mark text=>> texthl=Search
40    exe "sign place 2 line=3 name=Mark buffer=" . bufnr('%')
41    let l = getbufinfo('%')
42    call assert_equal(2, l[0].signs[0].id)
43    call assert_equal(3, l[0].signs[0].lnum)
44    call assert_equal('Mark', l[0].signs[0].name)
45    sign unplace *
46    sign undefine Mark
47    enew!
48  endif
49  call assert_notequal([], getbufinfo(test_null_dict()))
50
51  only
52  let w1_id = win_getid()
53  setl foldcolumn=3
54  new
55  let w2_id = win_getid()
56  tabnew | let w3_id = win_getid()
57  new | let w4_id = win_getid()
58  vert new | let w5_id = win_getid()
59  eval 'green'->setwinvar(0, 'signal')
60  tabfirst
61  let winlist = getwininfo()
62  call assert_equal(5, len(winlist))
63  call assert_equal(winwidth(1), winlist[0].width)
64  call assert_equal(1, winlist[0].wincol)
65  " tabline adds one row in terminal, not in GUI
66  let tablineheight = winlist[0].winrow == 2 ? 1 : 0
67  call assert_equal(tablineheight + 1, winlist[0].winrow)
68
69  call assert_equal(winbufnr(2), winlist[1].bufnr)
70  call assert_equal(winheight(2), winlist[1].height)
71  call assert_equal(1, winlist[1].wincol)
72  call assert_equal(3, winlist[1].textoff)  " foldcolumn
73  call assert_equal(tablineheight + winheight(1) + 2, winlist[1].winrow)
74
75  call assert_equal(1, winlist[2].winnr)
76  call assert_equal(tablineheight + 1, winlist[2].winrow)
77  call assert_equal(1, winlist[2].wincol)
78
79  call assert_equal(winlist[2].width + 2, winlist[3].wincol)
80  call assert_equal(1, winlist[4].wincol)
81
82  call assert_equal(1, winlist[0].tabnr)
83  call assert_equal(1, winlist[1].tabnr)
84  call assert_equal(2, winlist[2].tabnr)
85  call assert_equal(2, winlist[3].tabnr)
86  call assert_equal(2, winlist[4].tabnr)
87
88  call assert_equal('green', winlist[2].variables.signal)
89  call assert_equal(w4_id, winlist[3].winid)
90  let winfo = w5_id->getwininfo()[0]
91  call assert_equal(2, winfo.tabnr)
92  call assert_equal([], getwininfo(3))
93
94  call settabvar(1, 'space', 'build')
95  let tablist = gettabinfo()
96  call assert_equal(2, len(tablist))
97  call assert_equal(3, len(tablist[1].windows))
98  call assert_equal(2, tablist[1].tabnr)
99  call assert_equal('build', tablist[0].variables.space)
100  call assert_equal(w2_id, tablist[0].windows[0])
101  call assert_equal([], 3->gettabinfo())
102
103  tabonly | only
104
105  lexpr ''
106  lopen
107  copen
108  let winlist = getwininfo()
109  call assert_false(winlist[0].quickfix)
110  call assert_false(winlist[0].loclist)
111  call assert_true(winlist[1].quickfix)
112  call assert_true(winlist[1].loclist)
113  call assert_true(winlist[2].quickfix)
114  call assert_false(winlist[2].loclist)
115  wincmd t | only
116endfunc
117
118function Test_get_buf_options()
119  let opts = bufnr()->getbufvar('&')
120  call assert_equal(v:t_dict, type(opts))
121  call assert_equal(8, opts.tabstop)
122endfunc
123
124function Test_get_win_options()
125  if has('folding')
126    set foldlevel=999
127  endif
128  set list
129  let opts = getwinvar(1, '&')
130  call assert_equal(v:t_dict, type(opts))
131  call assert_equal(0, opts.linebreak)
132  call assert_equal(1, opts.list)
133  if has('folding')
134    call assert_equal(999, opts.foldlevel)
135  endif
136  if has('signs')
137    call assert_equal('auto', opts.signcolumn)
138  endif
139
140  let opts = gettabwinvar(1, 1, '&')
141  call assert_equal(v:t_dict, type(opts))
142  call assert_equal(0, opts.linebreak)
143  call assert_equal(1, opts.list)
144  if has('signs')
145    call assert_equal('auto', opts.signcolumn)
146  endif
147  set list&
148  if has('folding')
149    set foldlevel=0
150  endif
151endfunc
152
153function Test_getbufinfo_lastused()
154  call test_settime(1234567)
155  edit Xtestfile1
156  enew
157  call test_settime(7654321)
158  edit Xtestfile2
159  enew
160  call assert_equal(getbufinfo('Xtestfile1')[0].lastused, 1234567)
161  call assert_equal(getbufinfo('Xtestfile2')[0].lastused, 7654321)
162  call test_settime(0)
163endfunc
164
165func Test_getbufinfo_lines()
166  new Xfoo
167  call setline(1, ['a', 'bc', 'd'])
168  let bn = bufnr('%')
169  hide
170  call assert_equal(3, getbufinfo(bn)[0]["linecount"])
171  edit Xfoo
172  bw!
173endfunc
174
175" vim: shiftwidth=2 sts=2 expandtab
176