mirror of
https://github.com/neovim/neovim.git
synced 2025-10-26 12:27:24 +00:00
tests: wviminfo_spec.lua: rework
074_global_var_in_viminfo_spec: remove some redundant sanity checks.
This commit is contained in:
@@ -3,60 +3,55 @@ local clear, execute, eq, neq, spawn, nvim_prog, set_session, wait =
|
||||
helpers.clear, helpers.execute, helpers.eq, helpers.neq, helpers.spawn,
|
||||
helpers.nvim_prog, helpers.set_session, helpers.wait
|
||||
|
||||
-- Lua does not have a sleep function so we use the system command. If the
|
||||
-- command does not support sub second precision we use math.floor() to get
|
||||
-- full seconds.
|
||||
local sleep = function(millisec)
|
||||
local sec = millisec / 1000
|
||||
local round = math.floor(sec)
|
||||
if round == 0 then round = 1 end
|
||||
os.execute('sleep '..sec..' || sleep '..round)
|
||||
end
|
||||
|
||||
describe(':wviminfo', function()
|
||||
local file = 'foo'
|
||||
local viminfo_file = 'wviminfo_test'
|
||||
local session
|
||||
|
||||
before_each(function()
|
||||
clear()
|
||||
os.remove(file)
|
||||
if session then
|
||||
session:exit(0)
|
||||
end
|
||||
|
||||
-- Override the default session because we need 'swapfile' for these tests.
|
||||
local session = spawn({nvim_prog, '-u', 'NONE', '--embed',
|
||||
'--cmd', 'set swapfile'})
|
||||
set_session(session)
|
||||
|
||||
os.remove(viminfo_file)
|
||||
end)
|
||||
|
||||
it('creates a file', function()
|
||||
-- TODO
|
||||
-- Set up the nvim session to be able to write viminfo files. Is it
|
||||
-- possible to do this outside of the it() call?
|
||||
local nvim2 = spawn({nvim_prog, '-u', 'NONE', '--embed'})
|
||||
--local nvim2 = spawn({nvim_prog, '-u', 'NONE', '--embed', '--cmd', 'let hans=42' })
|
||||
set_session(nvim2)
|
||||
--eq(43, eval('hans'))
|
||||
|
||||
-- Assert that the file does not exist.
|
||||
eq(nil, lfs.attributes(file))
|
||||
execute('wv! '..file)
|
||||
it('creates a viminfo file', function()
|
||||
-- file should _not_ exist
|
||||
eq(nil, lfs.attributes(viminfo_file))
|
||||
execute('wv! '..viminfo_file)
|
||||
wait()
|
||||
-- Assert that the file does exist.
|
||||
neq(nil, lfs.attributes(file))
|
||||
-- file _should_ exist
|
||||
neq(nil, lfs.attributes(viminfo_file))
|
||||
end)
|
||||
|
||||
it('overwrites existing files', function()
|
||||
-- TODO see above
|
||||
local nvim2 = spawn({nvim_prog, '-u', 'NONE', '--embed'})
|
||||
set_session(nvim2)
|
||||
local text = 'wviminfo test'
|
||||
|
||||
local text = 'foo test'
|
||||
|
||||
local fp = io.open(file, 'w')
|
||||
-- Create a dummy file
|
||||
local fp = io.open(viminfo_file, 'w')
|
||||
fp:write(text)
|
||||
fp:flush()
|
||||
fp:close()
|
||||
-- Assert that the file already exists.
|
||||
neq(nil, lfs.attributes(file))
|
||||
execute('wv! '..file)
|
||||
|
||||
-- sanity check
|
||||
eq(text, io.open(viminfo_file):read())
|
||||
neq(nil, lfs.attributes(viminfo_file))
|
||||
|
||||
execute('wv! '..viminfo_file)
|
||||
wait()
|
||||
-- Assert that the contents of the file changed.
|
||||
neq(text, io.open(file):read())
|
||||
|
||||
-- File should have been overwritten with a viminfo file.
|
||||
local line1 = io.lines(viminfo_file)()
|
||||
assert(nil ~= string.find(line1, 'This viminfo file was generated by Nvim'),
|
||||
viminfo_file..' should be a viminfo-formatted file')
|
||||
end)
|
||||
|
||||
teardown(function()
|
||||
os.remove(file)
|
||||
os.remove(viminfo_file)
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -34,21 +34,20 @@ describe('storing global variables in viminfo files', function()
|
||||
)
|
||||
eq(test_dict, eval('MY_GLOBAL_DICT'))
|
||||
eq(test_list, eval('MY_GLOBAL_LIST'))
|
||||
-- Assert that the viminfo file does not exists.
|
||||
eq(nil, lfs.attributes('Xviminfo'))
|
||||
|
||||
execute('wv! Xviminfo')
|
||||
wait()
|
||||
|
||||
-- Assert that the viminfo file exists.
|
||||
neq(nil, lfs.attributes('Xviminfo'))
|
||||
execute('unlet MY_GLOBAL_DICT',
|
||||
'unlet MY_GLOBAL_LIST')
|
||||
'unlet MY_GLOBAL_LIST')
|
||||
-- Assert that the variables where deleted.
|
||||
eq(0, eval('exists("MY_GLOBAL_DICT")'))
|
||||
eq(0, eval('exists("MY_GLOBAL_LIST")'))
|
||||
|
||||
execute('rv! Xviminfo')
|
||||
-- Assert that the variables where restored.
|
||||
eq(1, eval('exists("MY_GLOBAL_DICT")'))
|
||||
eq(1, eval('exists("MY_GLOBAL_LIST")'))
|
||||
|
||||
eq(test_list, eval('MY_GLOBAL_LIST'))
|
||||
eq(test_dict, eval('MY_GLOBAL_DICT'))
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user