-- ShaDa merging data support
local helpers = require('test.functional.helpers')
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
local shada_helpers = require('test.functional.shada.helpers')
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-merging.shada')
describe('ShaDa history merging code', function()
before_each(reset)
after_each(function()
clear()
os.remove(shada_fname)
end)
it('takes item with greater timestamp from Neovim instance when reading',
function()
wshada('\004\001\009\147\000\196\002ab\196\001a')
eq(0, exc_exec(sdrcmd()))
wshada('\004\000\009\147\000\196\002ab\196\001b')
eq(0, exc_exec(sdrcmd()))
os.remove(shada_fname)
eq(0, exc_exec('wshada! ' .. shada_fname))
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 4 and v.value[1] == 0 and v.value[2] == 'ab' then
eq(1, v.timestamp)
eq('a', v.value[3])
found = found + 1
end
end
eq(1, found)
end)
it('takes item with equal timestamp from Neovim instance when reading',
function()
wshada('\004\000\009\147\000\196\002ab\196\001a')
eq(0, exc_exec(sdrcmd()))
wshada('\004\000\009\147\000\196\002ab\196\001b')
eq(0, exc_exec(sdrcmd()))
os.remove(shada_fname)
eq(0, exc_exec('wshada! ' .. shada_fname))
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 4 and v.value[1] == 0 and v.value[2] == 'ab' then
eq(0, v.timestamp)
eq('a', v.value[3])
found = found + 1
end
end
eq(1, found)
end)
it('takes item with greater timestamp from ShaDa when reading',
function()
wshada('\004\000\009\147\000\196\002ab\196\001a')
eq(0, exc_exec(sdrcmd()))
wshada('\004\001\009\147\000\196\002ab\196\001b')
eq(0, exc_exec(sdrcmd()))
os.remove(shada_fname)
eq(0, exc_exec('wshada! ' .. shada_fname))
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 4 and v.value[1] == 0 and v.value[2] == 'ab' then
eq(1, v.timestamp)
eq('b', v.value[3])
found = found + 1
end
end
eq(1, found)
end)
it('takes item with greater timestamp from Neovim instance when writing',
function()
wshada('\004\001\009\147\000\196\002ab\196\001a')
eq(0, exc_exec(sdrcmd()))
wshada('\004\000\009\147\000\196\002ab\196\001b')
eq(0, exc_exec('wshada ' .. shada_fname))
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 4 and v.value[1] == 0 and v.value[2] == 'ab' then
eq(1, v.timestamp)
eq('a', v.value[3])
found = found + 1
end
end
eq(1, found)
end)
it('takes item with equal timestamp from Neovim instance when writing',
function()
wshada('\004\000\009\147\000\196\002ab\196\001a')
eq(0, exc_exec(sdrcmd()))
wshada('\004\000\009\147\000\196\002ab\196\001b')
eq(0, exc_exec('wshada ' .. shada_fname))
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 4 and v.value[1] == 0 and v.value[2] == 'ab' then
eq(0, v.timestamp)
eq('a', v.value[3])
found = found + 1
end
end
eq(1, found)
end)
it('takes item with greater timestamp from ShaDa when writing',
function()
wshada('\004\000\009\147\000\196\002ab\196\001a')
eq(0, exc_exec(sdrcmd()))
wshada('\004\001\009\147\000\196\002ab\196\001b')
eq(0, exc_exec('wshada ' .. shada_fname))
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 4 and v.value[1] == 0 and v.value[2] == 'ab' then
eq(1, v.timestamp)
eq('b', v.value[3])
found = found + 1
end
end
eq(1, found)
end)
it('correctly reads history items with messed up timestamps',
function()
wshada('\004\010\009\147\000\196\002ab\196\001a'
.. '\004\010\009\147\000\196\002ac\196\001a'
.. '\004\005\009\147\000\196\002ad\196\001a'
.. '\004\100\009\147\000\196\002ae\196\001a'
.. '\004\090\009\147\000\196\002af\196\001a'
)
eq(0, exc_exec(sdrcmd()))
os.remove(shada_fname)
eq(0, exc_exec('wshada! ' .. shada_fname))
local items = {'ad', 'ab', 'ac', 'af', 'ae'}
for i, v in ipairs(items) do
eq(v, funcs.histget(':', i
|