mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
functests: Add tests for ShaDa variables dumping/reading
This commit is contained in:
parent
5e34d4873b
commit
e143be7f3d
@ -44,11 +44,15 @@ elseif os.getenv('GDB') then
|
||||
end
|
||||
|
||||
if prepend_argv then
|
||||
local new_nvim_argv = {}
|
||||
local len = #prepend_argv
|
||||
for i = 1, #nvim_argv do
|
||||
prepend_argv[i + len] = nvim_argv[i]
|
||||
for i = 1, len do
|
||||
new_nvim_argv[i] = prepend_argv[i]
|
||||
end
|
||||
nvim_argv = prepend_argv
|
||||
for i = 1, #nvim_argv do
|
||||
new_nvim_argv[i + len] = nvim_argv[i]
|
||||
end
|
||||
nvim_argv = new_nvim_argv
|
||||
end
|
||||
|
||||
local session, loop_running, loop_stopped, last_error
|
||||
@ -338,6 +342,7 @@ local exc_exec = function(cmd)
|
||||
end
|
||||
|
||||
return {
|
||||
prepend_argv = prepend_argv,
|
||||
clear = clear,
|
||||
spawn = spawn,
|
||||
dedent = dedent,
|
||||
|
53
test/functional/shada/helpers.lua
Normal file
53
test/functional/shada/helpers.lua
Normal file
@ -0,0 +1,53 @@
|
||||
local helpers = require('test.functional.helpers')
|
||||
local spawn, set_session, nvim, nvim_prog =
|
||||
helpers.spawn, helpers.set_session, helpers.nvim, helpers.nvim_prog
|
||||
|
||||
local tmpname = os.tmpname()
|
||||
local additional_cmd = ''
|
||||
|
||||
local function nvim_argv()
|
||||
local ret
|
||||
local nvim_argv = {nvim_prog, '-u', 'NONE', '-i', tmpname, '-N',
|
||||
'--cmd', 'set shortmess+=I background=light noswapfile',
|
||||
'--cmd', additional_cmd,
|
||||
'--embed'}
|
||||
if helpers.prepend_argv then
|
||||
ret = {}
|
||||
for i, v in ipairs(helpers.prepend_argv) do
|
||||
ret[i] = v
|
||||
end
|
||||
local shift = #ret
|
||||
for i, v in ipairs(nvim_argv) do
|
||||
ret[i + shift] = v
|
||||
end
|
||||
else
|
||||
ret = nvim_argv
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
local session = nil
|
||||
|
||||
local reset = function()
|
||||
if session then
|
||||
session:exit(0)
|
||||
end
|
||||
session = spawn(nvim_argv())
|
||||
set_session(session)
|
||||
nvim('set_var', 'tmpname', tmpname)
|
||||
end
|
||||
|
||||
local set_additional_cmd = function(s)
|
||||
additional_cmd = s
|
||||
end
|
||||
|
||||
local clear = function()
|
||||
os.remove(tmpname)
|
||||
set_additional_cmd('')
|
||||
end
|
||||
|
||||
return {
|
||||
reset=reset,
|
||||
set_additional_cmd=set_additional_cmd,
|
||||
clear=clear,
|
||||
}
|
84
test/functional/shada/variables_spec.lua
Normal file
84
test/functional/shada/variables_spec.lua
Normal file
@ -0,0 +1,84 @@
|
||||
-- ShaDa variables saving/reading support
|
||||
local helpers = require('test.functional.helpers')
|
||||
local nvim, nvim_command, nvim_eval, eq =
|
||||
helpers.nvim, helpers.command, helpers.eval, helpers.eq
|
||||
|
||||
local shada_helpers = require('test.functional.shada.helpers')
|
||||
local reset, set_additional_cmd, clear =
|
||||
shada_helpers.reset, shada_helpers.set_additional_cmd,
|
||||
shada_helpers.clear
|
||||
|
||||
describe('ShaDa support code', function()
|
||||
before_each(reset)
|
||||
after_each(clear)
|
||||
|
||||
it('is able to dump and read back string variable', function()
|
||||
nvim('set_var', 'STRVAR', 'foo')
|
||||
nvim_command('set viminfo+=!')
|
||||
nvim_command('wviminfo')
|
||||
reset()
|
||||
nvim_command('set viminfo+=!')
|
||||
nvim_command('rviminfo')
|
||||
eq('foo', nvim('get_var', 'STRVAR'))
|
||||
end)
|
||||
|
||||
local autotest = function(tname, varname, varval)
|
||||
it('is able to dump and read back ' .. tname .. ' variable automatically',
|
||||
function()
|
||||
set_additional_cmd('set viminfo+=!')
|
||||
reset()
|
||||
nvim('set_var', varname, varval)
|
||||
-- Exit during `reset` is not a regular exit: it does not write viminfo
|
||||
-- automatically
|
||||
nvim_command('qall')
|
||||
reset()
|
||||
eq(varval, nvim('get_var', varname))
|
||||
end)
|
||||
end
|
||||
|
||||
autotest('string', 'STRVAR', 'foo')
|
||||
autotest('number', 'NUMVAR', 42)
|
||||
autotest('float', 'FLTVAR', 42.5)
|
||||
autotest('dictionary', 'DCTVAR', {a=10})
|
||||
autotest('list', 'LSTVAR', {{a=10}, {b=10.5}, {c='str'}})
|
||||
|
||||
it('does not read back variables without `!` in &viminfo', function()
|
||||
nvim('set_var', 'STRVAR', 'foo')
|
||||
nvim_command('set viminfo+=!')
|
||||
nvim_command('wviminfo')
|
||||
set_additional_cmd('set viminfo-=!')
|
||||
reset()
|
||||
nvim_command('rviminfo')
|
||||
eq(0, nvim_eval('exists("g:STRVAR")'))
|
||||
end)
|
||||
|
||||
it('does not dump variables without `!` in &viminfo', function()
|
||||
nvim_command('set viminfo-=!')
|
||||
nvim('set_var', 'STRVAR', 'foo')
|
||||
nvim_command('wviminfo')
|
||||
reset()
|
||||
nvim_command('set viminfo+=!')
|
||||
nvim_command('rviminfo')
|
||||
eq(0, nvim_eval('exists("g:STRVAR")'))
|
||||
end)
|
||||
|
||||
it('does not dump session variables', function()
|
||||
nvim_command('set viminfo+=!')
|
||||
nvim('set_var', 'StrVar', 'foo')
|
||||
nvim_command('wviminfo')
|
||||
reset()
|
||||
nvim_command('set viminfo+=!')
|
||||
nvim_command('rviminfo')
|
||||
eq(0, nvim_eval('exists("g:StrVar")'))
|
||||
end)
|
||||
|
||||
it('does not dump regular variables', function()
|
||||
nvim_command('set viminfo+=!')
|
||||
nvim('set_var', 'str_var', 'foo')
|
||||
nvim_command('wviminfo')
|
||||
reset()
|
||||
nvim_command('set viminfo+=!')
|
||||
nvim_command('rviminfo')
|
||||
eq(0, nvim_eval('exists("g:str_var")'))
|
||||
end)
|
||||
end)
|
Loading…
Reference in New Issue
Block a user