close_count_spec.lua 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. -- Tests for :[count]close! and :[count]hide
  2. local helpers = require('test.functional.helpers')(after_each)
  3. local eq = helpers.eq
  4. local poke_eventloop = helpers.poke_eventloop
  5. local eval = helpers.eval
  6. local feed = helpers.feed
  7. local clear = helpers.clear
  8. local command = helpers.command
  9. describe('close_count', function()
  10. setup(clear)
  11. it('is working', function()
  12. command('let tests = []')
  13. command('for i in range(5)|new|endfor')
  14. command('4wincmd w')
  15. command('close!')
  16. command('let buffers = []')
  17. command('windo call add(buffers, bufnr("%"))')
  18. eq({6, 5, 4, 2, 1}, eval('buffers'))
  19. command('1close!')
  20. command('let buffers = []')
  21. command('windo call add(buffers, bufnr("%"))')
  22. eq({5, 4, 2, 1}, eval('buffers'))
  23. command('$close!')
  24. command('let buffers = []')
  25. command('windo call add(buffers, bufnr("%"))')
  26. eq({5, 4, 2}, eval('buffers'))
  27. command('1wincmd w')
  28. command('2close!')
  29. command('let buffers = []')
  30. command('windo call add(buffers, bufnr("%"))')
  31. eq({5, 2}, eval('buffers'))
  32. command('1wincmd w')
  33. command('new')
  34. command('new')
  35. command('2wincmd w')
  36. command('-1close!')
  37. command('let buffers = []')
  38. command('windo call add(buffers, bufnr("%"))')
  39. eq({7, 5, 2}, eval('buffers'))
  40. command('2wincmd w')
  41. command('+1close!')
  42. command('let buffers = []')
  43. command('windo call add(buffers, bufnr("%"))')
  44. eq({7, 5}, eval('buffers'))
  45. command('only!')
  46. command('b1')
  47. command('let tests = []')
  48. command('for i in range(5)|new|endfor')
  49. command('let buffers = []')
  50. command('windo call add(buffers, bufnr("%"))')
  51. eq({13, 12, 11, 10, 9, 1}, eval('buffers'))
  52. command('4wincmd w')
  53. command('.hide')
  54. command('let buffers = []')
  55. command('windo call add(buffers, bufnr("%"))')
  56. eq({13, 12, 11, 9, 1}, eval('buffers'))
  57. command('1hide')
  58. command('let buffers = []')
  59. command('windo call add(buffers, bufnr("%"))')
  60. eq({12, 11, 9, 1}, eval('buffers'))
  61. command('$hide')
  62. command('let buffers = []')
  63. command('windo call add(buffers, bufnr("%"))')
  64. eq({12, 11, 9}, eval('buffers'))
  65. command('1wincmd w')
  66. command('2hide')
  67. command('let buffers = []')
  68. command('windo call add(buffers, bufnr("%"))')
  69. eq({12, 9}, eval('buffers'))
  70. command('1wincmd w')
  71. command('new')
  72. command('new')
  73. command('3wincmd w')
  74. command('-hide')
  75. command('let buffers = []')
  76. command('windo call add(buffers, bufnr("%"))')
  77. eq({15, 12, 9}, eval('buffers'))
  78. command('2wincmd w')
  79. command('+hide')
  80. command('let buffers = []')
  81. command('windo call add(buffers, bufnr("%"))')
  82. eq({15, 12}, eval('buffers'))
  83. command('only!')
  84. command('b1')
  85. command('let tests = []')
  86. command('set hidden')
  87. command('for i in range(5)|new|endfor')
  88. command('1wincmd w')
  89. command('$ hide')
  90. command('let buffers = []')
  91. command('windo call add(buffers, bufnr("%"))')
  92. eq({20, 19, 18, 17, 16}, eval('buffers'))
  93. command('$-1 close!')
  94. command('let buffers = []')
  95. command('windo call add(buffers, bufnr("%"))')
  96. eq({20, 19, 18, 16}, eval('buffers'))
  97. command('1wincmd w')
  98. command('.+close!')
  99. command('let buffers = []')
  100. command('windo call add(buffers, bufnr("%"))')
  101. eq({20, 18, 16}, eval('buffers'))
  102. command('only!')
  103. command('b1')
  104. command('let tests = []')
  105. command('set hidden')
  106. command('for i in range(5)|new|endfor')
  107. command('4wincmd w')
  108. feed('<C-W>c<cr>')
  109. poke_eventloop()
  110. command('let buffers = []')
  111. command('windo call add(buffers, bufnr("%"))')
  112. eq({25, 24, 23, 21, 1}, eval('buffers'))
  113. feed('1<C-W>c<cr>')
  114. poke_eventloop()
  115. command('let buffers = []')
  116. command('windo call add(buffers, bufnr("%"))')
  117. eq({24, 23, 21, 1}, eval('buffers'))
  118. feed('9<C-W>c<cr>')
  119. poke_eventloop()
  120. command('let buffers = []')
  121. command('windo call add(buffers, bufnr("%"))')
  122. eq({24, 23, 21}, eval('buffers'))
  123. command('1wincmd w')
  124. feed('2<C-W>c<cr>')
  125. poke_eventloop()
  126. command('let buffers = []')
  127. command('windo call add(buffers, bufnr("%"))')
  128. eq({24, 21}, eval('buffers'))
  129. end)
  130. end)