aboutsummaryrefslogtreecommitdiff
path: root/test/functional/shada
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/shada')
-rw-r--r--test/functional/shada/buffers_spec.lua47
-rw-r--r--test/functional/shada/compatibility_spec.lua19
-rw-r--r--test/functional/shada/errors_spec.lua25
-rw-r--r--test/functional/shada/helpers.lua34
-rw-r--r--test/functional/shada/history_spec.lua22
-rw-r--r--test/functional/shada/marks_spec.lua10
-rw-r--r--test/functional/shada/merging_spec.lua10
-rw-r--r--test/functional/shada/registers_spec.lua18
-rw-r--r--test/functional/shada/shada_spec.lua17
-rw-r--r--test/functional/shada/variables_spec.lua44
10 files changed, 177 insertions, 69 deletions
diff --git a/test/functional/shada/buffers_spec.lua b/test/functional/shada/buffers_spec.lua
index 3666b718f0..fd4809e01a 100644
--- a/test/functional/shada/buffers_spec.lua
+++ b/test/functional/shada/buffers_spec.lua
@@ -1,7 +1,7 @@
-- ShaDa buffer list saving/reading support
local helpers = require('test.functional.helpers')
-local nvim_command, funcs, eq =
- helpers.command, helpers.funcs, helpers.eq
+local nvim_command, funcs, eq, curbufmeths =
+ helpers.command, helpers.funcs, helpers.eq, helpers.curbufmeths
local shada_helpers = require('test.functional.shada.helpers')
local reset, set_additional_cmd, clear =
@@ -9,8 +9,8 @@ local reset, set_additional_cmd, clear =
shada_helpers.clear
describe('ShaDa support code', function()
- testfilename = 'Xtestfile-functional-shada-buffers'
- testfilename_2 = 'Xtestfile-functional-shada-buffers-2'
+ local testfilename = 'Xtestfile-functional-shada-buffers'
+ local testfilename_2 = 'Xtestfile-functional-shada-buffers-2'
before_each(reset)
after_each(clear)
@@ -48,4 +48,43 @@ describe('ShaDa support code', function()
eq(1, funcs.bufnr('$'))
eq('', funcs.bufname(1))
end)
+
+ it('does not dump unlisted buffer', function()
+ set_additional_cmd('set shada+=%')
+ reset()
+ nvim_command('edit ' .. testfilename)
+ nvim_command('edit ' .. testfilename_2)
+ curbufmeths.set_option('buflisted', false)
+ nvim_command('qall')
+ reset()
+ eq(2, funcs.bufnr('$'))
+ eq('', funcs.bufname(1))
+ eq(testfilename, funcs.bufname(2))
+ end)
+
+ it('does not dump quickfix buffer', function()
+ set_additional_cmd('set shada+=%')
+ reset()
+ nvim_command('edit ' .. testfilename)
+ nvim_command('edit ' .. testfilename_2)
+ curbufmeths.set_option('buftype', 'quickfix')
+ nvim_command('qall')
+ reset()
+ eq(2, funcs.bufnr('$'))
+ eq('', funcs.bufname(1))
+ eq(testfilename, funcs.bufname(2))
+ end)
+
+ it('does not dump unnamed buffers', function()
+ set_additional_cmd('set shada+=% hidden')
+ reset()
+ curbufmeths.set_line(0, 'foo')
+ nvim_command('enew')
+ curbufmeths.set_line(0, 'bar')
+ eq(2, funcs.bufnr('$'))
+ nvim_command('qall!')
+ reset()
+ eq(1, funcs.bufnr('$'))
+ eq('', funcs.bufname(1))
+ end)
end)
diff --git a/test/functional/shada/compatibility_spec.lua b/test/functional/shada/compatibility_spec.lua
index 342dee377b..1fa88c58e5 100644
--- a/test/functional/shada/compatibility_spec.lua
+++ b/test/functional/shada/compatibility_spec.lua
@@ -4,9 +4,8 @@ local nvim_command, funcs, eq = helpers.command, helpers.funcs, helpers.eq
local exc_exec = helpers.exc_exec
local shada_helpers = require('test.functional.shada.helpers')
-local reset, set_additional_cmd, clear, get_shada_rw =
- shada_helpers.reset, shada_helpers.set_additional_cmd,
- shada_helpers.clear, shada_helpers.get_shada_rw
+local reset, clear, get_shada_rw = shada_helpers.reset, shada_helpers.clear,
+ shada_helpers.get_shada_rw
local read_shada_file = shada_helpers.read_shada_file
local wshada, sdrcmd, shada_fname = get_shada_rw('Xtest-functional-shada-compatibility.shada')
@@ -181,7 +180,7 @@ describe('ShaDa forward compatibility support code', function()
end
eq(3, found)
nvim_command('wshada! ' .. shada_fname)
- local found = 0
+ found = 0
for i, subv in ipairs(read_shada_file(shada_fname)) do
if i == 1 then
eq(1, subv.type)
@@ -249,7 +248,7 @@ describe('ShaDa forward compatibility support code', function()
end
eq(1, found)
nvim_command('wshada! ' .. shada_fname)
- local found = 0
+ found = 0
for i, v in ipairs(read_shada_file(shada_fname)) do
if i == 1 then
eq(1, v.type)
@@ -271,9 +270,7 @@ describe('ShaDa forward compatibility support code', function()
it('works with register item with type 10', function()
wshada('\005\001\019\132\161na\162rX\194\162rc\145\196\001-\162rt\010')
eq(0, exc_exec(sdrcmd(true)))
- -- getreg may return empty list as list with NULL pointer which API
- -- translates into nil for some reason.
- eq({}, funcs.getreg('a', 1, 1) or {})
+ eq({}, funcs.getreg('a', 1, 1))
eq('', funcs.getregtype('a'))
nvim_command('wshada ' .. shada_fname)
local found = 0
@@ -289,7 +286,7 @@ describe('ShaDa forward compatibility support code', function()
end
eq(1, found)
nvim_command('wshada! ' .. shada_fname)
- local found = 0
+ found = 0
for i, v in ipairs(read_shada_file(shada_fname)) do
if i == 1 then
eq(1, v.type)
@@ -395,7 +392,7 @@ describe('ShaDa forward compatibility support code', function()
end
eq(1, found)
nvim_command('wshada! ' .. shada_fname)
- local found = 0
+ found = 0
for i, v in ipairs(read_shada_file(shada_fname)) do
if i == 1 then
eq(1, v.type)
@@ -432,7 +429,7 @@ describe('ShaDa forward compatibility support code', function()
end
eq(1, found)
nvim_command('wshada! ' .. shada_fname)
- local found = 0
+ found = 0
for i, v in ipairs(read_shada_file(shada_fname)) do
if i == 1 then
eq(1, v.type)
diff --git a/test/functional/shada/errors_spec.lua b/test/functional/shada/errors_spec.lua
index 16ae77af02..e7951ee74c 100644
--- a/test/functional/shada/errors_spec.lua
+++ b/test/functional/shada/errors_spec.lua
@@ -1,6 +1,7 @@
-- ShaDa errors handling support
local helpers = require('test.functional.helpers')
-local nvim_command, eq, exc_exec = helpers.command, helpers.eq, helpers.exc_exec
+local nvim_command, eq, exc_exec, redir_exec =
+ helpers.command, helpers.eq, helpers.exc_exec, helpers.redir_exec
local shada_helpers = require('test.functional.shada.helpers')
local reset, clear, get_shada_rw =
@@ -124,6 +125,11 @@ describe('ShaDa error handling', function()
eq('Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has sc key value which is not a boolean', exc_exec(sdrcmd()))
end)
+ it('fails on search pattern item with NIL search_backward key value', function()
+ wshada('\002\000\009\130\162sX\192\162sb\192')
+ eq('Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has sb key value which is not a boolean', exc_exec(sdrcmd()))
+ end)
+
it('fails on search pattern item with NIL has_line_offset key value', function()
wshada('\002\000\009\130\162sX\192\162sl\192')
eq('Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has sl key value which is not a boolean', exc_exec(sdrcmd()))
@@ -487,4 +493,21 @@ $
eq('Vim(wshada):E576: Error while reading ShaDa file: last entry specified that it occupies 47 bytes, but file ended earlier', exc_exec('wshada ' .. shada_fname))
eq(0, exc_exec('wshada! ' .. shada_fname))
end)
+
+ it('errors when a funcref is stored in a variable', function()
+ nvim_command('let F = function("tr")')
+ nvim_command('set shada+=!')
+ eq('\nE951: Error while dumping variable g:F, itself: attempt to dump function reference'
+ .. '\nE574: Failed to write variable F',
+ redir_exec('wshada'))
+ end)
+
+ it('errors when a self-referencing list is stored in a variable', function()
+ nvim_command('let L = []')
+ nvim_command('call add(L, L)')
+ nvim_command('set shada+=!')
+ eq('\nE952: Unable to dump variable g:L: container references itself in index 0'
+ .. '\nE574: Failed to write variable L',
+ redir_exec('wshada'))
+ end)
end)
diff --git a/test/functional/shada/helpers.lua b/test/functional/shada/helpers.lua
index c2ff4cadd1..d4eb7f57bd 100644
--- a/test/functional/shada/helpers.lua
+++ b/test/functional/shada/helpers.lua
@@ -3,32 +3,25 @@ local spawn, set_session, meths, nvim_prog =
helpers.spawn, helpers.set_session, helpers.meths, helpers.nvim_prog
local write_file, merge_args = helpers.write_file, helpers.merge_args
-local msgpack = require('MessagePack')
+local mpack = require('mpack')
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'}
+ local argv = {nvim_prog, '-u', 'NONE', '-i', tmpname, '-N',
+ '--cmd', 'set shortmess+=I background=light noswapfile',
+ '--cmd', additional_cmd,
+ '--embed'}
if helpers.prepend_argv then
- return merge_args(helpers.prepend_argv, nvim_argv)
+ return merge_args(helpers.prepend_argv, argv)
else
- return nvim_argv
+ return argv
end
end
-local session = nil
-
local reset = function()
- if session then
- session:exit(0)
- end
- session = spawn(nvim_argv())
- set_session(session)
+ set_session(spawn(nvim_argv()))
meths.set_var('tmpname', tmpname)
end
@@ -67,13 +60,13 @@ local read_shada_file = function(fname)
local fd = io.open(fname, 'r')
local mstring = fd:read('*a')
fd:close()
- local unpacker = msgpack.unpacker(mstring)
+ local unpack = mpack.Unpacker()
local ret = {}
- local cur
+ local cur, val
local i = 0
- while true do
- local off, val = unpacker()
- if not off then break end
+ local off = 1
+ while off <= #mstring do
+ val, off = unpack(mstring, off)
if i % 4 == 0 then
cur = {}
ret[#ret + 1] = cur
@@ -88,7 +81,6 @@ return {
reset=reset,
set_additional_cmd=set_additional_cmd,
clear=clear,
- exc_exec=exc_exec,
get_shada_rw=get_shada_rw,
read_shada_file=read_shada_file,
}
diff --git a/test/functional/shada/history_spec.lua b/test/functional/shada/history_spec.lua
index 1123f829d2..94513945d0 100644
--- a/test/functional/shada/history_spec.lua
+++ b/test/functional/shada/history_spec.lua
@@ -107,14 +107,32 @@ describe('ShaDa support code', function()
end)
it('dumps and loads last search pattern with offset', function()
- funcs.setline('.', {'foo', 'bar'})
+ meths.set_option('wrapscan', false)
+ funcs.setline('.', {'foo', 'bar--'})
nvim_feed('gg0/a/e+1\n')
eq({0, 2, 3, 0}, funcs.getpos('.'))
nvim_command('wshada')
reset()
- funcs.setline('.', {'foo', 'bar'})
+ meths.set_option('wrapscan', false)
+ funcs.setline('.', {'foo', 'bar--'})
nvim_feed('gg0n')
eq({0, 2, 3, 0}, funcs.getpos('.'))
+ eq(1, meths.get_vvar('searchforward'))
+ end)
+
+ it('dumps and loads last search pattern with offset and backward direction',
+ function()
+ meths.set_option('wrapscan', false)
+ funcs.setline('.', {'foo', 'bar--'})
+ nvim_feed('G$?a?e+1\n')
+ eq({0, 2, 3, 0}, funcs.getpos('.'))
+ nvim_command('wshada')
+ reset()
+ meths.set_option('wrapscan', false)
+ funcs.setline('.', {'foo', 'bar--'})
+ nvim_feed('G$n')
+ eq({0, 2, 3, 0}, funcs.getpos('.'))
+ eq(0, meths.get_vvar('searchforward'))
end)
it('saves v:hlsearch=1', function()
diff --git a/test/functional/shada/marks_spec.lua b/test/functional/shada/marks_spec.lua
index f03b330fb5..955a6f382b 100644
--- a/test/functional/shada/marks_spec.lua
+++ b/test/functional/shada/marks_spec.lua
@@ -15,15 +15,15 @@ local nvim_current_line = function()
end
describe('ShaDa support code', function()
- testfilename = 'Xtestfile-functional-shada-marks'
- testfilename_2 = 'Xtestfile-functional-shada-marks-2'
+ local testfilename = 'Xtestfile-functional-shada-marks'
+ local testfilename_2 = 'Xtestfile-functional-shada-marks-2'
before_each(function()
reset()
local fd = io.open(testfilename, 'w')
fd:write('test\n')
fd:write('test2\n')
fd:close()
- local fd = io.open(testfilename_2, 'w')
+ fd = io.open(testfilename_2, 'w')
fd:write('test3\n')
fd:write('test4\n')
fd:close()
@@ -108,13 +108,15 @@ describe('ShaDa support code', function()
nvim_command('qall')
reset()
local oldfiles = meths.get_vvar('oldfiles')
+ table.sort(oldfiles)
eq(2, #oldfiles)
eq(testfilename, oldfiles[1]:sub(-#testfilename))
eq(testfilename_2, oldfiles[2]:sub(-#testfilename_2))
eq(tf_full, oldfiles[1])
eq(tf_full_2, oldfiles[2])
nvim_command('rshada!')
- local oldfiles = meths.get_vvar('oldfiles')
+ oldfiles = meths.get_vvar('oldfiles')
+ table.sort(oldfiles)
eq(2, #oldfiles)
eq(testfilename, oldfiles[1]:sub(-#testfilename))
eq(testfilename_2, oldfiles[2]:sub(-#testfilename_2))
diff --git a/test/functional/shada/merging_spec.lua b/test/functional/shada/merging_spec.lua
index 7066ca9f54..221f989409 100644
--- a/test/functional/shada/merging_spec.lua
+++ b/test/functional/shada/merging_spec.lua
@@ -1,7 +1,7 @@
-- ShaDa merging data support
local helpers = require('test.functional.helpers')
-local nvim_command, meths, funcs, curbufmeths, eq =
- helpers.command, helpers.meths, helpers.funcs,
+local nvim_command, funcs, curbufmeths, eq =
+ helpers.command, helpers.funcs,
helpers.curbufmeths, helpers.eq
local exc_exec, redir_exec = helpers.exc_exec, helpers.redir_exec
@@ -870,7 +870,7 @@ describe('ShaDa jumps support code', function()
end
wshada(shada)
eq(0, exc_exec(sdrcmd()))
- local shada = ''
+ shada = ''
for i = 1,101 do
local t = i * 2
shada = shada .. (
@@ -964,7 +964,7 @@ describe('ShaDa changes support code', function()
end
wshada(shada)
eq(0, exc_exec(sdrcmd()))
- local shada = ''
+ shada = ''
for i = 1,101 do
local t = i * 2
shada = shada .. (
@@ -1001,7 +1001,7 @@ describe('ShaDa changes support code', function()
end
wshada(shada)
eq(0, exc_exec(sdrcmd()))
- local shada = ''
+ shada = ''
for i = 1,100 do
shada = shada .. ('\011%c\018\131\162mX\195\161f\196\006/a/b/c\161l%c'
):format(i, i)
diff --git a/test/functional/shada/registers_spec.lua b/test/functional/shada/registers_spec.lua
index f0133b1086..4043d94a69 100644
--- a/test/functional/shada/registers_spec.lua
+++ b/test/functional/shada/registers_spec.lua
@@ -43,9 +43,9 @@ describe('ShaDa support code', function()
setreg('b', {'bca', 'abc', 'cba'}, 'b3')
nvim_command('qall')
reset()
- eq({nil, ''}, getreg('c'))
- eq({nil, ''}, getreg('l'))
- eq({nil, ''}, getreg('b'))
+ eq({{}, ''}, getreg('c'))
+ eq({{}, ''}, getreg('l'))
+ eq({{}, ''}, getreg('b'))
end)
it('does restore registers with zero <', function()
@@ -67,9 +67,9 @@ describe('ShaDa support code', function()
setreg('b', {'bca', 'abc', 'cba'}, 'b3')
nvim_command('qall')
reset()
- eq({nil, ''}, getreg('c'))
- eq({nil, ''}, getreg('l'))
- eq({nil, ''}, getreg('b'))
+ eq({{}, ''}, getreg('c'))
+ eq({{}, ''}, getreg('l'))
+ eq({{}, ''}, getreg('b'))
end)
it('does restore registers with zero "', function()
@@ -103,7 +103,7 @@ describe('ShaDa support code', function()
nvim_command('qall')
reset()
eq({{'d'}, 'v'}, getreg('o'))
- eq({nil, ''}, getreg('t'))
+ eq({{}, ''}, getreg('t'))
end)
it('does limit number of lines according to "', function()
@@ -113,7 +113,7 @@ describe('ShaDa support code', function()
nvim_command('qall')
reset()
eq({{'d'}, 'v'}, getreg('o'))
- eq({nil, ''}, getreg('t'))
+ eq({{}, ''}, getreg('t'))
end)
it('does limit number of lines according to < rather then "', function()
@@ -125,7 +125,7 @@ describe('ShaDa support code', function()
reset()
eq({{'d'}, 'v'}, getreg('o'))
eq({{'a', 'b', 'cde'}, 'V'}, getreg('t'))
- eq({nil, ''}, getreg('h'))
+ eq({{}, ''}, getreg('h'))
end)
it('dumps and loads register correctly when &encoding is not UTF-8',
diff --git a/test/functional/shada/shada_spec.lua b/test/functional/shada/shada_spec.lua
index 2bc855a239..683d520627 100644
--- a/test/functional/shada/shada_spec.lua
+++ b/test/functional/shada/shada_spec.lua
@@ -8,7 +8,7 @@ local write_file, spawn, set_session, nvim_prog, exc_exec =
local lfs = require('lfs')
local paths = require('test.config.paths')
-local msgpack = require('MessagePack')
+local mpack = require('mpack')
local shada_helpers = require('test.functional.shada.helpers')
local reset, clear, get_shada_rw =
@@ -107,7 +107,7 @@ describe('ShaDa support code', function()
end)
it('reads correctly various timestamps', function()
- local mpack = {
+ local msgpack = {
'\100', -- Positive fixnum 100
'\204\255', -- uint 8 255
'\205\010\003', -- uint 16 2563
@@ -116,23 +116,23 @@ describe('ShaDa support code', function()
}
local s = '\100'
local e = '\001\192'
- wshada(s .. table.concat(mpack, e .. s) .. e)
+ wshada(s .. table.concat(msgpack, e .. s) .. e)
eq(0, exc_exec('wshada ' .. shada_fname))
local found = 0
- local typ = select(2, msgpack.unpacker(s)())
+ local typ = mpack.unpack(s)
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == typ then
found = found + 1
- eq(select(2, msgpack.unpacker(mpack[found])()), v.timestamp)
+ eq(mpack.unpack(msgpack[found]), v.timestamp)
end
end
- eq(#mpack, found)
+ eq(#msgpack, found)
end)
it('does not write NONE file', function()
local session = spawn({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed',
'--cmd', 'qall'}, true)
- session:exit(0)
+ session:close()
eq(nil, lfs.attributes('NONE'))
eq(nil, lfs.attributes('NONE.tmp.a'))
end)
@@ -143,7 +143,7 @@ describe('ShaDa support code', function()
true)
set_session(session)
eq('', funcs.getreg('a'))
- session:exit(0)
+ session:close()
os.remove('NONE')
end)
@@ -174,6 +174,7 @@ describe('ShaDa support code', function()
nvim_command('set shada+=%')
nvim_command('wshada! ' .. shada_fname)
local readme_fname = paths.test_source_path .. '/README.md'
+ readme_fname = helpers.eval( 'resolve("' .. readme_fname .. '")' )
eq({[7]=1, [8]=2, [9]=1, [10]=4, [11]=1}, find_file(readme_fname))
nvim_command('set shada+=r~')
nvim_command('wshada! ' .. shada_fname)
diff --git a/test/functional/shada/variables_spec.lua b/test/functional/shada/variables_spec.lua
index 6225971e5f..7ceeafdc71 100644
--- a/test/functional/shada/variables_spec.lua
+++ b/test/functional/shada/variables_spec.lua
@@ -1,7 +1,7 @@
-- ShaDa variables saving/reading support
local helpers = require('test.functional.helpers')
-local meths, funcs, nvim_command, eq =
- helpers.meths, helpers.funcs, helpers.command, helpers.eq
+local meths, funcs, nvim_command, eq, exc_exec =
+ helpers.meths, helpers.funcs, helpers.command, helpers.eq, helpers.exc_exec
local shada_helpers = require('test.functional.shada.helpers')
local reset, set_additional_cmd, clear =
@@ -22,12 +22,17 @@ describe('ShaDa support code', function()
eq('foo', meths.get_var('STRVAR'))
end)
- local autotest = function(tname, varname, varval)
+ local autotest = function(tname, varname, varval, val_is_expr)
it('is able to dump and read back ' .. tname .. ' variable automatically',
function()
set_additional_cmd('set shada+=!')
reset()
- meths.set_var(varname, varval)
+ if val_is_expr then
+ nvim_command('let g:' .. varname .. ' = ' .. varval)
+ varval = meths.get_var(varname)
+ else
+ meths.set_var(varname, varval)
+ end
-- Exit during `reset` is not a regular exit: it does not write shada
-- automatically
nvim_command('qall')
@@ -41,6 +46,10 @@ describe('ShaDa support code', function()
autotest('float', 'FLTVAR', 42.5)
autotest('dictionary', 'DCTVAR', {a=10})
autotest('list', 'LSTVAR', {{a=10}, {b=10.5}, {c='str'}})
+ 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)
it('does not read back variables without `!` in &shada', function()
meths.set_var('STRVAR', 'foo')
@@ -136,4 +145,31 @@ describe('ShaDa support code', function()
eq({['\171']={{'\171'}, {['\171']='\171'}, {a='Test'}}},
meths.get_var('NESTEDVAR'))
end)
+
+ 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+=!')
+ eq('Vim(wshada):E951: Error while dumping variable g:F, itself: attempt to dump function reference',
+ 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+=!')
+ eq('Vim(wshada):E952: Unable to dump variable g:L: container references itself in index 0',
+ exc_exec('wshada'))
+ meths.set_option('shada', '')
+ set_additional_cmd('set shada+=!')
+ reset()
+ eq('10', meths.get_var('U'))
+ end)
end)