Update lua client to 0.0.1-24

The new version of the lua client uses libmpack as a backend, and some test
scripts had to be updated to reflect that.
This commit is contained in:
Thiago de Arruda
2016-04-13 09:21:32 -03:00
parent 10a8bb02ac
commit c18d5917e3
14 changed files with 54 additions and 90 deletions

View File

@@ -80,7 +80,7 @@ describe('vim_* functions', function()
it('set_var returns the old value', function()
local val1 = {1, 2, {['3'] = 1}}
local val2 = {4, 7}
eq(nil, nvim('set_var', 'lua', val1))
eq(NIL, nvim('set_var', 'lua', val1))
eq(val1, nvim('set_var', 'lua', val2))
end)

View File

@@ -24,6 +24,6 @@ describe('u_* functions', function()
'-c', 'set undodir=. undofile'})
set_session(session)
execute('echo "True"') -- Should not error out due to crashed Neovim
session:exit(0)
session:close()
end)
end)

View File

@@ -9,7 +9,7 @@ describe(':wshada', function()
before_each(function()
if session then
session:exit(0)
session:close()
end
-- Override the default session because we need 'swapfile' for these tests.

View File

@@ -1,9 +1,8 @@
require('coxpcall')
NIL = require('mpack').NIL
local lfs = require('lfs')
local assert = require('luassert')
local Loop = require('nvim.loop')
local MsgpackStream = require('nvim.msgpack_stream')
local AsyncSession = require('nvim.async_session')
local ChildProcessStream = require('nvim.child_process_stream')
local Session = require('nvim.session')
local nvim_prog = os.getenv('NVIM_PROG') or 'build/bin/nvim'
@@ -60,7 +59,7 @@ local session, loop_running, last_error
local function set_session(s)
if session then
session:exit(0)
session:close()
end
session = s
end
@@ -212,12 +211,8 @@ local function merge_args(...)
end
local function spawn(argv, merge)
local loop = Loop.new()
local msgpack_stream = MsgpackStream.new(loop)
local async_session = AsyncSession.new(msgpack_stream)
local sess = Session.new(async_session)
loop:spawn(merge and merge_args(prepend_argv, argv) or argv)
return sess
local child_stream = ChildProcessStream.spawn(merge and merge_args(prepend_argv, argv) or argv)
return Session.new(child_stream)
end
local function clear(extra_cmd)

View File

@@ -25,7 +25,7 @@ local session = nil
local reset = function(...)
if session then
session:exit(0)
session:close()
end
session = spawn(nvim_argv(...))
set_session(session)

View File

@@ -4,7 +4,7 @@ local eq, nvim_eval, nvim_command, nvim, exc_exec, funcs, nvim_feed, curbuf =
helpers.funcs, helpers.feed, helpers.curbuf
local neq = helpers.neq
local msgpack = require('MessagePack')
local mpack = require('mpack')
local plugin_helpers = require('test.functional.plugin.helpers')
local reset = plugin_helpers.reset
@@ -15,13 +15,13 @@ local get_shada_rw = shada_helpers.get_shada_rw
local mpack_eq = function(expected, mpack_result)
local mpack_keys = {'type', 'timestamp', 'length', 'value'}
local unpacker = msgpack.unpacker(mpack_result)
local unpack = mpack.Unpacker()
local actual = {}
local cur
local cur, val
local i = 0
while true do
local off, val = unpacker()
if not off then break end
local off = 1
while off <= #mpack_result do
val, off = unpack(mpack_result, off)
if i % 4 == 0 then
cur = {}
actual[#actual + 1] = cur
@@ -78,36 +78,6 @@ describe('In autoload/shada.vim', function()
return ('{"_TYPE": v:msgpack_types.%s, "_VAL": %s}'):format(typ, val)
end
local st_meta = {
__pairs=function(table)
local ret = {}
local next_key = nil
local num_keys = 0
while true do
next_key = next(table, next_key)
if next_key == nil then
break
end
num_keys = num_keys + 1
ret[num_keys] = {next_key, table[next_key]}
end
table.sort(ret, function(a, b)
return a[1] < b[1]
end)
local state = {i=0}
return (function(state_, _)
state_.i = state_.i + 1
if ret[state_.i] then
return table.unpack(ret[state_.i])
end
end), state
end
}
local st = function(table)
return setmetatable(table, st_meta)
end
describe('function shada#mpack_to_sd', function()
local mpack2sd = function(arg)
return ('shada#mpack_to_sd(%s)'):format(arg)
@@ -184,7 +154,7 @@ describe('In autoload/shada.vim', function()
' + b 2',
' + c column 3',
' + d 4',
}, {{type=1, timestamp=0, data=st({a=1, b=2, c=3, d=4})}})
}, {{type=1, timestamp=0, data={a=1, b=2, c=3, d=4}}})
sd2strings_eq({
'Header with timestamp ' .. epoch .. ':',
' % Key Value',
@@ -2848,3 +2818,4 @@ describe('syntax/shada.vim', function()
eq(exp, act)
end)
end)

View File

@@ -272,7 +272,7 @@ describe('ShaDa forward compatibility support code', function()
eq(0, exc_exec(sdrcmd(true)))
-- getreg may return empty list as list with NULL pointer which API
-- translates into nil for some reason.
eq({}, funcs.getreg('a', 1, 1) or {})
eq(NIL, funcs.getreg('a', 1, 1) or {})
eq('', funcs.getregtype('a'))
nvim_command('wshada ' .. shada_fname)
local found = 0

View File

@@ -3,7 +3,7 @@ local spawn, set_session, meths, nvim_prog =
helpers.spawn, helpers.set_session, helpers.meths, helpers.nvim_prog
local write_file, merge_args = helpers.write_file, helpers.merge_args
local msgpack = require('MessagePack')
local mpack = require('mpack')
local tmpname = os.tmpname()
local additional_cmd = ''
@@ -60,13 +60,13 @@ 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 unpack = mpack.Unpacker()
local ret = {}
local cur
local cur, val
local i = 0
while true do
local off, val = unpacker()
if not off then break end
local off = 1
while off <= #mstring do
val, off = unpack(mstring, off)
if i % 4 == 0 then
cur = {}
ret[#ret + 1] = cur

View File

@@ -43,9 +43,9 @@ describe('ShaDa support code', function()
setreg('b', {'bca', 'abc', 'cba'}, 'b3')
nvim_command('qall')
reset()
eq({nil, ''}, getreg('c'))
eq({nil, ''}, getreg('l'))
eq({nil, ''}, getreg('b'))
eq({NIL, ''}, getreg('c'))
eq({NIL, ''}, getreg('l'))
eq({NIL, ''}, getreg('b'))
end)
it('does restore registers with zero <', function()
@@ -67,9 +67,9 @@ describe('ShaDa support code', function()
setreg('b', {'bca', 'abc', 'cba'}, 'b3')
nvim_command('qall')
reset()
eq({nil, ''}, getreg('c'))
eq({nil, ''}, getreg('l'))
eq({nil, ''}, getreg('b'))
eq({NIL, ''}, getreg('c'))
eq({NIL, ''}, getreg('l'))
eq({NIL, ''}, getreg('b'))
end)
it('does restore registers with zero "', function()
@@ -103,7 +103,7 @@ describe('ShaDa support code', function()
nvim_command('qall')
reset()
eq({{'d'}, 'v'}, getreg('o'))
eq({nil, ''}, getreg('t'))
eq({NIL, ''}, getreg('t'))
end)
it('does limit number of lines according to "', function()
@@ -113,7 +113,7 @@ describe('ShaDa support code', function()
nvim_command('qall')
reset()
eq({{'d'}, 'v'}, getreg('o'))
eq({nil, ''}, getreg('t'))
eq({NIL, ''}, getreg('t'))
end)
it('does limit number of lines according to < rather then "', function()
@@ -125,7 +125,7 @@ describe('ShaDa support code', function()
reset()
eq({{'d'}, 'v'}, getreg('o'))
eq({{'a', 'b', 'cde'}, 'V'}, getreg('t'))
eq({nil, ''}, getreg('h'))
eq({NIL, ''}, getreg('h'))
end)
it('dumps and loads register correctly when &encoding is not UTF-8',

View File

@@ -8,7 +8,7 @@ local write_file, spawn, set_session, nvim_prog, exc_exec =
local lfs = require('lfs')
local paths = require('test.config.paths')
local msgpack = require('MessagePack')
local mpack = require('mpack')
local shada_helpers = require('test.functional.shada.helpers')
local reset, clear, get_shada_rw =
@@ -107,7 +107,7 @@ describe('ShaDa support code', function()
end)
it('reads correctly various timestamps', function()
local mpack = {
local msgpack = {
'\100', -- Positive fixnum 100
'\204\255', -- uint 8 255
'\205\010\003', -- uint 16 2563
@@ -116,23 +116,23 @@ describe('ShaDa support code', function()
}
local s = '\100'
local e = '\001\192'
wshada(s .. table.concat(mpack, e .. s) .. e)
wshada(s .. table.concat(msgpack, e .. s) .. e)
eq(0, exc_exec('wshada ' .. shada_fname))
local found = 0
local typ = select(2, msgpack.unpacker(s)())
local typ = mpack.unpack(s)
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == typ then
found = found + 1
eq(select(2, msgpack.unpacker(mpack[found])()), v.timestamp)
eq(mpack.unpack(msgpack[found]), v.timestamp)
end
end
eq(#mpack, found)
eq(#msgpack, found)
end)
it('does not write NONE file', function()
local session = spawn({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed',
'--cmd', 'qall'}, true)
session:exit(0)
session:close()
eq(nil, lfs.attributes('NONE'))
eq(nil, lfs.attributes('NONE.tmp.a'))
end)
@@ -143,7 +143,7 @@ describe('ShaDa support code', function()
true)
set_session(session)
eq('', funcs.getreg('a'))
session:exit(0)
session:close()
os.remove('NONE')
end)

View File

@@ -138,7 +138,7 @@ do
-- this is just a helper to get any canonical name of a color
colornames[rgb] = name
end
session:exit(0)
session:close()
Screen.colors = colors
Screen.colornames = colornames
end