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 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(tablineheight + winheight(1) + 2, winlist[1].winrow) 72 73 call assert_equal(1, winlist[2].winnr) 74 call assert_equal(tablineheight + 1, winlist[2].winrow) 75 call assert_equal(1, winlist[2].wincol) 76 77 call assert_equal(winlist[2].width + 2, winlist[3].wincol) 78 call assert_equal(1, winlist[4].wincol) 79 80 call assert_equal(1, winlist[0].tabnr) 81 call assert_equal(1, winlist[1].tabnr) 82 call assert_equal(2, winlist[2].tabnr) 83 call assert_equal(2, winlist[3].tabnr) 84 call assert_equal(2, winlist[4].tabnr) 85 86 call assert_equal('green', winlist[2].variables.signal) 87 call assert_equal(w4_id, winlist[3].winid) 88 let winfo = w5_id->getwininfo()[0] 89 call assert_equal(2, winfo.tabnr) 90 call assert_equal([], getwininfo(3)) 91 92 call settabvar(1, 'space', 'build') 93 let tablist = gettabinfo() 94 call assert_equal(2, len(tablist)) 95 call assert_equal(3, len(tablist[1].windows)) 96 call assert_equal(2, tablist[1].tabnr) 97 call assert_equal('build', tablist[0].variables.space) 98 call assert_equal(w2_id, tablist[0].windows[0]) 99 call assert_equal([], 3->gettabinfo()) 100 101 tabonly | only 102 103 lexpr '' 104 lopen 105 copen 106 let winlist = getwininfo() 107 call assert_false(winlist[0].quickfix) 108 call assert_false(winlist[0].loclist) 109 call assert_true(winlist[1].quickfix) 110 call assert_true(winlist[1].loclist) 111 call assert_true(winlist[2].quickfix) 112 call assert_false(winlist[2].loclist) 113 wincmd t | only 114endfunc 115 116function Test_get_buf_options() 117 let opts = bufnr()->getbufvar('&') 118 call assert_equal(v:t_dict, type(opts)) 119 call assert_equal(8, opts.tabstop) 120endfunc 121 122function Test_get_win_options() 123 if has('folding') 124 set foldlevel=999 125 endif 126 set list 127 let opts = getwinvar(1, '&') 128 call assert_equal(v:t_dict, type(opts)) 129 call assert_equal(0, opts.linebreak) 130 call assert_equal(1, opts.list) 131 if has('folding') 132 call assert_equal(999, opts.foldlevel) 133 endif 134 if has('signs') 135 call assert_equal('auto', opts.signcolumn) 136 endif 137 138 let opts = gettabwinvar(1, 1, '&') 139 call assert_equal(v:t_dict, type(opts)) 140 call assert_equal(0, opts.linebreak) 141 call assert_equal(1, opts.list) 142 if has('signs') 143 call assert_equal('auto', opts.signcolumn) 144 endif 145 set list& 146 if has('folding') 147 set foldlevel=0 148 endif 149endfunc 150 151function Test_getbufinfo_lastused() 152 call test_settime(1234567) 153 edit Xtestfile1 154 enew 155 call test_settime(7654321) 156 edit Xtestfile2 157 enew 158 call assert_equal(getbufinfo('Xtestfile1')[0].lastused, 1234567) 159 call assert_equal(getbufinfo('Xtestfile2')[0].lastused, 7654321) 160 call test_settime(0) 161endfunc 162 163func Test_getbufinfo_lines() 164 new Xfoo 165 call setline(1, ['a', 'bc', 'd']) 166 let bn = bufnr('%') 167 hide 168 call assert_equal(3, getbufinfo(bn)[0]["linecount"]) 169 edit Xfoo 170 bw! 171endfunc 172 173" vim: shiftwidth=2 sts=2 expandtab 174