From fb146e80aa1ead96518f38b9684e39249bc83485 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 26 Jul 2016 23:16:23 +0300 Subject: eval: Split eval.c into smaller files --- test/unit/eval/helpers.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'test/unit/eval/helpers.lua') diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index 1377d5b501..49f929937f 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -5,7 +5,7 @@ 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 eval = cimport('./src/nvim/eval.h', './src/nvim/eval/typval.h', './src/nvim/hashtab.h') local null_string = {[true]='NULL string'} @@ -33,7 +33,7 @@ local function li_alloc(nogc) end local function list(...) - local ret = ffi.gc(eval.list_alloc(), eval.list_unref) + local ret = ffi.gc(eval.tv_list_alloc(), eval.tv_list_unref) eq(0, ret.lv_refcount) ret.lv_refcount = 1 for i = 1, select('#', ...) do @@ -241,7 +241,7 @@ local typvalt = function(typ, vval) elseif type(typ) == 'string' then typ = eval[typ] end - return ffi.gc(ffi.new('typval_T', {v_type=typ, vval=vval}), eval.clear_tv) + return ffi.gc(ffi.new('typval_T', {v_type=typ, vval=vval}), eval.tv_clear) end local lua2typvalt_type_tab = { @@ -256,14 +256,14 @@ local lua2typvalt_type_tab = { processed[l].lv_refcount = processed[l].lv_refcount + 1 return typvalt(eval.VAR_LIST, {v_list=processed[l]}) end - local lst = eval.list_alloc() + local lst = eval.tv_list_alloc() lst.lv_refcount = 1 processed[l] = lst local ret = typvalt(eval.VAR_LIST, {v_list=lst}) for i = 1, #l do local item_tv = ffi.gc(lua2typvalt(l[i], processed), nil) - eval.list_append_tv(lst, item_tv) - eval.clear_tv(item_tv) + eval.tv_list_append_tv(lst, item_tv) + eval.tv_clear(item_tv) end return ret end, @@ -281,7 +281,7 @@ local lua2typvalt_type_tab = { local di = eval.dictitem_alloc(to_cstr(k)) local val_tv = ffi.gc(lua2typvalt(v, processed), nil) eval.copy_tv(val_tv, di.di_tv) - eval.clear_tv(val_tv) + eval.tv_clear(val_tv) eval.dict_add(dct, di) end end @@ -301,7 +301,7 @@ local lua2typvalt_type_tab = { for i, arg in ipairs(l.args) do local arg_tv = ffi.gc(lua2typvalt(arg, processed), nil) eval.copy_tv(arg_tv, argv[i - 1]) - eval.clear_tv(arg_tv) + eval.tv_clear(arg_tv) end end local dict = nil -- cgit From e18a5783080f7c94f408ec5f53dedffdb69789e1 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 Aug 2016 22:24:34 +0300 Subject: *: Move some dictionary functions to typval.h and use char* Also fixes buffer reusage in setmatches() and complete(). --- test/unit/eval/helpers.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/unit/eval/helpers.lua') diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index 49f929937f..be77ef4c83 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -272,17 +272,17 @@ local lua2typvalt_type_tab = { processed[l].dv_refcount = processed[l].dv_refcount + 1 return typvalt(eval.VAR_DICT, {v_dict=processed[l]}) end - local dct = eval.dict_alloc() + local dct = eval.tv_dict_alloc() dct.dv_refcount = 1 processed[l] = dct local ret = typvalt(eval.VAR_DICT, {v_dict=dct}) for k, v in pairs(l) do if type(k) == 'string' then - local di = eval.dictitem_alloc(to_cstr(k)) + local di = eval.tv_dict_item_alloc(to_cstr(k)) local val_tv = ffi.gc(lua2typvalt(v, processed), nil) eval.copy_tv(val_tv, di.di_tv) eval.tv_clear(val_tv) - eval.dict_add(dct, di) + eval.tv_dict_add(dct, di) end end return ret -- cgit From 2ad4fba46db26d0724106b194f7cb628fb9b02e8 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 11 Sep 2016 03:37:03 +0300 Subject: eval: Move copy_tv to eval/typval --- test/unit/eval/helpers.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/unit/eval/helpers.lua') diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index be77ef4c83..c603953a05 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -280,7 +280,7 @@ local lua2typvalt_type_tab = { if type(k) == 'string' then local di = eval.tv_dict_item_alloc(to_cstr(k)) local val_tv = ffi.gc(lua2typvalt(v, processed), nil) - eval.copy_tv(val_tv, di.di_tv) + eval.tv_copy(val_tv, di.di_tv) eval.tv_clear(val_tv) eval.tv_dict_add(dct, di) end @@ -300,7 +300,7 @@ local lua2typvalt_type_tab = { argv = ffi.gc(ffi.cast('typval_T*', eval.xmalloc(ffi.sizeof('typval_T') * #l.args)), nil) for i, arg in ipairs(l.args) do local arg_tv = ffi.gc(lua2typvalt(arg, processed), nil) - eval.copy_tv(arg_tv, argv[i - 1]) + eval.tv_copy(arg_tv, argv[i - 1]) eval.tv_clear(arg_tv) end end -- cgit From a394167177390a66c275d32e3862c82c546970ff Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 12 Mar 2017 13:41:11 +0300 Subject: unittests: Test tv_list_item_\* functions To check that memory is free()d correctly. --- test/unit/eval/helpers.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'test/unit/eval/helpers.lua') diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index c603953a05..8bf06e61f1 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -12,6 +12,7 @@ local null_string = {[true]='NULL string'} local null_list = {[true]='NULL list'} local null_dict = {[true]='NULL dict'} local type_key = {[true]='type key'} +local locks_key = {[true]='locks key'} local list_type = {[true]='list type'} local dict_type = {[true]='dict type'} local func_type = {[true]='func type'} @@ -23,9 +24,9 @@ local nil_value = {[true]='nil'} local lua2typvalt local function li_alloc(nogc) - local gcfunc = eval.listitem_free + local gcfunc = eval.tv_list_item_free if nogc then gcfunc = nil end - local li = ffi.gc(eval.listitem_alloc(), gcfunc) + local li = ffi.gc(eval.tv_list_item_alloc(), gcfunc) li.li_next = nil li.li_prev = nil li.li_tv = {v_type=eval.VAR_UNKNOWN, v_lock=eval.VAR_UNLOCKED} @@ -373,8 +374,9 @@ lua2typvalt = function(l, processed) end end +local void_ptr = ffi.typeof('void *') local function void(ptr) - return ffi.cast('void*', ptr) + return ffi.cast(void_ptr, ptr) end local alloc_logging_helpers = { @@ -386,7 +388,7 @@ local alloc_logging_helpers = { end, str = function(s, size) return {func='malloc', args={size + 1}, ret=void(s)} end, - freed = function(p) return {func='free', args={p and void(p)}} end, + freed = function(p) return {func='free', args={type(p) == 'table' and p or void(p)}} end, } return { @@ -402,6 +404,7 @@ return { nil_value=nil_value, type_key=type_key, + locks_key=locks_key, list=list, lst2tbl=lst2tbl, -- cgit From 9b8beaff021fd83770fb5510904910de2e696263 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 17 Sep 2016 04:25:49 +0300 Subject: unittests: Add tests for tv_list_insert*()/…append*() functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/unit/eval/helpers.lua | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'test/unit/eval/helpers.lua') diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index 8bf06e61f1..f4ea6799f5 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -369,7 +369,7 @@ lua2typvalt = function(l, processed) return typvalt(eval.VAR_STRING, {v_string=eval.xmemdupz(to_cstr(l), #l)}) elseif type(l) == 'cdata' then local tv = typvalt(eval.VAR_UNKNOWN) - eval.copy_tv(l, tv) + eval.tv_copy(l, tv) return tv end end @@ -379,14 +379,28 @@ local function void(ptr) return ffi.cast(void_ptr, ptr) end +local function alloc_len(len, get_ptr) + if type(len) == 'string' or type(len) == 'table' then + return #len + elseif len == nil then + return eval.strlen(get_ptr()) + else + return len + end +end + local alloc_logging_helpers = { list = function(l) return {func='calloc', args={1, ffi.sizeof('list_T')}, ret=void(l)} end, li = function(li) return {func='malloc', args={ffi.sizeof('listitem_T')}, ret=void(li)} end, dict = function(d) return {func='malloc', args={ffi.sizeof('dict_T')}, ret=void(d)} end, di = function(di, size) + size = alloc_len(size, function() return di.di_key end) return {func='malloc', args={ffi.offsetof('dictitem_T', 'di_key') + size + 1}, ret=void(di)} end, - str = function(s, size) return {func='malloc', args={size + 1}, ret=void(s)} end, + str = function(s, size) + size = alloc_len(size, function() return s end) + return {func='malloc', args={size + 1}, ret=void(s)} + end, freed = function(p) return {func='free', args={type(p) == 'table' and p or void(p)}} end, } -- cgit From 7ceebacb3fad49ba8321397cf839948caa55b3f5 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 24 Sep 2016 00:51:34 +0300 Subject: eval/typval,tests: Fix extending list with itself, add tests Adds unit test for tv_list_extend and regression test for extend() VimL function. --- test/unit/eval/helpers.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/unit/eval/helpers.lua') diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index f4ea6799f5..eea5cc8880 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -439,4 +439,6 @@ return { list_items=list_items, dict_items=dict_items, + + empty_list = {[type_key]=list_type}, } -- cgit From e5edf07ec44f8d147d7482cae2997be62c30373f Mon Sep 17 00:00:00 2001 From: ZyX Date: Fri, 4 Nov 2016 19:33:36 +0300 Subject: unittests: Add tests for tv_list_find*() functions Additional modifications: - More `const` qualifiers in tested functions. - `tv_list_find_str()` second argument is more in-line with other `tv_list_find*()` functions. --- test/unit/eval/helpers.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test/unit/eval/helpers.lua') diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index eea5cc8880..cd85b143d9 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -405,7 +405,13 @@ local alloc_logging_helpers = { freed = function(p) return {func='free', args={type(p) == 'table' and p or void(p)}} end, } +local function int(n) + return {[type_key]=int_type, value=n} +end + return { + int=int, + null_string=null_string, null_list=null_list, null_dict=null_dict, -- cgit From 4c3be98db9b24b7d5b8dc2cf55574e778b7ad137 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 4 Mar 2017 23:28:54 +0300 Subject: unittests: Add tv_dict_watcher_{add,remove} tests --- test/unit/eval/helpers.lua | 246 +++++++++++++++++++++++++++++++-------------- 1 file changed, 168 insertions(+), 78 deletions(-) (limited to 'test/unit/eval/helpers.lua') diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index cd85b143d9..21ef51ff20 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -33,18 +33,62 @@ local function li_alloc(nogc) return li end -local function list(...) - local ret = ffi.gc(eval.tv_list_alloc(), eval.tv_list_unref) - eq(0, ret.lv_refcount) - ret.lv_refcount = 1 - for i = 1, select('#', ...) do - local val = select(i, ...) - local li_tv = ffi.gc(lua2typvalt(val), nil) - local li = li_alloc(true) - li.li_tv = li_tv - eval.tv_list_append(ret, li) +local function populate_list(l, lua_l, processed) + processed = processed or {} + eq(0, l.lv_refcount) + l.lv_refcount = 1 + processed[lua_l] = l + for i = 1, #lua_l do + local item_tv = ffi.gc(lua2typvalt(lua_l[i], processed), nil) + local item_li = eval.tv_list_item_alloc() + item_li.li_tv = item_tv + eval.tv_list_append(l, item_li) end - return ret + return l +end + +local function populate_dict(d, lua_d, processed) + processed = processed or {} + eq(0, d.dv_refcount) + d.dv_refcount = 1 + processed[lua_d] = d + for k, v in pairs(lua_d) do + if type(k) == 'string' then + local di = eval.tv_dict_item_alloc(to_cstr(k)) + local val_tv = ffi.gc(lua2typvalt(v, processed), nil) + eval.tv_copy(val_tv, di.di_tv) + eval.tv_clear(val_tv) + eval.tv_dict_add(d, di) + end + end + return d +end + +local function populate_partial(pt, lua_pt, processed) + processed = processed or {} + eq(0, pt.pt_refcount) + processed[lua_pt] = pt + local argv = nil + if lua_pt.args and #lua_pt.args > 0 then + argv = ffi.gc(ffi.cast('typval_T*', eval.xmalloc(ffi.sizeof('typval_T') * #lua_pt.args)), nil) + for i, arg in ipairs(lua_pt.args) do + local arg_tv = ffi.gc(lua2typvalt(arg, processed), nil) + argv[i - 1] = arg_tv + end + end + local dict = nil + if lua_pt.dict then + local dict_tv = ffi.gc(lua2typvalt(lua_pt.dict, processed), nil) + assert(dict_tv.v_type == eval.VAR_DICT) + dict = dict_tv.vval.v_dict + end + pt.pt_refcount = 1 + pt.pt_name = eval.xmemdupz(to_cstr(lua_pt.value), #lua_pt.value) + pt.pt_auto = not not lua_pt.auto + pt.pt_argc = lua_pt.args and #lua_pt.args or 0 + pt.pt_argv = argv + pt.pt_dict = dict + return pt end local ptr2key = function(ptr) @@ -55,6 +99,30 @@ local lst2tbl local dct2tbl local typvalt2lua + +local function partial2lua(pt, processed) + processed = processed or {} + local value, auto, dict, argv = nil, nil, nil, nil + if pt ~= nil then + value = ffi.string(pt.pt_name) + auto = pt.pt_auto and true or nil + argv = {} + for i = 1, pt.pt_argc do + argv[i] = typvalt2lua(pt.pt_argv[i - 1], processed) + end + if pt.pt_dict ~= nil then + dict = dct2tbl(pt.pt_dict) + end + end + return { + [type_key]=func_type, + value=value, + auto=auto, + args=argv, + dict=dict, + } +end + local typvalt2lua_tab = nil local function typvalt2lua_tab_init() @@ -97,26 +165,7 @@ local function typvalt2lua_tab_init() if processed[p_key] then return processed[p_key] end - local pt = t.vval.v_partial - local value, auto, dict, argv = nil, nil, nil, nil - if pt ~= nil then - value = ffi.string(pt.pt_name) - auto = pt.pt_auto and true or nil - argv = {} - for i = 1, pt.pt_argc do - argv[i] = typvalt2lua(pt.pt_argv[i - 1], processed) - end - if pt.pt_dict ~= nil then - dict = dct2tbl(pt.pt_dict) - end - end - return { - [type_key]=func_type, - value=value, - auto=auto, - args=argv, - dict=dict, - } + return partial2lua(t.vval.v_partial, processed) end, } end @@ -257,36 +306,16 @@ local lua2typvalt_type_tab = { processed[l].lv_refcount = processed[l].lv_refcount + 1 return typvalt(eval.VAR_LIST, {v_list=processed[l]}) end - local lst = eval.tv_list_alloc() - lst.lv_refcount = 1 - processed[l] = lst - local ret = typvalt(eval.VAR_LIST, {v_list=lst}) - for i = 1, #l do - local item_tv = ffi.gc(lua2typvalt(l[i], processed), nil) - eval.tv_list_append_tv(lst, item_tv) - eval.tv_clear(item_tv) - end - return ret + local lst = populate_list(eval.tv_list_alloc(), l, processed) + return typvalt(eval.VAR_LIST, {v_list=lst}) end, [dict_type] = function(l, processed) if processed[l] then processed[l].dv_refcount = processed[l].dv_refcount + 1 return typvalt(eval.VAR_DICT, {v_dict=processed[l]}) end - local dct = eval.tv_dict_alloc() - dct.dv_refcount = 1 - processed[l] = dct - local ret = typvalt(eval.VAR_DICT, {v_dict=dct}) - for k, v in pairs(l) do - if type(k) == 'string' then - local di = eval.tv_dict_item_alloc(to_cstr(k)) - local val_tv = ffi.gc(lua2typvalt(v, processed), nil) - eval.tv_copy(val_tv, di.di_tv) - eval.tv_clear(val_tv) - eval.tv_dict_add(dct, di) - end - end - return ret + local dct = populate_dict(eval.tv_dict_alloc(), l, processed) + return typvalt(eval.VAR_DICT, {v_dict=dct}) end, [func_type] = function(l, processed) if processed[l] then @@ -294,29 +323,8 @@ local lua2typvalt_type_tab = { return typvalt(eval.VAR_PARTIAL, {v_partial=processed[l]}) end if l.args or l.dict then - local pt = ffi.gc(ffi.cast('partial_T*', eval.xmalloc(ffi.sizeof('partial_T'))), nil) - processed[l] = pt - local argv = nil - if l.args and #l.args > 0 then - argv = ffi.gc(ffi.cast('typval_T*', eval.xmalloc(ffi.sizeof('typval_T') * #l.args)), nil) - for i, arg in ipairs(l.args) do - local arg_tv = ffi.gc(lua2typvalt(arg, processed), nil) - eval.tv_copy(arg_tv, argv[i - 1]) - eval.tv_clear(arg_tv) - end - end - local dict = nil - if l.dict then - local dict_tv = ffi.gc(lua2typvalt(l.dict, processed), nil) - assert(dict_tv.v_type == eval.VAR_DICT) - dict = dict_tv.vval.v_dict - end - pt.pt_refcount = 1 - pt.pt_name = eval.xmemdupz(to_cstr(l.value), #l.value) - pt.pt_auto = not not l.auto - pt.pt_argc = l.args and #l.args or 0 - pt.pt_argv = argv - pt.pt_dict = dict + local pt = populate_partial(ffi.gc(ffi.cast('partial_T*', + eval.xcalloc(1, ffi.sizeof('partial_T'))), nil), l, processed) return typvalt(eval.VAR_PARTIAL, {v_partial=pt}) else return typvalt(eval.VAR_FUNC, { @@ -402,13 +410,91 @@ local alloc_logging_helpers = { return {func='malloc', args={size + 1}, ret=void(s)} end, + dwatcher = function(w) return {func='malloc', args={ffi.sizeof('DictWatcher')}, ret=void(w)} end, + freed = function(p) return {func='free', args={type(p) == 'table' and p or void(p)}} end, + + -- lua_…: allocated by this file, not by some Neovim function + lua_pt = function(pt) return {func='calloc', args={1, ffi.sizeof('partial_T')}, ret=void(pt)} end, + lua_tvs = function(argv, argc) return {func='malloc', args={ffi.sizeof('typval_T')*argc}, ret=void(argv)} end, } local function int(n) return {[type_key]=int_type, value=n} end +local function list(...) + return populate_list(ffi.gc(eval.tv_list_alloc(), eval.tv_list_unref), + {...}, {}) +end + +local function dict(d) + return populate_dict(ffi.gc(eval.tv_dict_alloc(), eval.tv_dict_free), + d, {}) +end + +local callback2tbl_type_tab = nil + +local function init_callback2tbl_type_tab() + if callback2tbl_type_tab then + return + end + callback2tbl_type_tab = { + [tonumber(eval.kCallbackNone)] = function(_) return {type='none'} end, + [tonumber(eval.kCallbackFuncref)] = function(cb) + return {type='fref', fref=ffi.string(cb.data.funcref)} + end, + [tonumber(eval.kCallbackPartial)] = function(cb) + local lua_pt = partial2lua(cb.data.partial) + return {type='pt', fref=ffi.string(lua_pt.value), pt=lua_pt} + end + } +end + +local function callback2tbl(cb) + init_callback2tbl_type_tab() + return callback2tbl_type_tab[tonumber(cb.type)](cb) +end + +local function tbl2callback(tbl) + local ret = nil + if tbl.type == 'none' then + ret = ffi.new('Callback[1]', {{type=eval.kCallbackNone}}) + elseif tbl.type == 'fref' then + ret = ffi.new('Callback[1]', {{type=eval.kCallbackFuncref, + data={funcref=eval.xstrdup(tbl.fref)}}}) + elseif tbl.type == 'pt' then + local pt = ffi.gc(ffi.cast('partial_T*', + eval.xcalloc(1, ffi.sizeof('partial_T'))), eval.partial_unref) + ret = ffi.new('Callback[1]', {{type=eval.kCallbackPartial, + data={partial=populate_partial(pt, tbl.pt, {})}}}) + else + assert(false) + end + return ffi.gc(ffi.cast('Callback*', ret), helpers.callback_free) +end + +local function dict_watchers(d) + local ret = {} + local h = d.watchers + local q = h.next + local qs = {} + local key_patterns = {} + while q ~= h do + local qitem = ffi.cast('DictWatcher *', + ffi.cast('char *', q) - ffi.offsetof('DictWatcher', 'node')) + ret[#ret + 1] = { + cb=callback2tbl(qitem.callback), + pat=ffi.string(qitem.key_pattern, qitem.key_pattern_len), + busy=qitem.busy, + } + qs[#qs + 1] = qitem + key_patterns[#key_patterns + 1] = {qitem.key_pattern, qitem.key_pattern_len} + q = q.next + end + return ret, qs, key_patterns +end + return { int=int, @@ -427,6 +513,7 @@ return { locks_key=locks_key, list=list, + dict=dict, lst2tbl=lst2tbl, dct2tbl=dct2tbl, @@ -446,5 +533,8 @@ return { list_items=list_items, dict_items=dict_items, + dict_watchers=dict_watchers, + tbl2callback=tbl2callback, + empty_list = {[type_key]=list_type}, } -- cgit From 6c622ed08bb56f08f4cc4dbf6251220ccf7ba2ba Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 5 Mar 2017 01:26:26 +0300 Subject: unittests: Add tv_dict_item_{add,remove} tests --- test/unit/eval/helpers.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'test/unit/eval/helpers.lua') diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index 21ef51ff20..8faa8dbf5c 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -416,7 +416,10 @@ local alloc_logging_helpers = { -- lua_…: allocated by this file, not by some Neovim function lua_pt = function(pt) return {func='calloc', args={1, ffi.sizeof('partial_T')}, ret=void(pt)} end, - lua_tvs = function(argv, argc) return {func='malloc', args={ffi.sizeof('typval_T')*argc}, ret=void(argv)} end, + lua_tvs = function(argv, argc) + argc = alloc_len(argc) + return {func='malloc', args={ffi.sizeof('typval_T')*argc}, ret=void(argv)} + end, } local function int(n) @@ -430,7 +433,7 @@ end local function dict(d) return populate_dict(ffi.gc(eval.tv_dict_alloc(), eval.tv_dict_free), - d, {}) + d or {}, {}) end local callback2tbl_type_tab = nil -- cgit From bc87d23c28c10c70b4addaf18ae16bcbe0682c8a Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 12 Mar 2017 21:58:57 +0300 Subject: unittests: Add tests for dictionary indexing --- test/unit/eval/helpers.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'test/unit/eval/helpers.lua') diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index 8faa8dbf5c..6909953022 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -538,6 +538,7 @@ return { dict_watchers=dict_watchers, tbl2callback=tbl2callback, + callback2tbl=callback2tbl, empty_list = {[type_key]=list_type}, } -- cgit From 8b9a1fbf7a630b68b1428a39f25e1fa38fe0cc9f Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 13 Mar 2017 14:35:53 +0300 Subject: unittests: Add tests for tv_dict_extend --- test/unit/eval/helpers.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test/unit/eval/helpers.lua') diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index 6909953022..a3cb062b7b 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -498,6 +498,16 @@ local function dict_watchers(d) return ret, qs, key_patterns end +local function eval0(expr) + local tv = ffi.gc(ffi.new('typval_T', {v_type=eval.VAR_UNKNOWN}), + eval.tv_clear) + if eval.eval0(to_cstr(expr), tv, nil, true) == 0 then + return nil + else + return tv + end +end + return { int=int, @@ -540,5 +550,7 @@ return { tbl2callback=tbl2callback, callback2tbl=callback2tbl, + eval0=eval0, + empty_list = {[type_key]=list_type}, } -- cgit From ed4948a93317bf801eb2454fd5597a4388730a7b Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 13 Mar 2017 19:49:13 +0300 Subject: unittests: Test tv_copy() --- test/unit/eval/helpers.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test/unit/eval/helpers.lua') diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index a3cb062b7b..fa76113756 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -132,10 +132,10 @@ local function typvalt2lua_tab_init() typvalt2lua_tab = { [tonumber(eval.VAR_SPECIAL)] = function(t) return ({ - [eval.kSpecialVarFalse] = false, - [eval.kSpecialVarNull] = nil_value, - [eval.kSpecialVarTrue] = true, - })[t.vval.v_special] + [tonumber(eval.kSpecialVarFalse)] = false, + [tonumber(eval.kSpecialVarNull)] = nil_value, + [tonumber(eval.kSpecialVarTrue)] = true, + })[tonumber(t.vval.v_special)] end, [tonumber(eval.VAR_NUMBER)] = function(t) return {[type_key]=int_type, value=tonumber(t.vval.v_number)} -- cgit