wviminfo_spec.lua 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local clear = n.clear
  4. local command, eq, neq, write_file = n.command, t.eq, t.neq, t.write_file
  5. local read_file = t.read_file
  6. local is_os = t.is_os
  7. describe(':wshada', function()
  8. local shada_file = 'wshada_test'
  9. before_each(function()
  10. clear {
  11. args = {
  12. '-i',
  13. is_os('win') and 'nul' or '/dev/null',
  14. -- Need 'swapfile' for these tests.
  15. '--cmd',
  16. 'set swapfile undodir=. directory=. viewdir=. backupdir=. belloff= noshowcmd noruler',
  17. },
  18. args_rm = { '-n', '-i', '--cmd' },
  19. }
  20. end)
  21. after_each(function()
  22. os.remove(shada_file)
  23. end)
  24. it('creates a shada file', function()
  25. -- file should _not_ exist
  26. eq(nil, vim.uv.fs_stat(shada_file))
  27. command('wsh! ' .. shada_file)
  28. -- file _should_ exist
  29. neq(nil, vim.uv.fs_stat(shada_file))
  30. end)
  31. it('overwrites existing files', function()
  32. local text = 'wshada test'
  33. -- Create a dummy file
  34. write_file(shada_file, text)
  35. -- sanity check
  36. eq(text, read_file(shada_file))
  37. neq(nil, vim.uv.fs_stat(shada_file))
  38. command('wsh! ' .. shada_file)
  39. -- File should have been overwritten with a shada file.
  40. local fp = io.open(shada_file, 'r')
  41. local char1 = fp:read(1)
  42. fp:close()
  43. -- ShaDa file starts with a “header” entry
  44. assert(char1:byte() == 0x01, shada_file .. ' should be a shada file')
  45. end)
  46. end)