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