drop_spec.lua 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local command = helpers.command
  3. local Screen = require('test.functional.ui.screen')
  4. local clear, feed, feed_command = helpers.clear, helpers.feed, helpers.feed_command
  5. describe(":drop", function()
  6. local screen
  7. before_each(function()
  8. clear()
  9. screen = Screen.new(35, 10)
  10. screen:attach()
  11. screen:set_default_attr_ids({
  12. [0] = {bold=true, foreground=Screen.colors.Blue},
  13. [1] = {bold = true, reverse = true},
  14. [2] = {reverse = true},
  15. [3] = {bold = true},
  16. })
  17. command("set laststatus=2 shortmess-=F")
  18. end)
  19. it("works like :e when called with only one window open", function()
  20. feed_command("drop tmp1.vim")
  21. screen:expect([[
  22. ^ |
  23. {0:~ }|
  24. {0:~ }|
  25. {0:~ }|
  26. {0:~ }|
  27. {0:~ }|
  28. {0:~ }|
  29. {0:~ }|
  30. {1:tmp1.vim }|
  31. "tmp1.vim" [New] |
  32. ]])
  33. end)
  34. it("switches to an open window showing the buffer", function()
  35. feed_command("edit tmp1")
  36. feed_command("vsplit")
  37. feed_command("edit tmp2")
  38. feed_command("drop tmp1")
  39. screen:expect([[
  40. │^ |
  41. {0:~ }│{0:~ }|
  42. {0:~ }│{0:~ }|
  43. {0:~ }│{0:~ }|
  44. {0:~ }│{0:~ }|
  45. {0:~ }│{0:~ }|
  46. {0:~ }│{0:~ }|
  47. {0:~ }│{0:~ }|
  48. {2:tmp2 }{1:tmp1 }|
  49. :drop tmp1 |
  50. ]])
  51. end)
  52. it("splits off a new window when a buffer can't be abandoned", function()
  53. command("set nohidden")
  54. feed_command("edit tmp1")
  55. feed_command("vsplit")
  56. feed_command("edit tmp2")
  57. feed("iABC<esc>")
  58. feed_command("drop tmp3")
  59. screen:expect([[
  60. ^ │ |
  61. {0:~ }│{0:~ }|
  62. {0:~ }│{0:~ }|
  63. {0:~ }│{0:~ }|
  64. {1:tmp3 }│{0:~ }|
  65. ABC │{0:~ }|
  66. {0:~ }│{0:~ }|
  67. {0:~ }│{0:~ }|
  68. {2:tmp2 [+] tmp1 }|
  69. "tmp3" [New] |
  70. ]])
  71. end)
  72. end)