mirror of
https://github.com/neovim/neovim.git
synced 2025-11-05 10:14:26 +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.clear, helpers.execute, helpers.eq, helpers.neq, helpers.spawn,
|
||||||
helpers.nvim_prog, helpers.set_session, helpers.wait
|
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()
|
describe(':wviminfo', function()
|
||||||
local file = 'foo'
|
local viminfo_file = 'wviminfo_test'
|
||||||
|
local session
|
||||||
|
|
||||||
before_each(function()
|
before_each(function()
|
||||||
clear()
|
if session then
|
||||||
os.remove(file)
|
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)
|
end)
|
||||||
|
|
||||||
it('creates a file', function()
|
it('creates a viminfo file', function()
|
||||||
-- TODO
|
-- file should _not_ exist
|
||||||
-- Set up the nvim session to be able to write viminfo files. Is it
|
eq(nil, lfs.attributes(viminfo_file))
|
||||||
-- possible to do this outside of the it() call?
|
execute('wv! '..viminfo_file)
|
||||||
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)
|
|
||||||
wait()
|
wait()
|
||||||
-- Assert that the file does exist.
|
-- file _should_ exist
|
||||||
neq(nil, lfs.attributes(file))
|
neq(nil, lfs.attributes(viminfo_file))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('overwrites existing files', function()
|
it('overwrites existing files', function()
|
||||||
-- TODO see above
|
local text = 'wviminfo test'
|
||||||
local nvim2 = spawn({nvim_prog, '-u', 'NONE', '--embed'})
|
|
||||||
set_session(nvim2)
|
|
||||||
|
|
||||||
local text = 'foo test'
|
-- Create a dummy file
|
||||||
|
local fp = io.open(viminfo_file, 'w')
|
||||||
local fp = io.open(file, 'w')
|
|
||||||
fp:write(text)
|
fp:write(text)
|
||||||
fp:flush()
|
fp:flush()
|
||||||
fp:close()
|
fp:close()
|
||||||
-- Assert that the file already exists.
|
|
||||||
neq(nil, lfs.attributes(file))
|
-- sanity check
|
||||||
execute('wv! '..file)
|
eq(text, io.open(viminfo_file):read())
|
||||||
|
neq(nil, lfs.attributes(viminfo_file))
|
||||||
|
|
||||||
|
execute('wv! '..viminfo_file)
|
||||||
wait()
|
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)
|
end)
|
||||||
|
|
||||||
teardown(function()
|
teardown(function()
|
||||||
os.remove(file)
|
os.remove(viminfo_file)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|||||||
@@ -34,10 +34,10 @@ describe('storing global variables in viminfo files', function()
|
|||||||
)
|
)
|
||||||
eq(test_dict, eval('MY_GLOBAL_DICT'))
|
eq(test_dict, eval('MY_GLOBAL_DICT'))
|
||||||
eq(test_list, eval('MY_GLOBAL_LIST'))
|
eq(test_list, eval('MY_GLOBAL_LIST'))
|
||||||
-- Assert that the viminfo file does not exists.
|
|
||||||
eq(nil, lfs.attributes('Xviminfo'))
|
|
||||||
execute('wv! Xviminfo')
|
execute('wv! Xviminfo')
|
||||||
wait()
|
wait()
|
||||||
|
|
||||||
-- Assert that the viminfo file exists.
|
-- Assert that the viminfo file exists.
|
||||||
neq(nil, lfs.attributes('Xviminfo'))
|
neq(nil, lfs.attributes('Xviminfo'))
|
||||||
execute('unlet MY_GLOBAL_DICT',
|
execute('unlet MY_GLOBAL_DICT',
|
||||||
@@ -45,10 +45,9 @@ describe('storing global variables in viminfo files', function()
|
|||||||
-- Assert that the variables where deleted.
|
-- Assert that the variables where deleted.
|
||||||
eq(0, eval('exists("MY_GLOBAL_DICT")'))
|
eq(0, eval('exists("MY_GLOBAL_DICT")'))
|
||||||
eq(0, eval('exists("MY_GLOBAL_LIST")'))
|
eq(0, eval('exists("MY_GLOBAL_LIST")'))
|
||||||
|
|
||||||
execute('rv! Xviminfo')
|
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_list, eval('MY_GLOBAL_LIST'))
|
||||||
eq(test_dict, eval('MY_GLOBAL_DICT'))
|
eq(test_dict, eval('MY_GLOBAL_DICT'))
|
||||||
end)
|
end)
|
||||||
|
|||||||
Reference in New Issue
Block a user