2015-04-26 05:31:39 -07:00
|
|
|
local helpers = require('test.functional.helpers')
|
2015-09-26 16:49:48 -07:00
|
|
|
local spawn, set_session, meths, nvim_prog =
|
|
|
|
helpers.spawn, helpers.set_session, helpers.meths, helpers.nvim_prog
|
2015-08-15 07:25:10 -07:00
|
|
|
local write_file, merge_args = helpers.write_file, helpers.merge_args
|
2015-04-26 05:31:39 -07:00
|
|
|
|
2015-08-09 08:41:25 -07:00
|
|
|
local msgpack = require('MessagePack')
|
|
|
|
|
2015-04-26 05:31:39 -07:00
|
|
|
local tmpname = os.tmpname()
|
|
|
|
local additional_cmd = ''
|
|
|
|
|
|
|
|
local function nvim_argv()
|
2015-11-17 14:44:00 -07:00
|
|
|
local argv = {nvim_prog, '-u', 'NONE', '-i', tmpname, '-N',
|
|
|
|
'--cmd', 'set shortmess+=I background=light noswapfile',
|
|
|
|
'--cmd', additional_cmd,
|
|
|
|
'--embed'}
|
2015-04-26 05:31:39 -07:00
|
|
|
if helpers.prepend_argv then
|
2015-11-17 14:44:00 -07:00
|
|
|
return merge_args(helpers.prepend_argv, argv)
|
2015-04-26 05:31:39 -07:00
|
|
|
else
|
2015-11-17 14:44:00 -07:00
|
|
|
return argv
|
2015-04-26 05:31:39 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local reset = function()
|
2016-04-10 19:46:11 -07:00
|
|
|
set_session(spawn(nvim_argv()))
|
2015-09-26 16:49:48 -07:00
|
|
|
meths.set_var('tmpname', tmpname)
|
2015-04-26 05:31:39 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
local set_additional_cmd = function(s)
|
|
|
|
additional_cmd = s
|
|
|
|
end
|
|
|
|
|
|
|
|
local clear = function()
|
|
|
|
os.remove(tmpname)
|
|
|
|
set_additional_cmd('')
|
|
|
|
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()
|
|
|
|
local unpacker = msgpack.unpacker(mstring)
|
|
|
|
local ret = {}
|
|
|
|
local cur
|
|
|
|
local i = 0
|
|
|
|
while true do
|
|
|
|
local off, val = unpacker()
|
|
|
|
if not off then break end
|
|
|
|
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,
|
|
|
|
set_additional_cmd=set_additional_cmd,
|
|
|
|
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
|
|
|
}
|