031_close_commands_spec.lua 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. -- Test for commands that close windows and/or buffers
  2. -- :quit
  3. -- :close
  4. -- :hide
  5. -- :only
  6. -- :sall
  7. -- :all
  8. -- :ball
  9. -- :buf
  10. -- :edit
  11. local helpers = require('test.functional.helpers')(after_each)
  12. local feed = helpers.feed
  13. local clear = helpers.clear
  14. local source = helpers.source
  15. local insert = helpers.insert
  16. local expect = helpers.expect
  17. local feed_command = helpers.feed_command
  18. describe('Commands that close windows and/or buffers', function()
  19. local function cleanup()
  20. os.remove('Xtest1')
  21. os.remove('Xtest2')
  22. os.remove('Xtest3')
  23. end
  24. setup(function()
  25. cleanup()
  26. clear()
  27. end)
  28. teardown(function()
  29. cleanup()
  30. end)
  31. it('is working', function()
  32. insert('testtext')
  33. feed('GA 1<Esc>:$w! Xtest1<CR>')
  34. feed('$r2:$w! Xtest2<CR>')
  35. feed('$r3:$w! Xtest3<CR>')
  36. feed_command('n! Xtest1 Xtest2')
  37. feed('A 1<Esc>:set hidden<CR>')
  38. -- Test for working :n when hidden set
  39. feed_command('n')
  40. expect('testtext 2')
  41. -- Test for failing :rew when hidden not set
  42. feed_command('set nohidden')
  43. feed('A 2<Esc>:rew<CR>')
  44. expect('testtext 2 2')
  45. -- Test for working :rew when hidden set
  46. feed_command('set hidden')
  47. feed_command('rew')
  48. expect('testtext 1 1')
  49. -- Test for :all keeping a buffer when it's modified
  50. feed_command('set nohidden')
  51. feed('A 1<Esc>:sp<CR>')
  52. feed_command('n Xtest2 Xtest3')
  53. feed_command('all')
  54. feed_command('1wincmd w')
  55. expect('testtext 1 1 1')
  56. -- Test abandoning changed buffer, should be unloaded even when 'hidden' set
  57. feed_command('set hidden')
  58. feed('A 1<Esc>:q!<CR>')
  59. expect('testtext 2 2')
  60. feed_command('unhide')
  61. expect('testtext 2 2')
  62. -- Test ":hide" hides anyway when 'hidden' not set
  63. feed_command('set nohidden')
  64. feed('A 2<Esc>:hide<CR>')
  65. expect('testtext 3')
  66. -- Test ":edit" failing in modified buffer when 'hidden' not set
  67. feed('A 3<Esc>:e Xtest1<CR>')
  68. expect('testtext 3 3')
  69. -- Test ":edit" working in modified buffer when 'hidden' set
  70. feed_command('set hidden')
  71. feed_command('e Xtest1')
  72. expect('testtext 1')
  73. -- Test ":close" not hiding when 'hidden' not set in modified buffer
  74. feed_command('sp Xtest3')
  75. feed_command('set nohidden')
  76. feed('A 3<Esc>:close<CR>')
  77. expect('testtext 3 3 3')
  78. -- Test ":close!" does hide when 'hidden' not set in modified buffer
  79. feed('A 3<Esc>:close!<CR>')
  80. feed_command('set nohidden')
  81. expect('testtext 1')
  82. -- Test ":all!" hides changed buffer
  83. feed_command('sp Xtest4')
  84. feed('GA 4<Esc>:all!<CR>')
  85. feed_command('1wincmd w')
  86. expect('testtext 2 2 2')
  87. -- Test ":q!" and hidden buffer.
  88. feed_command('bw! Xtest1 Xtest2 Xtest3 Xtest4')
  89. feed_command('sp Xtest1')
  90. feed_command('wincmd w')
  91. feed_command('bw!')
  92. feed_command('set modified')
  93. feed_command('bot sp Xtest2')
  94. feed_command('set modified')
  95. feed_command('bot sp Xtest3')
  96. feed_command('set modified')
  97. feed_command('wincmd t')
  98. feed_command('hide')
  99. feed_command('q!')
  100. expect('testtext 3')
  101. feed_command('q!')
  102. feed('<CR>')
  103. expect('testtext 1')
  104. source([[
  105. q!
  106. " Now nvim should have exited
  107. throw "Oh, Not finished yet."]])
  108. end)
  109. end)