2015-05-07 00:26:04 -07:00
|
|
|
local helpers, lfs = require('test.functional.helpers'), require('lfs')
|
2015-11-17 15:31:22 -07:00
|
|
|
local execute, eq, neq, spawn, nvim_prog, set_session, wait, write_file
|
|
|
|
= helpers.execute, helpers.eq, helpers.neq, helpers.spawn,
|
2015-06-30 05:16:22 -07:00
|
|
|
helpers.nvim_prog, helpers.set_session, helpers.wait, helpers.write_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
|
|
|
if session then
|
|
|
|
session:exit(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Override the default session because we need 'swapfile' for these tests.
|
2015-11-17 15:31:22 -07:00
|
|
|
session = spawn({nvim_prog, '-u', 'NONE', '-i', '/dev/null', '--embed',
|
2015-06-12 00:09:12 -07:00
|
|
|
'--cmd', 'set swapfile'})
|
|
|
|
set_session(session)
|
|
|
|
|
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))
|
2015-07-05 16:26:44 -07:00
|
|
|
execute('wsh! '..shada_file)
|
2015-05-07 00:26:04 -07:00
|
|
|
wait()
|
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
|
2015-07-05 16:16:05 -07:00
|
|
|
eq(text, io.open(shada_file):read())
|
|
|
|
neq(nil, lfs.attributes(shada_file))
|
2015-06-12 00:09:12 -07:00
|
|
|
|
2015-07-05 16:26:44 -07:00
|
|
|
execute('wsh! '..shada_file)
|
2015-05-07 00:26:04 -07:00
|
|
|
wait()
|
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)
|
|
|
|
|
|
|
|
teardown(function()
|
2015-07-05 16:16:05 -07:00
|
|
|
os.remove(shada_file)
|
2015-05-07 00:26:04 -07:00
|
|
|
end)
|
|
|
|
end)
|