2015-04-26 05:31:39 -07:00
|
|
|
-- ShaDa variables saving/reading support
|
2016-04-23 16:53:11 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
2015-11-23 04:24:25 -07:00
|
|
|
local meths, funcs, nvim_command, eq, exc_exec =
|
|
|
|
helpers.meths, helpers.funcs, helpers.command, helpers.eq, helpers.exc_exec
|
2015-04-26 05:31:39 -07:00
|
|
|
|
|
|
|
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()
|
2015-09-26 16:49:48 -07:00
|
|
|
meths.set_var('STRVAR', 'foo')
|
2015-07-05 16:26:44 -07:00
|
|
|
nvim_command('set shada+=!')
|
|
|
|
nvim_command('wshada')
|
2015-04-26 05:31:39 -07:00
|
|
|
reset()
|
2015-07-05 16:26:44 -07:00
|
|
|
nvim_command('set shada+=!')
|
|
|
|
nvim_command('rshada')
|
2015-09-26 16:49:48 -07:00
|
|
|
eq('foo', meths.get_var('STRVAR'))
|
2015-04-26 05:31:39 -07:00
|
|
|
end)
|
|
|
|
|
2016-02-06 11:03:33 -07:00
|
|
|
local autotest = function(tname, varname, varval, val_is_expr)
|
2015-04-26 05:31:39 -07:00
|
|
|
it('is able to dump and read back ' .. tname .. ' variable automatically',
|
|
|
|
function()
|
2015-07-05 16:26:44 -07:00
|
|
|
set_additional_cmd('set shada+=!')
|
2015-04-26 05:31:39 -07:00
|
|
|
reset()
|
2016-02-06 11:03:33 -07:00
|
|
|
if val_is_expr then
|
|
|
|
nvim_command('let g:' .. varname .. ' = ' .. varval)
|
|
|
|
varval = meths.get_var(varname)
|
|
|
|
else
|
|
|
|
meths.set_var(varname, varval)
|
|
|
|
end
|
2015-07-05 16:26:44 -07:00
|
|
|
-- Exit during `reset` is not a regular exit: it does not write shada
|
2015-04-26 05:31:39 -07:00
|
|
|
-- automatically
|
|
|
|
nvim_command('qall')
|
|
|
|
reset()
|
2015-09-26 16:49:48 -07:00
|
|
|
eq(varval, meths.get_var(varname))
|
2015-04-26 05:31:39 -07:00
|
|
|
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'}})
|
2016-02-06 11:03:33 -07:00
|
|
|
autotest('true', 'TRUEVAR', true)
|
|
|
|
autotest('false', 'FALSEVAR', false)
|
|
|
|
autotest('null', 'NULLVAR', 'v:null', true)
|
|
|
|
autotest('ext', 'EXTVAR', '{"_TYPE": v:msgpack_types.ext, "_VAL": [2, ["", ""]]}', true)
|
2015-04-26 05:31:39 -07:00
|
|
|
|
2015-07-05 16:26:44 -07:00
|
|
|
it('does not read back variables without `!` in &shada', function()
|
2015-09-26 16:49:48 -07:00
|
|
|
meths.set_var('STRVAR', 'foo')
|
2015-07-05 16:26:44 -07:00
|
|
|
nvim_command('set shada+=!')
|
|
|
|
nvim_command('wshada')
|
|
|
|
set_additional_cmd('set shada-=!')
|
2015-04-26 05:31:39 -07:00
|
|
|
reset()
|
2015-07-05 16:26:44 -07:00
|
|
|
nvim_command('rshada')
|
2015-09-26 16:49:48 -07:00
|
|
|
eq(0, funcs.exists('g:STRVAR'))
|
2015-04-26 05:31:39 -07:00
|
|
|
end)
|
|
|
|
|
2015-07-05 16:26:44 -07:00
|
|
|
it('does not dump variables without `!` in &shada', function()
|
|
|
|
nvim_command('set shada-=!')
|
2015-09-26 16:49:48 -07:00
|
|
|
meths.set_var('STRVAR', 'foo')
|
2015-07-05 16:26:44 -07:00
|
|
|
nvim_command('wshada')
|
2015-04-26 05:31:39 -07:00
|
|
|
reset()
|
2015-07-05 16:26:44 -07:00
|
|
|
nvim_command('set shada+=!')
|
|
|
|
nvim_command('rshada')
|
2015-09-26 16:49:48 -07:00
|
|
|
eq(0, funcs.exists('g:STRVAR'))
|
2015-04-26 05:31:39 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('does not dump session variables', function()
|
2015-07-05 16:26:44 -07:00
|
|
|
nvim_command('set shada+=!')
|
2015-09-26 16:49:48 -07:00
|
|
|
meths.set_var('StrVar', 'foo')
|
2015-07-05 16:26:44 -07:00
|
|
|
nvim_command('wshada')
|
2015-04-26 05:31:39 -07:00
|
|
|
reset()
|
2015-07-05 16:26:44 -07:00
|
|
|
nvim_command('set shada+=!')
|
|
|
|
nvim_command('rshada')
|
2015-09-26 16:49:48 -07:00
|
|
|
eq(0, funcs.exists('g:StrVar'))
|
2015-04-26 05:31:39 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('does not dump regular variables', function()
|
2015-07-05 16:26:44 -07:00
|
|
|
nvim_command('set shada+=!')
|
2015-09-26 16:49:48 -07:00
|
|
|
meths.set_var('str_var', 'foo')
|
2015-07-05 16:26:44 -07:00
|
|
|
nvim_command('wshada')
|
2015-04-26 05:31:39 -07:00
|
|
|
reset()
|
2015-07-05 16:26:44 -07:00
|
|
|
nvim_command('set shada+=!')
|
|
|
|
nvim_command('rshada')
|
2015-09-26 16:49:48 -07:00
|
|
|
eq(0, funcs.exists('g:str_var'))
|
2015-04-26 05:31:39 -07:00
|
|
|
end)
|
2015-07-05 07:24:02 -07:00
|
|
|
|
|
|
|
it('dumps and loads variables correctly when &encoding is not UTF-8',
|
|
|
|
function()
|
|
|
|
set_additional_cmd('set encoding=latin1')
|
|
|
|
reset()
|
|
|
|
-- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1
|
2015-09-26 16:49:48 -07:00
|
|
|
meths.set_var('STRVAR', '\171')
|
|
|
|
meths.set_var('LSTVAR', {'\171'})
|
|
|
|
meths.set_var('DCTVAR', {['\171']='\171'})
|
|
|
|
meths.set_var('NESTEDVAR', {['\171']={{'\171'}, {['\171']='\171'},
|
|
|
|
{a='Test'}}})
|
2015-07-05 07:24:02 -07:00
|
|
|
nvim_command('qall')
|
|
|
|
reset()
|
2015-09-26 16:49:48 -07:00
|
|
|
eq('\171', meths.get_var('STRVAR'))
|
|
|
|
eq({'\171'}, meths.get_var('LSTVAR'))
|
|
|
|
eq({['\171']='\171'}, meths.get_var('DCTVAR'))
|
2015-07-05 07:24:02 -07:00
|
|
|
eq({['\171']={{'\171'}, {['\171']='\171'}, {a='Test'}}},
|
2015-09-26 16:49:48 -07:00
|
|
|
meths.get_var('NESTEDVAR'))
|
2015-07-05 07:24:02 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('dumps and loads variables correctly when &encoding /= UTF-8 when dumping',
|
|
|
|
function()
|
|
|
|
set_additional_cmd('set encoding=latin1')
|
|
|
|
reset()
|
|
|
|
-- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1
|
2015-09-26 16:49:48 -07:00
|
|
|
meths.set_var('STRVAR', '\171')
|
|
|
|
meths.set_var('LSTVAR', {'\171'})
|
|
|
|
meths.set_var('DCTVAR', {['\171']='\171'})
|
|
|
|
meths.set_var('NESTEDVAR', {['\171']={{'\171'}, {['\171']='\171'},
|
|
|
|
{a='Test'}}})
|
2015-07-05 07:24:02 -07:00
|
|
|
set_additional_cmd('')
|
|
|
|
nvim_command('qall')
|
|
|
|
reset()
|
2015-09-26 16:49:48 -07:00
|
|
|
eq('«', meths.get_var('STRVAR'))
|
|
|
|
eq({'«'}, meths.get_var('LSTVAR'))
|
|
|
|
eq({['«']='«'}, meths.get_var('DCTVAR'))
|
|
|
|
eq({['«']={{'«'}, {['«']='«'}, {a='Test'}}}, meths.get_var('NESTEDVAR'))
|
2015-07-05 07:24:02 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('dumps and loads variables correctly when &encoding /= UTF-8 when loading',
|
|
|
|
function()
|
|
|
|
-- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1
|
2015-09-26 16:49:48 -07:00
|
|
|
meths.set_var('STRVAR', '«')
|
|
|
|
meths.set_var('LSTVAR', {'«'})
|
|
|
|
meths.set_var('DCTVAR', {['«']='«'})
|
|
|
|
meths.set_var('NESTEDVAR', {['«']={{'«'}, {['«']='«'}, {a='Test'}}})
|
2015-07-05 07:24:02 -07:00
|
|
|
set_additional_cmd('set encoding=latin1')
|
|
|
|
nvim_command('qall')
|
|
|
|
reset()
|
2015-09-26 16:49:48 -07:00
|
|
|
eq('\171', meths.get_var('STRVAR'))
|
|
|
|
eq({'\171'}, meths.get_var('LSTVAR'))
|
|
|
|
eq({['\171']='\171'}, meths.get_var('DCTVAR'))
|
2015-07-05 07:24:02 -07:00
|
|
|
eq({['\171']={{'\171'}, {['\171']='\171'}, {a='Test'}}},
|
2015-09-26 16:49:48 -07:00
|
|
|
meths.get_var('NESTEDVAR'))
|
2015-07-05 07:24:02 -07:00
|
|
|
end)
|
2015-11-23 04:24:25 -07:00
|
|
|
|
|
|
|
it('errors and writes when a funcref is stored in a variable',
|
|
|
|
function()
|
|
|
|
nvim_command('let F = function("tr")')
|
|
|
|
meths.set_var('U', '10')
|
|
|
|
nvim_command('set shada+=!')
|
|
|
|
set_additional_cmd('set shada+=!')
|
2016-01-06 12:33:56 -07:00
|
|
|
eq('Vim(wshada):E951: Error while dumping variable g:F, itself: attempt to dump function reference',
|
2015-11-23 04:24:25 -07:00
|
|
|
exc_exec('wshada'))
|
|
|
|
meths.set_option('shada', '')
|
|
|
|
reset()
|
|
|
|
eq('10', meths.get_var('U'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('errors and writes when a self-referencing list is stored in a variable',
|
|
|
|
function()
|
|
|
|
meths.set_var('L', {})
|
|
|
|
nvim_command('call add(L, L)')
|
|
|
|
meths.set_var('U', '10')
|
|
|
|
nvim_command('set shada+=!')
|
2016-01-06 12:33:56 -07:00
|
|
|
eq('Vim(wshada):E952: Unable to dump variable g:L: container references itself in index 0',
|
2015-11-23 04:24:25 -07:00
|
|
|
exc_exec('wshada'))
|
|
|
|
meths.set_option('shada', '')
|
|
|
|
set_additional_cmd('set shada+=!')
|
|
|
|
reset()
|
|
|
|
eq('10', meths.get_var('U'))
|
|
|
|
end)
|
2015-04-26 05:31:39 -07:00
|
|
|
end)
|