2024-04-20 08:44:13 -07:00
|
|
|
local t = require('test.testutil')
|
|
|
|
local n = require('test.functional.testnvim')()
|
|
|
|
|
|
|
|
local api = n.api
|
2024-04-08 02:03:20 -07:00
|
|
|
local write_file = t.write_file
|
|
|
|
local concat_tables = t.concat_tables
|
2015-04-26 05:31:39 -07:00
|
|
|
|
2024-04-08 02:03:20 -07:00
|
|
|
local tmpname = t.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')
|
|
|
|
local args = {
|
|
|
|
'-i',
|
|
|
|
o.shadafile or tmpname,
|
|
|
|
}
|
|
|
|
if type(o) == 'string' then
|
|
|
|
args = concat_tables(args, { '--cmd', o })
|
|
|
|
elseif o.args then
|
|
|
|
args = concat_tables(args, o.args)
|
2018-09-20 10:19:38 -07:00
|
|
|
end
|
2024-04-20 08:44:13 -07:00
|
|
|
n.clear {
|
2019-08-09 01:23:57 -07:00
|
|
|
args_rm = args_rm,
|
|
|
|
args = args,
|
|
|
|
}
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_var('tmpname', tmpname)
|
2015-04-26 05:31:39 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
local clear = function()
|
2024-04-20 08:44:13 -07:00
|
|
|
n.expect_exit(n.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
|
|
|
|
|
|
|
|
local mpack_keys = { 'type', 'timestamp', 'length', 'value' }
|
|
|
|
|
|
|
|
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 {
|
|
|
|
reset = reset,
|
|
|
|
clear = clear,
|
2015-08-08 04:54:47 -07:00
|
|
|
get_shada_rw = get_shada_rw,
|
2015-08-09 08:41:25 -07:00
|
|
|
read_shada_file = read_shada_file,
|
2015-04-26 05:31:39 -07:00
|
|
|
}
|