close_count_spec.lua 4.1 KB

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