2016-04-23 16:53:11 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
|
|
|
local lfs = require('lfs')
|
2017-04-08 14:12:26 -07:00
|
|
|
local command, eq, neq, spawn, nvim_prog, set_session, write_file =
|
|
|
|
helpers.command, helpers.eq, helpers.neq, helpers.spawn,
|
|
|
|
helpers.nvim_prog, helpers.set_session, helpers.write_file
|
2018-05-21 12:18:32 -07:00
|
|
|
local iswin = helpers.iswin
|
|
|
|
local read_file = helpers.read_file
|
2015-05-07 00:26:04 -07:00
|
|
|
|
2015-07-05 16:26:44 -07:00
|
|
|
describe(':wshada', function()
|
|
|
|
local shada_file = 'wshada_test'
|
2015-06-12 00:09:12 -07:00
|
|
|
local session
|
|
|
|
|
2015-05-07 00:26:04 -07:00
|
|
|
before_each(function()
|
2015-06-12 00:09:12 -07:00
|
|
|
-- Override the default session because we need 'swapfile' for these tests.
|
2018-05-21 12:18:32 -07:00
|
|
|
session = spawn({nvim_prog, '-u', 'NONE', '-i', iswin() and 'nul' or '/dev/null', '--embed',
|
2015-06-12 00:09:12 -07:00
|
|
|
'--cmd', 'set swapfile'})
|
|
|
|
set_session(session)
|
2018-05-21 12:18:32 -07:00
|
|
|
end)
|
|
|
|
after_each(function ()
|
|
|
|
session:close()
|
2015-07-05 16:16:05 -07:00
|
|
|
os.remove(shada_file)
|
2015-05-07 00:26:04 -07:00
|
|
|
end)
|
|
|
|
|
2015-07-05 16:16:05 -07:00
|
|
|
it('creates a shada file', function()
|
2015-06-12 00:09:12 -07:00
|
|
|
-- file should _not_ exist
|
2015-07-05 16:16:05 -07:00
|
|
|
eq(nil, lfs.attributes(shada_file))
|
2017-04-08 14:12:26 -07:00
|
|
|
command('wsh! '..shada_file)
|
2015-06-12 00:09:12 -07:00
|
|
|
-- file _should_ exist
|
2015-07-05 16:16:05 -07:00
|
|
|
neq(nil, lfs.attributes(shada_file))
|
2015-05-07 00:26:04 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('overwrites existing files', function()
|
2015-07-05 16:26:44 -07:00
|
|
|
local text = 'wshada test'
|
2015-05-07 00:26:04 -07:00
|
|
|
|
2015-06-12 00:09:12 -07:00
|
|
|
-- Create a dummy file
|
2015-07-05 16:16:05 -07:00
|
|
|
write_file(shada_file, text)
|
2015-06-12 00:09:12 -07:00
|
|
|
|
|
|
|
-- sanity check
|
2018-05-21 12:18:32 -07:00
|
|
|
eq(text, read_file(shada_file))
|
2015-07-05 16:16:05 -07:00
|
|
|
neq(nil, lfs.attributes(shada_file))
|
2015-06-12 00:09:12 -07:00
|
|
|
|
2017-04-08 14:12:26 -07:00
|
|
|
command('wsh! '..shada_file)
|
2015-06-12 00:09:12 -07:00
|
|
|
|
2015-07-05 16:16:05 -07:00
|
|
|
-- File should have been overwritten with a shada file.
|
|
|
|
local fp = io.open(shada_file, 'r')
|
|
|
|
local char1 = fp:read(1)
|
|
|
|
fp:close()
|
|
|
|
-- ShaDa file starts with a “header” entry
|
|
|
|
assert(char1:byte() == 0x01,
|
|
|
|
shada_file..' should be a shada file')
|
2015-05-07 00:26:04 -07:00
|
|
|
end)
|
|
|
|
end)
|