test_bufwintabinfo.vim (6132B)
1 " Tests for the getbufinfo(), getwininfo() and gettabinfo() functions 2 source check.vim 3 4 func Test_getbufwintabinfo() 5 CheckFeature quickfix 6 7 edit Xtestfile1 8 edit Xtestfile2 9 let buflist = getbufinfo() 10 call assert_equal(2, len(buflist)) 11 call assert_match('Xtestfile1', buflist[0].name) 12 call assert_match('Xtestfile2', getbufinfo('Xtestfile2')[0].name) 13 call assert_equal([], getbufinfo(2016)) 14 edit Xtestfile1 15 hide edit Xtestfile2 16 hide enew 17 call assert_equal(3, len(getbufinfo({'bufloaded':1}))) 18 19 set tabstop&vim 20 let b:editor = 'vim' 21 let l = getbufinfo('%') 22 call assert_equal(bufnr('%'), l[0].bufnr) 23 call assert_equal('vim', l[0].variables.editor) 24 call assert_notequal(-1, index(l[0].windows, '%'->bufwinid())) 25 26 let l = '%'->getbufinfo() 27 call assert_equal(bufnr('%'), l[0].bufnr) 28 29 " Test for getbufinfo() with 'bufmodified' 30 call assert_equal(0, len(getbufinfo({'bufmodified' : 1}))) 31 call setbufline('Xtestfile1', 1, ["Line1"]) 32 let l = getbufinfo({'bufmodified' : 1}) 33 call assert_equal(1, len(l)) 34 call assert_equal(bufnr('Xtestfile1'), l[0].bufnr) 35 36 if has('signs') 37 call append(0, ['Linux', 'Windows', 'Mac']) 38 sign define Mark text=>> texthl=Search 39 exe "sign place 2 line=3 name=Mark buffer=" . bufnr('%') 40 let l = getbufinfo('%') 41 call assert_equal(2, l[0].signs[0].id) 42 call assert_equal(3, l[0].signs[0].lnum) 43 call assert_equal('Mark', l[0].signs[0].name) 44 sign unplace * 45 sign undefine Mark 46 enew! 47 endif 48 call assert_notequal([], getbufinfo(v:_null_dict)) 49 50 only 51 let w1_id = win_getid() 52 setl foldcolumn=3 53 new 54 let w2_id = win_getid() 55 tabnew | let w3_id = win_getid() 56 new | let w4_id = win_getid() 57 vert new | let w5_id = win_getid() 58 eval 'green'->setwinvar(0, 'signal') 59 tabfirst 60 let winlist = getwininfo() 61 call assert_equal(5, len(winlist)) 62 call assert_equal(winwidth(1), winlist[0].width) 63 call assert_equal(1, winlist[0].wincol) 64 " tabline adds one row in terminal, not in GUI 65 let tablineheight = winlist[0].winrow == 2 ? 1 : 0 66 call assert_equal(tablineheight + 1, winlist[0].winrow) 67 68 call assert_equal(winbufnr(2), winlist[1].bufnr) 69 call assert_equal(winheight(2), winlist[1].height) 70 call assert_equal(1, winlist[1].wincol) 71 call assert_equal(3, winlist[1].textoff) " foldcolumn 72 call assert_equal(tablineheight + winheight(1) + 2, winlist[1].winrow) 73 74 call assert_equal(1, winlist[2].winnr) 75 call assert_equal(tablineheight + 1, winlist[2].winrow) 76 call assert_equal(1, winlist[2].wincol) 77 78 call assert_equal(winlist[2].width + 2, winlist[3].wincol) 79 call assert_equal(1, winlist[4].wincol) 80 81 call assert_equal(1, winlist[0].tabnr) 82 call assert_equal(1, winlist[1].tabnr) 83 call assert_equal(2, winlist[2].tabnr) 84 call assert_equal(2, winlist[3].tabnr) 85 call assert_equal(2, winlist[4].tabnr) 86 87 call assert_equal('green', winlist[2].variables.signal) 88 call assert_equal(w4_id, winlist[3].winid) 89 let winfo = w5_id->getwininfo()[0] 90 call assert_equal(2, winfo.tabnr) 91 call assert_equal([], getwininfo(3)) 92 93 call settabvar(1, 'space', 'build') 94 let tablist = gettabinfo() 95 call assert_equal(2, len(tablist)) 96 call assert_equal(3, len(tablist[1].windows)) 97 call assert_equal(2, tablist[1].tabnr) 98 call assert_equal('build', tablist[0].variables.space) 99 call assert_equal(w2_id, tablist[0].windows[0]) 100 call assert_equal([], 3->gettabinfo()) 101 102 tabonly | only 103 104 lexpr '' 105 lopen 106 copen 107 let winlist = getwininfo() 108 call assert_false(winlist[0].quickfix) 109 call assert_false(winlist[0].loclist) 110 call assert_true(winlist[1].quickfix) 111 call assert_true(winlist[1].loclist) 112 call assert_true(winlist[2].quickfix) 113 call assert_false(winlist[2].loclist) 114 wincmd t | only 115 %bw! 116 endfunc 117 118 function Test_get_wininfo_leftcol() 119 set nowrap 120 set winwidth=10 121 vsp 122 call setline(1, ['abcdefghijklmnopqrstuvwxyz']) 123 norm! 5zl 124 call assert_equal(5, getwininfo()[0].leftcol) 125 bwipe! 126 set wrap& 127 set winwidth& 128 endfunc 129 130 function Test_get_buf_options() 131 let opts = bufnr()->getbufvar('&') 132 call assert_equal(v:t_dict, type(opts)) 133 call assert_equal(8, opts.tabstop) 134 endfunc 135 136 function Test_get_win_options() 137 if has('folding') 138 set foldlevel=999 139 endif 140 set list 141 let opts = getwinvar(1, '&') 142 call assert_equal(v:t_dict, type(opts)) 143 call assert_equal(0, opts.linebreak) 144 call assert_equal(1, opts.list) 145 if has('folding') 146 call assert_equal(999, opts.foldlevel) 147 endif 148 if has('signs') 149 call assert_equal('auto', opts.signcolumn) 150 endif 151 152 let opts = gettabwinvar(1, 1, '&') 153 call assert_equal(v:t_dict, type(opts)) 154 call assert_equal(0, opts.linebreak) 155 call assert_equal(1, opts.list) 156 if has('signs') 157 call assert_equal('auto', opts.signcolumn) 158 endif 159 set list& 160 if has('folding') 161 set foldlevel=0 162 endif 163 endfunc 164 165 function Test_getbufinfo_lastused() 166 new Xfoo 167 let info = getbufinfo('Xfoo')[0] 168 call assert_equal(has_key(info, 'lastused'), 1) 169 call assert_equal(type(info.lastused), type(0)) 170 endfunc 171 172 func Test_getbufinfo_lines() 173 new Xfoo 174 call setline(1, ['a', 'bc', 'd']) 175 let bn = bufnr('%') 176 hide 177 call assert_equal(3, getbufinfo(bn)[0]["linecount"]) 178 edit Xfoo 179 bw! 180 endfunc 181 182 func Test_getwininfo_au() 183 enew 184 call setline(1, range(1, 16)) 185 186 let g:info = #{} 187 augroup T1 188 au! 189 au WinEnter * let g:info = getwininfo(win_getid())[0] 190 augroup END 191 192 4split 193 " Check that calling getwininfo() from WinEnter returns fresh values for 194 " topline and botline. 195 call assert_equal(1, g:info.topline) 196 call assert_equal(4, g:info.botline) 197 close 198 199 unlet g:info 200 augroup! T1 201 bwipe! 202 endfunc 203 204 func Test_getwininfo_status_height() 205 set laststatus=0 206 vsplit 207 let info = getwininfo(win_getid())[0] 208 call assert_equal(0, info.status_height) 209 210 set laststatus=2 211 let info = getwininfo(win_getid())[0] 212 call assert_equal(1, info.status_height) 213 214 set laststatus=1 215 only 216 let info = getwininfo(win_getid())[0] 217 call assert_equal(0, info.status_height) 218 vsplit 219 let info = getwininfo(win_getid())[0] 220 call assert_equal(1, info.status_height) 221 222 set laststatus&vim 223 bwipe! 224 endfunc 225 226 " vim: shiftwidth=2 sts=2 expandtab