2016-04-23 16:53:11 -07:00
|
|
|
local helpers = require('test.functional.helpers')(nil)
|
2019-08-09 01:23:57 -07:00
|
|
|
local meths = helpers.meths
|
|
|
|
local write_file = helpers.write_file
|
|
|
|
local concat_tables = helpers.concat_tables
|
2015-04-26 05:31:39 -07:00
|
|
|
|
2015-12-29 12:18:16 -07:00
|
|
|
local tmpname = helpers.tmpname()
|
2015-04-26 05:31:39 -07:00
|
|
|
|
2019-08-09 01:23:57 -07:00
|
|
|
-- o={
|
|
|
|
-- args=…,
|
|
|
|
-- args_rm=…,
|
|
|
|
-- shadafile=…,
|
|
|
|
-- }
|
|
|
|
local function reset(o)
|
|
|
|
assert(o == nil or type(o) == 'table' or type(o) == 'string')
|
|
|
|
o = o and o or {}
|
|
|
|
local args_rm = o.args_rm or {}
|
|
|
|
table.insert(args_rm, '-i')
|
2024-01-02 18:09:18 -07:00
|
|
|
local args = {
|
|
|
|
'-i',
|
|
|
|
o.shadafile or tmpname,
|
2019-08-09 01:23:57 -07:00
|
|
|
}
|
|
|
|
if type(o) == 'string' then
|
2024-01-02 18:09:18 -07:00
|
|
|
args = concat_tables(args, { '--cmd', o })
|
2019-08-09 01:23:57 -07:00
|
|
|
elseif o.args then
|
|
|
|
args = concat_tables(args, o.args)
|
2018-09-20 10:19:38 -07:00
|
|
|
end
|
2024-01-02 18:09:18 -07:00
|
|
|
helpers.clear {
|
|
|
|
args_rm = args_rm,
|
|
|
|
args = args,
|
2019-08-09 01:23:57 -07:00
|
|
|
}
|
2024-01-12 05:44:54 -07:00
|
|
|
meths.nvim_set_var('tmpname', tmpname)
|
2015-04-26 05:31:39 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
local clear = function()
|
2023-02-11 03:25:01 -07:00
|
|
|
helpers.expect_exit(helpers.command, 'qall!')
|
2015-04-26 05:31:39 -07:00
|
|
|
os.remove(tmpname)
|
|
|
|
end
|
|
|
|
|
2015-08-08 04:54:47 -07:00
|
|
|
local get_shada_rw = function(fname)
|
|
|
|
local wshada = function(text)
|
|
|
|
write_file(fname, text, true)
|
|
|
|
end
|
|
|
|
local sdrcmd = function(bang)
|
|
|
|
return 'rshada' .. (bang and '!' or '') .. ' ' .. fname
|
|
|
|
end
|
2015-08-09 08:41:25 -07:00
|
|
|
local clean = function()
|
|
|
|
os.remove(fname)
|
|
|
|
local i = ('a'):byte()
|
|
|
|
while i <= ('z'):byte() do
|
|
|
|
if not os.remove(fname .. ('.tmp.%c'):format(i)) then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
i = i + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return wshada, sdrcmd, fname, clean
|
|
|
|
end
|
|
|
|
|
2024-01-02 18:09:18 -07:00
|
|
|
local mpack_keys = { 'type', 'timestamp', 'length', 'value' }
|
2015-08-09 08:41:25 -07:00
|
|
|
|
|
|
|
local read_shada_file = function(fname)
|
|
|
|
local fd = io.open(fname, 'r')
|
|
|
|
local mstring = fd:read('*a')
|
|
|
|
fd:close()
|
2024-01-12 05:03:25 -07:00
|
|
|
local unpack = vim.mpack.Unpacker()
|
2015-08-09 08:41:25 -07:00
|
|
|
local ret = {}
|
2016-04-13 05:21:32 -07:00
|
|
|
local cur, val
|
2015-08-09 08:41:25 -07:00
|
|
|
local i = 0
|
2016-04-13 05:21:32 -07:00
|
|
|
local off = 1
|
|
|
|
while off <= #mstring do
|
|
|
|
val, off = unpack(mstring, off)
|
2015-08-09 08:41:25 -07:00
|
|
|
if i % 4 == 0 then
|
|
|
|
cur = {}
|
|
|
|
ret[#ret + 1] = cur
|
|
|
|
end
|
|
|
|
cur[mpack_keys[(i % 4) + 1]] = val
|
|
|
|
i = i + 1
|
|
|
|
end
|
|
|
|
return ret
|
2015-08-08 04:54:47 -07:00
|
|
|
end
|
|
|
|
|
2015-04-26 05:31:39 -07:00
|
|
|
return {
|
2024-01-02 18:09:18 -07:00
|
|
|
reset = reset,
|
|
|
|
clear = clear,
|
|
|
|
get_shada_rw = get_shada_rw,
|
|
|
|
read_shada_file = read_shada_file,
|
2015-04-26 05:31:39 -07:00
|
|
|
}
|