-- ShaDa merging data support
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local t_shada = require('test.functional.shada.testutil')
local nvim_command, fn, eq = n.command, n.fn, t.eq
local exc_exec, exec_capture = n.exc_exec, n.exec_capture
local api = n.api
local reset, clear, get_shada_rw = t_shada.reset, t_shada.clear, t_shada.get_shada_rw
local read_shada_file = t_shada.read_shada_file
local wshada, sdrcmd, shada_fname = get_shada_rw('Xtest-functional-shada-merging.shada')
local mock_file_path = '/a/b/'
if t.is_os('win') then
mock_file_path = 'C:/a/'
end
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[
|