buffers_spec.lua 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. -- shada buffer list saving/reading support
  2. local t = require('test.testutil')
  3. local n = require('test.functional.testnvim')()
  4. local t_shada = require('test.functional.shada.testutil')
  5. local nvim_command, fn, eq, api = n.command, n.fn, t.eq, n.api
  6. local expect_exit = n.expect_exit
  7. local reset, clear = t_shada.reset, t_shada.clear
  8. describe('shada support code', function()
  9. local testfilename = 'Xtestfile-functional-shada-buffers'
  10. local testfilename_2 = 'Xtestfile-functional-shada-buffers-2'
  11. after_each(clear)
  12. it('is able to dump and restore buffer list', function()
  13. reset('set shada+=%')
  14. nvim_command('edit ' .. testfilename)
  15. nvim_command('edit ' .. testfilename_2)
  16. expect_exit(nvim_command, 'qall')
  17. reset('set shada+=%')
  18. eq(3, fn.bufnr('$'))
  19. eq('', fn.bufname(1))
  20. eq(testfilename, fn.bufname(2))
  21. eq(testfilename_2, fn.bufname(3))
  22. end)
  23. it('does not restore buffer list without % in &shada', function()
  24. reset('set shada+=%')
  25. nvim_command('edit ' .. testfilename)
  26. nvim_command('edit ' .. testfilename_2)
  27. expect_exit(nvim_command, 'qall')
  28. reset()
  29. eq(1, fn.bufnr('$'))
  30. eq('', fn.bufname(1))
  31. end)
  32. it('does not dump buffer list without % in &shada', function()
  33. reset()
  34. nvim_command('edit ' .. testfilename)
  35. nvim_command('edit ' .. testfilename_2)
  36. expect_exit(nvim_command, 'qall')
  37. reset('set shada+=%')
  38. eq(1, fn.bufnr('$'))
  39. eq('', fn.bufname(1))
  40. end)
  41. it('does not dump unlisted buffer', function()
  42. reset('set shada+=%')
  43. nvim_command('edit ' .. testfilename)
  44. nvim_command('edit ' .. testfilename_2)
  45. api.nvim_set_option_value('buflisted', false, {})
  46. expect_exit(nvim_command, 'qall')
  47. reset('set shada+=%')
  48. eq(2, fn.bufnr('$'))
  49. eq('', fn.bufname(1))
  50. eq(testfilename, fn.bufname(2))
  51. end)
  52. it('does not dump quickfix buffer', function()
  53. reset('set shada+=%')
  54. nvim_command('edit ' .. testfilename)
  55. nvim_command('edit ' .. testfilename_2)
  56. api.nvim_set_option_value('buftype', 'quickfix', {})
  57. expect_exit(nvim_command, 'qall')
  58. reset('set shada+=%')
  59. eq(2, fn.bufnr('$'))
  60. eq('', fn.bufname(1))
  61. eq(testfilename, fn.bufname(2))
  62. end)
  63. it('does not dump unnamed buffers', function()
  64. reset('set shada+=% hidden')
  65. api.nvim_buf_set_lines(0, 0, 1, true, { 'foo' })
  66. nvim_command('enew')
  67. api.nvim_buf_set_lines(0, 0, 1, true, { 'bar' })
  68. eq(2, fn.bufnr('$'))
  69. expect_exit(nvim_command, 'qall!')
  70. reset('set shada+=% hidden')
  71. eq(1, fn.bufnr('$'))
  72. eq('', fn.bufname(1))
  73. end)
  74. it('restores 1 buffer with %1 in &shada, #5759', function()
  75. reset('set shada+=%1')
  76. nvim_command('edit ' .. testfilename)
  77. nvim_command('edit ' .. testfilename_2)
  78. expect_exit(nvim_command, 'qall')
  79. reset('set shada+=%1')
  80. eq(2, fn.bufnr('$'))
  81. eq('', fn.bufname(1))
  82. eq(testfilename, fn.bufname(2))
  83. end)
  84. end)