drop_spec.lua 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. local n = require('test.functional.testnvim')()
  2. local Screen = require('test.functional.ui.screen')
  3. local command = n.command
  4. local clear, feed, feed_command = n.clear, n.feed, n.feed_command
  5. local exec = n.exec
  6. describe(':drop', function()
  7. local screen
  8. before_each(function()
  9. clear()
  10. screen = Screen.new(35, 10)
  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 nohidden 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:~ }|*7
  24. {1:tmp1.vim }|
  25. "tmp1.vim" [New] |
  26. ]])
  27. end)
  28. it('switches to an open window showing the buffer', function()
  29. feed_command('edit tmp1')
  30. feed_command('vsplit')
  31. feed_command('edit tmp2')
  32. feed_command('drop tmp1')
  33. screen:expect([[
  34. │^ |
  35. {0:~ }│{0:~ }|*7
  36. {2:tmp2 }{1:tmp1 }|
  37. "tmp1" [New] |
  38. ]])
  39. end)
  40. it("splits off a new window when a buffer can't be abandoned", function()
  41. feed_command('edit tmp1')
  42. feed_command('vsplit')
  43. feed_command('edit tmp2')
  44. feed('iABC<esc>')
  45. feed_command('drop tmp3')
  46. screen:expect([[
  47. ^ │ |
  48. {0:~ }│{0:~ }|*3
  49. {1:tmp3 }│{0:~ }|
  50. ABC │{0:~ }|
  51. {0:~ }│{0:~ }|*2
  52. {2:tmp2 [+] tmp1 }|
  53. "tmp3" [New] |
  54. ]])
  55. end)
  56. -- oldtest: Test_drop_modified_file()
  57. it('does not cause E37 with modified same file', function()
  58. exec([[
  59. edit Xdrop_modified.txt
  60. call setline(1, 'The quick brown fox jumped over the lazy dogs')
  61. ]])
  62. feed_command('drop Xdrop_modified.txt')
  63. screen:expect([[
  64. ^The quick brown fox jumped over the|
  65. lazy dogs |
  66. {0:~ }|*6
  67. {1:Xdrop_modified.txt [+] }|
  68. :drop Xdrop_modified.txt |
  69. ]])
  70. end)
  71. end)