2024-04-20 08:44:13 -07:00
|
|
|
local t = require('test.testutil')
|
|
|
|
local n = require('test.functional.testnvim')()
|
|
|
|
|
|
|
|
local clear = n.clear
|
|
|
|
local command, eq, neq, write_file = n.command, t.eq, t.neq, t.write_file
|
2024-04-08 02:03:20 -07:00
|
|
|
local read_file = t.read_file
|
|
|
|
local is_os = t.is_os
|
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
|
|
|
|
2015-05-07 00:26:04 -07:00
|
|
|
before_each(function()
|
2022-11-21 17:13:30 -07:00
|
|
|
clear {
|
|
|
|
args = {
|
|
|
|
'-i',
|
|
|
|
is_os('win') and 'nul' or '/dev/null',
|
2019-04-16 16:08:48 -07:00
|
|
|
-- Need 'swapfile' for these tests.
|
|
|
|
'--cmd',
|
|
|
|
'set swapfile undodir=. directory=. viewdir=. backupdir=. belloff= noshowcmd noruler',
|
|
|
|
},
|
|
|
|
args_rm = { '-n', '-i', '--cmd' },
|
|
|
|
}
|
2018-05-21 12:18:32 -07:00
|
|
|
end)
|
|
|
|
after_each(function()
|
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
|
2024-01-12 05:03:25 -07:00
|
|
|
eq(nil, vim.uv.fs_stat(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
|
2024-01-12 05:03:25 -07:00
|
|
|
neq(nil, vim.uv.fs_stat(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))
|
2024-01-12 05:03:25 -07:00
|
|
|
neq(nil, vim.uv.fs_stat(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)
|