diff options
author | ZyX <kp-pav@yandex.ru> | 2016-02-09 03:20:16 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2016-04-18 02:47:13 +0300 |
commit | 77776b09c684bc2a0c42114fce5a8b04409ec91d (patch) | |
tree | de255689c5cc709b88e065b1a99bffed0e310ac0 /test/unit/eval/helpers.lua | |
parent | c27395ddc84952b94118de94af4c33f56f6beca5 (diff) | |
download | rneovim-77776b09c684bc2a0c42114fce5a8b04409ec91d.tar.gz rneovim-77776b09c684bc2a0c42114fce5a8b04409ec91d.tar.bz2 rneovim-77776b09c684bc2a0c42114fce5a8b04409ec91d.zip |
eval/encode: Fix writing strings starting with NL to list
Error [found][1] by oni-link.
[1]: https://github.com/neovim/neovim/pull/4131/files#r52239384
Diffstat (limited to 'test/unit/eval/helpers.lua')
-rw-r--r-- | test/unit/eval/helpers.lua | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua new file mode 100644 index 0000000000..da2f5626ff --- /dev/null +++ b/test/unit/eval/helpers.lua @@ -0,0 +1,72 @@ +local helpers = require('test.unit.helpers') + +local cimport = helpers.cimport +local to_cstr = helpers.to_cstr +local ffi = helpers.ffi +local eq = helpers.eq + +local eval = cimport('./src/nvim/eval.h', './src/nvim/eval_defs.h') + +local null_string = {[true]='NULL string'} +local null_list = {[true]='NULL list'} +local type_key = {[true]='type key'} +local list_type = {[true]='list type'} + +local list = function(...) + local ret = ffi.gc(eval.list_alloc(), eval.list_unref) + eq(0, ret.lv_refcount) + ret.lv_refcount = 1 + for i = 1, select('#', ...) do + local val = select(i, ...) + local typ = type(val) + if typ == 'string' then + eval.list_append_string(ret, to_cstr(val)) + elseif typ == 'table' and val == null_string then + eval.list_append_string(ret, nil) + elseif typ == 'table' and val == null_list then + eval.list_append_list(ret, nil) + elseif typ == 'table' and val[type_key] == list_type then + local itemlist = ffi.gc(list(table.unpack(val)), nil) + eq(1, itemlist.lv_refcount) + itemlist.lv_refcount = 0 + eval.list_append_list(ret, itemlist) + else + assert(false, 'Not implemented yet') + end + end + return ret +end + +local lst2tbl = function(l) + local ret = {[type_key]=list_type} + if l == nil then + return ret + end + local li = l.lv_first + -- (listitem_T *) NULL is equal to nil, but yet it is not false. + while li ~= nil do + local typ = li.li_tv.v_type + if typ == eval.VAR_STRING then + str = li.li_tv.vval.v_string + if str == nil then + ret[#ret + 1] = null_string + else + ret[#ret + 1] = ffi.string(str) + end + else + assert(false, 'Not implemented yet') + end + li = li.li_next + end + return ret +end + +return { + null_string=null_string, + null_list=null_list, + list_type=list_type, + type_key=type_key, + + list=list, + lst2tbl=lst2tbl, +} |