wviminfo_spec.lua 1.4 KB

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