test_bufwintabinfo.vim 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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_buf_options()
  102. let opts = bufnr()->getbufvar('&')
  103. call assert_equal(v:t_dict, type(opts))
  104. call assert_equal(8, opts.tabstop)
  105. endfunc
  106. function Test_get_win_options()
  107. if has('folding')
  108. set foldlevel=999
  109. endif
  110. set list
  111. let opts = getwinvar(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('folding')
  116. call assert_equal(999, opts.foldlevel)
  117. endif
  118. if has('signs')
  119. call assert_equal('auto', opts.signcolumn)
  120. endif
  121. let opts = gettabwinvar(1, 1, '&')
  122. call assert_equal(v:t_dict, type(opts))
  123. call assert_equal(0, opts.linebreak)
  124. call assert_equal(1, opts.list)
  125. if has('signs')
  126. call assert_equal('auto', opts.signcolumn)
  127. endif
  128. set list&
  129. if has('folding')
  130. set foldlevel=0
  131. endif
  132. endfunc
  133. function Test_getbufinfo_lastused()
  134. new Xfoo
  135. let info = getbufinfo('Xfoo')[0]
  136. call assert_equal(has_key(info, 'lastused'), 1)
  137. call assert_equal(type(info.lastused), type(0))
  138. endfunc
  139. func Test_getbufinfo_lines()
  140. new Xfoo
  141. call setline(1, ['a', 'bc', 'd'])
  142. let bn = bufnr('%')
  143. hide
  144. call assert_equal(3, getbufinfo(bn)[0]["linecount"])
  145. edit Xfoo
  146. bw!
  147. endfunc
  148. func Test_getwininfo_au()
  149. enew
  150. call setline(1, range(1, 16))
  151. let g:info = #{}
  152. augroup T1
  153. au!
  154. au WinEnter * let g:info = getwininfo(win_getid())[0]
  155. augroup END
  156. 4split
  157. " Check that calling getwininfo() from WinEnter returns fresh values for
  158. " topline and botline.
  159. call assert_equal(1, g:info.topline)
  160. call assert_equal(4, g:info.botline)
  161. close
  162. unlet g:info
  163. augroup! T1
  164. bwipe!
  165. endfunc
  166. " vim: shiftwidth=2 sts=2 expandtab