1" Tests for the getbufinfo(), getwininfo() and gettabinfo() functions 2 3function Test_getbufwintabinfo() 4 edit Xtestfile1 5 edit Xtestfile2 6 let buflist = getbufinfo() 7 call assert_equal(2, len(buflist)) 8 call assert_match('Xtestfile1', buflist[0].name) 9 call assert_match('Xtestfile2', getbufinfo('Xtestfile2')[0].name) 10 call assert_equal([], getbufinfo(2016)) 11 edit Xtestfile1 12 hide edit Xtestfile2 13 hide enew 14 call assert_equal(3, len(getbufinfo({'bufloaded':1}))) 15 16 set tabstop&vim 17 let b:editor = 'vim' 18 let l = getbufinfo('%') 19 call assert_equal(bufnr('%'), l[0].bufnr) 20 call assert_equal('vim', l[0].variables.editor) 21 call assert_notequal(-1, index(l[0].windows, bufwinid('%'))) 22 23 " Test for getbufinfo() with 'bufmodified' 24 call assert_equal(0, len(getbufinfo({'bufmodified' : 1}))) 25 call setbufline('Xtestfile1', 1, ["Line1"]) 26 let l = getbufinfo({'bufmodified' : 1}) 27 call assert_equal(1, len(l)) 28 call assert_equal(bufnr('Xtestfile1'), l[0].bufnr) 29 30 if has('signs') 31 call append(0, ['Linux', 'Windows', 'Mac']) 32 sign define Mark text=>> texthl=Search 33 exe "sign place 2 line=3 name=Mark buffer=" . bufnr('%') 34 let l = getbufinfo('%') 35 call assert_equal(2, l[0].signs[0].id) 36 call assert_equal(3, l[0].signs[0].lnum) 37 call assert_equal('Mark', l[0].signs[0].name) 38 sign unplace * 39 sign undefine Mark 40 enew! 41 endif 42 43 only 44 let w1_id = win_getid() 45 new 46 let w2_id = win_getid() 47 tabnew | let w3_id = win_getid() 48 new | let w4_id = win_getid() 49 new | let w5_id = win_getid() 50 call setwinvar(0, 'signal', 'green') 51 tabfirst 52 let winlist = getwininfo() 53 call assert_equal(5, len(winlist)) 54 call assert_equal(winbufnr(2), winlist[1].bufnr) 55 call assert_equal(winheight(2), winlist[1].height) 56 call assert_equal(1, winlist[2].winnr) 57 call assert_equal(2, winlist[3].tabnr) 58 call assert_equal('green', winlist[2].variables.signal) 59 call assert_equal(winwidth(1), winlist[0].width) 60 call assert_equal(w4_id, winlist[3].winid) 61 let winfo = getwininfo(w5_id)[0] 62 call assert_equal(2, winfo.tabnr) 63 call assert_equal([], getwininfo(3)) 64 65 call settabvar(1, 'space', 'build') 66 let tablist = gettabinfo() 67 call assert_equal(2, len(tablist)) 68 call assert_equal(3, len(tablist[1].windows)) 69 call assert_equal(2, tablist[1].tabnr) 70 call assert_equal('build', tablist[0].variables.space) 71 call assert_equal(w2_id, tablist[0].windows[0]) 72 call assert_equal([], gettabinfo(3)) 73 74 tabonly | only 75 76 lexpr '' 77 lopen 78 copen 79 let winlist = getwininfo() 80 call assert_false(winlist[0].quickfix) 81 call assert_false(winlist[0].loclist) 82 call assert_true(winlist[1].quickfix) 83 call assert_true(winlist[1].loclist) 84 call assert_true(winlist[2].quickfix) 85 call assert_false(winlist[2].loclist) 86 wincmd t | only 87endfunction 88 89function Test_get_buf_options() 90 let opts = getbufvar(bufnr('%'), '&') 91 call assert_equal(v:t_dict, type(opts)) 92 call assert_equal(8, opts.tabstop) 93endfunc 94 95function Test_get_win_options() 96 if has('folding') 97 set foldlevel=999 98 endif 99 set list 100 let opts = getwinvar(1, '&') 101 call assert_equal(v:t_dict, type(opts)) 102 call assert_equal(0, opts.linebreak) 103 call assert_equal(1, opts.list) 104 if has('folding') 105 call assert_equal(999, opts.foldlevel) 106 endif 107 if has('signs') 108 call assert_equal('auto', opts.signcolumn) 109 endif 110 111 let opts = gettabwinvar(1, 1, '&') 112 call assert_equal(v:t_dict, type(opts)) 113 call assert_equal(0, opts.linebreak) 114 call assert_equal(1, opts.list) 115 if has('signs') 116 call assert_equal('auto', opts.signcolumn) 117 endif 118 set list& 119 if has('folding') 120 set foldlevel=0 121 endif 122endfunc 123