1" Tests for the getbufinfo(), getwininfo() and gettabinfo() functions 2source check.vim 3 4func 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(test_null_dict())) 49 50 only 51 let w1_id = win_getid() 52 new 53 let w2_id = win_getid() 54 tabnew | let w3_id = win_getid() 55 new | let w4_id = win_getid() 56 vert new | let w5_id = win_getid() 57 eval 'green'->setwinvar(0, 'signal') 58 tabfirst 59 let winlist = getwininfo() 60 call assert_equal(5, len(winlist)) 61 call assert_equal(winwidth(1), winlist[0].width) 62 call assert_equal(1, winlist[0].wincol) 63 " tabline adds one row in terminal, not in GUI 64 let tablineheight = winlist[0].winrow == 2 ? 1 : 0 65 call assert_equal(tablineheight + 1, winlist[0].winrow) 66 67 call assert_equal(winbufnr(2), winlist[1].bufnr) 68 call assert_equal(winheight(2), winlist[1].height) 69 call assert_equal(1, winlist[1].wincol) 70 call assert_equal(tablineheight + winheight(1) + 2, winlist[1].winrow) 71 72 call assert_equal(1, winlist[2].winnr) 73 call assert_equal(tablineheight + 1, winlist[2].winrow) 74 call assert_equal(1, winlist[2].wincol) 75 76 call assert_equal(winlist[2].width + 2, winlist[3].wincol) 77 call assert_equal(1, winlist[4].wincol) 78 79 call assert_equal(1, winlist[0].tabnr) 80 call assert_equal(1, winlist[1].tabnr) 81 call assert_equal(2, winlist[2].tabnr) 82 call assert_equal(2, winlist[3].tabnr) 83 call assert_equal(2, winlist[4].tabnr) 84 85 call assert_equal('green', winlist[2].variables.signal) 86 call assert_equal(w4_id, winlist[3].winid) 87 let winfo = w5_id->getwininfo()[0] 88 call assert_equal(2, winfo.tabnr) 89 call assert_equal([], getwininfo(3)) 90 91 call settabvar(1, 'space', 'build') 92 let tablist = gettabinfo() 93 call assert_equal(2, len(tablist)) 94 call assert_equal(3, len(tablist[1].windows)) 95 call assert_equal(2, tablist[1].tabnr) 96 call assert_equal('build', tablist[0].variables.space) 97 call assert_equal(w2_id, tablist[0].windows[0]) 98 call assert_equal([], 3->gettabinfo()) 99 100 tabonly | only 101 102 lexpr '' 103 lopen 104 copen 105 let winlist = getwininfo() 106 call assert_false(winlist[0].quickfix) 107 call assert_false(winlist[0].loclist) 108 call assert_true(winlist[1].quickfix) 109 call assert_true(winlist[1].loclist) 110 call assert_true(winlist[2].quickfix) 111 call assert_false(winlist[2].loclist) 112 wincmd t | only 113endfunc 114 115function Test_get_buf_options() 116 let opts = bufnr()->getbufvar('&') 117 call assert_equal(v:t_dict, type(opts)) 118 call assert_equal(8, opts.tabstop) 119endfunc 120 121function Test_get_win_options() 122 if has('folding') 123 set foldlevel=999 124 endif 125 set list 126 let opts = getwinvar(1, '&') 127 call assert_equal(v:t_dict, type(opts)) 128 call assert_equal(0, opts.linebreak) 129 call assert_equal(1, opts.list) 130 if has('folding') 131 call assert_equal(999, opts.foldlevel) 132 endif 133 if has('signs') 134 call assert_equal('auto', opts.signcolumn) 135 endif 136 137 let opts = gettabwinvar(1, 1, '&') 138 call assert_equal(v:t_dict, type(opts)) 139 call assert_equal(0, opts.linebreak) 140 call assert_equal(1, opts.list) 141 if has('signs') 142 call assert_equal('auto', opts.signcolumn) 143 endif 144 set list& 145 if has('folding') 146 set foldlevel=0 147 endif 148endfunc 149 150function Test_getbufinfo_lastused() 151 call test_settime(1234567) 152 edit Xtestfile1 153 enew 154 call test_settime(7654321) 155 edit Xtestfile2 156 enew 157 call assert_equal(getbufinfo('Xtestfile1')[0].lastused, 1234567) 158 call assert_equal(getbufinfo('Xtestfile2')[0].lastused, 7654321) 159 call test_settime(0) 160endfunc 161 162func Test_getbufinfo_lines() 163 new Xfoo 164 call setline(1, ['a', 'bc', 'd']) 165 let bn = bufnr('%') 166 hide 167 call assert_equal(3, getbufinfo(bn)[0]["linecount"]) 168 edit Xfoo 169 bw! 170endfunc 171