diff options
| -rw-r--r-- | test/unit/eval/helpers.lua | 7 | ||||
| -rw-r--r-- | test/unit/eval/typval_spec.lua | 46 | 
2 files changed, 40 insertions, 13 deletions
| 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 diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 3bd7d9dbaf..ebd53469e8 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -8,6 +8,7 @@ local OK = helpers.OK  local eq = helpers.eq  local neq = helpers.neq  local ffi = helpers.ffi +local FAIL = helpers.FAIL  local cimport = helpers.cimport  local to_cstr = helpers.to_cstr  local alloc_log_new = helpers.alloc_log_new @@ -17,6 +18,7 @@ local int = eval_helpers.int  local list = eval_helpers.list  local dict = eval_helpers.dict  local lst2tbl = eval_helpers.lst2tbl +local dct2tbl = eval_helpers.dct2tbl  local typvalt = eval_helpers.typvalt  local type_key  = eval_helpers.type_key  local li_alloc  = eval_helpers.li_alloc @@ -111,6 +113,18 @@ local function ga_alloc(itemsize, growsize)    return ga  end +local function check_emsg(f, msg) +  local saved_last_msg_hist = lib.last_msg_hist +  local ret = {f()} +  if msg ~= nil then +    neq(saved_last_msg_hist, lib.last_msg_hist) +    eq(msg, ffi.string(lib.last_msg_hist.msg)) +  else +    eq(saved_last_msg_hist, lib.last_msg_hist) +  end +  return unpack(ret) +end +  describe('typval.c', function()    describe('list', function()      describe('item', function() @@ -1242,17 +1256,6 @@ describe('typval.c', function()            alloc_log:check({})          end)        end) -      local function check_emsg(f, msg) -        local saved_last_msg_hist = lib.last_msg_hist -        local ret = {f()} -        if msg ~= nil then -          neq(saved_last_msg_hist, lib.last_msg_hist) -          eq(msg, ffi.string(lib.last_msg_hist.msg)) -        else -          eq(saved_last_msg_hist, lib.last_msg_hist) -        end -        return unpack(ret) -      end        describe('nr()', function()          local function tv_list_find_nr(l, n, msg)            return check_emsg(function() @@ -1543,6 +1546,27 @@ describe('typval.c', function()            check_tv_dict_item_alloc_len('', 0, tv, {a.freed(tv.vval.v_string)})          end)        end) +      describe('add/remove', function() +        itp('works', function() +          local d = dict() +          eq({}, dct2tbl(d)) +          alloc_log:check({a.dict(d)}) +          local di = ffi.gc(lib.tv_dict_item_alloc(''), nil) +          local tv = lua2typvalt('test') +          di.di_tv = tv +          alloc_log:check({a.di(di, ''), a.str(tv.vval.v_string, 'test')}) +          eq(OK, lib.tv_dict_add(d, di)) +          alloc_log:check({}) +          eq(FAIL, check_emsg(function() return lib.tv_dict_add(d, di) end, +                              'E685: Internal error: hash_add()')) +          alloc_log:clear() +          lib.tv_dict_item_remove(d, di) +          alloc_log:check({ +            a.freed(tv.vval.v_string), +            a.freed(di), +          }) +        end) +      end)      end)    end)  end) | 
