test_bufwintabinfo.vim 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. " Tests for the getbufinfo(), getwininfo() and gettabinfo() functions
  2. source check.vim
  3. func Test_getbufwintabinfo()
  4. CheckFeature quickfix
  5. edit Xtestfile1
  6. edit Xtestfile2
  7. let buflist = getbufinfo()
  8. call assert_equal(2, len(buflist))
  9. call assert_match('Xtestfile1', buflist[0].name)
  10. call assert_match('Xtestfile2', getbufinfo('Xtestfile2')[0].name)
  11. call assert_equal([], getbufinfo(2016))
  12. edit Xtestfile1
  13. hide edit Xtestfile2
  14. hide enew
  15. call assert_equal(3, len(getbufinfo({'bufloaded':1})))
  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. let l = '%'->getbufinfo()
  23. call assert_equal(bufnr('%'), l[0].bufnr)
  24. " Test for getbufinfo() with 'bufmodified'
  25. call assert_equal(0, len(getbufinfo({'bufmodified' : 1})))
  26. call setbufline('Xtestfile1', 1, ["Line1"])
  27. let l = getbufinfo({'bufmodified' : 1})
  28. call assert_equal(1, len(l))
  29. call assert_equal(bufnr('Xtestfile1'), l[0].bufnr)
  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. call assert_notequal([], getbufinfo(v:_null_dict))
  43. only
  44. let w1_id = win_getid()
  45. setl foldcolumn=3
  46. new
  47. let w2_id = win_getid()
  48. tabnew | let w3_id = win_getid()
  49. new | let w4_id = win_getid()
  50. vert new | let w5_id = win_getid()
  51. eval 'green'->setwinvar(0, 'signal')
  52. tabfirst
  53. let winlist = getwininfo()
  54. call assert_equal(5, len(winlist))
  55. call assert_equal(winwidth(1), winlist[0].width)
  56. call assert_equal(1, winlist[0].wincol)
  57. " tabline adds one row in terminal, not in GUI
  58. let tablineheight = winlist[0].winrow == 2 ? 1 : 0
  59. call assert_equal(tablineheight + 1, winlist[0].winrow)
  60. call assert_equal(winbufnr(2), winlist[1].bufnr)
  61. call assert_equal(winheight(2), winlist[1].height)
  62. call assert_equal(1, winlist[1].wincol)
  63. call assert_equal(3, winlist[1].textoff) " foldcolumn
  64. call assert_equal(tablineheight + winheight(1) + 2, winlist[1].winrow)
  65. call assert_equal(1, winlist[2].winnr)
  66. call assert_equal(tablineheight + 1, winlist[2].winrow)
  67. call assert_equal(1, winlist[2].wincol)
  68. call assert_equal(winlist[2].width + 2, winlist[3].wincol)
  69. call assert_equal(1, winlist[4].wincol)
  70. call assert_equal(1, winlist[0].tabnr)
  71. call assert_equal(1, winlist[1].tabnr)
  72. call assert_equal(2, winlist[2].tabnr)
  73. call assert_equal(2, winlist[3].tabnr)
  74. call assert_equal(2, winlist[4].tabnr)
  75. call assert_equal('green', winlist[2].variables.signal)
  76. call assert_equal(w4_id, winlist[3].winid)
  77. let winfo = w5_id->getwininfo()[0]
  78. call assert_equal(2, winfo.tabnr)
  79. call assert_equal([], getwininfo(3))
  80. call settabvar(1, 'space', 'build')
  81. let tablist = gettabinfo()
  82. call assert_equal(2, len(tablist))
  83. call assert_equal(3, len(tablist[1].windows))
  84. call assert_equal(2, tablist[1].tabnr)
  85. call assert_equal('build', tablist[0].variables.space)
  86. call assert_equal(w2_id, tablist[0].windows[0])
  87. call assert_equal([], 3->gettabinfo())
  88. tabonly | only
  89. lexpr ''
  90. lopen
  91. copen
  92. let winlist = getwininfo()
  93. call assert_false(winlist[0].quickfix)
  94. call assert_false(winlist[0].loclist)
  95. call assert_true(winlist[1].quickfix)
  96. call assert_true(winlist[1].loclist)
  97. call assert_true(winlist[2].quickfix)
  98. call assert_false(winlist[2].loclist)
  99. wincmd t | only
  100. endfunc
  101. function Test_get_wininfo_leftcol()
  102. set nowrap
  103. set winwidth=10
  104. vsp
  105. call setline(1, ['abcdefghijklmnopqrstuvwxyz'])
  106. norm! 5zl
  107. call assert_equal(5, getwininfo()[0].leftcol)
  108. bwipe!
  109. set wrap&
  110. set winwidth&
  111. endfunc
  112. function 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)
  116. endfunc
  117. function Test_get_win_options()
  118. if has('folding')
  119. set foldlevel=999
  120. endif
  121. set list
  122. let opts = getwinvar(1, '&')
  123. call assert_equal(v:t_dict, type(opts))
  124. call assert_equal(0, opts.linebreak)
  125. call assert_equal(1, opts.list)
  126. if has('folding')
  127. call assert_equal(999, opts.foldlevel)
  128. endif
  129. if has('signs')
  130. call assert_equal('auto', opts.signcolumn)
  131. endif
  132. let opts = gettabwinvar(1, 1, '&')
  133. call assert_equal(v:t_dict, type(opts))
  134. call assert_equal(0, opts.linebreak)
  135. call assert_equal(1, opts.list)
  136. if has('signs')
  137. call assert_equal('auto', opts.signcolumn)
  138. endif
  139. set list&
  140. if has('folding')
  141. set foldlevel=0
  142. endif
  143. endfunc
  144. function Test_getbufinfo_lastused()
  145. new Xfoo
  146. let info = getbufinfo('Xfoo')[0]
  147. call assert_equal(has_key(info, 'lastused'), 1)
  148. call assert_equal(type(info.lastused), type(0))
  149. endfunc
  150. func Test_getbufinfo_lines()
  151. new Xfoo
  152. call setline(1, ['a', 'bc', 'd'])
  153. let bn = bufnr('%')
  154. hide
  155. call assert_equal(3, getbufinfo(bn)[0]["linecount"])
  156. edit Xfoo
  157. bw!
  158. endfunc
  159. func Test_getwininfo_au()
  160. enew
  161. call setline(1, range(1, 16))
  162. let g:info = #{}
  163. augroup T1
  164. au!
  165. au WinEnter * let g:info = getwininfo(win_getid())[0]
  166. augroup END
  167. 4split
  168. " Check that calling getwininfo() from WinEnter returns fresh values for
  169. " topline and botline.
  170. call assert_equal(1, g:info.topline)
  171. call assert_equal(4, g:info.botline)
  172. close
  173. unlet g:info
  174. augroup! T1
  175. bwipe!
  176. endfunc
  177. " vim: shiftwidth=2 sts=2 expandtab