diff options
author | ZyX <kp-pav@yandex.ru> | 2017-03-05 01:09:55 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2017-03-29 10:08:45 +0300 |
commit | ffaf7c7521399826d9a32b12a1180bcd162f88be (patch) | |
tree | b1428465d3a0d58a4a030863e862b485681c1e4f | |
parent | cdb1aa3e47cb0ec19d2ae597c1d21b7e892d0d7e (diff) | |
download | rneovim-ffaf7c7521399826d9a32b12a1180bcd162f88be.tar.gz rneovim-ffaf7c7521399826d9a32b12a1180bcd162f88be.tar.bz2 rneovim-ffaf7c7521399826d9a32b12a1180bcd162f88be.zip |
unittests: Add tv_dict_item_{alloc,free} tests
-rw-r--r-- | test/helpers.lua | 14 | ||||
-rw-r--r-- | test/unit/eval/typval_spec.lua | 45 |
2 files changed, 59 insertions, 0 deletions
diff --git a/test/helpers.lua b/test/helpers.lua index e5224349c2..1a86effa1c 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -225,6 +225,19 @@ local function which(exe) end end +local function concat_tables(...) + local ret = {} + for i = 1, select('#', ...) do + local tbl = select(i, ...) + if tbl then + for _, v in ipairs(tbl) do + ret[#ret + 1] = v + end + end + end + return ret +end + return { eq = eq, neq = neq, @@ -238,4 +251,5 @@ return { check_cores = check_cores, hasenv = hasenv, which = which, + concat_tables = concat_tables, } diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 4efde9c6c1..3bd7d9dbaf 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -1,4 +1,5 @@ local helpers = require('test.unit.helpers')(after_each) +local global_helpers = require('test.helpers') local eval_helpers = require('test.unit.eval.helpers') local itp = helpers.gen_itp(it) @@ -31,6 +32,8 @@ local null_string = eval_helpers.null_string local tbl2callback = eval_helpers.tbl2callback local dict_watchers = eval_helpers.dict_watchers +local concat_tables = global_helpers.concat_tables + local lib = cimport('./src/nvim/eval/typval.h', './src/nvim/memory.h', './src/nvim/mbyte.h', './src/nvim/garray.h', './src/nvim/eval.h') @@ -1498,6 +1501,48 @@ describe('typval.c', function() eq({}, dict_watchers(d)) end) end) + describe('notify', function() + -- Way too hard to test it here, functional tests in + -- dict_notifications_spec.lua. + end) + end) + describe('item', function() + describe('alloc/free', function() + local function check_tv_dict_item_alloc_len(s, len, tv, more_frees) + local di + if len == nil then + di = ffi.gc(lib.tv_dict_item_alloc(s), nil) + len = #s + else + di = ffi.gc(lib.tv_dict_item_alloc_len(s, len or #s), nil) + end + eq(s:sub(1, len), ffi.string(di.di_key)) + alloc_log:check({a.di(di, len)}) + if tv then + di.di_tv = tv + else + di.di_tv.v_type = lib.VAR_UNKNOWN + end + lib.tv_dict_item_free(di) + alloc_log:check(concat_tables(more_frees, {a.freed(di)})) + end + local function check_tv_dict_item_alloc(s, tv, more_frees) + return check_tv_dict_item_alloc_len(s, nil, tv, more_frees) + end + itp('works', function() + check_tv_dict_item_alloc('') + check_tv_dict_item_alloc('t') + check_tv_dict_item_alloc('TEST') + check_tv_dict_item_alloc_len('', 0) + check_tv_dict_item_alloc_len('TEST', 2) + local tv = lua2typvalt('test') + alloc_log:check({a.str(tv.vval.v_string, #('test'))}) + check_tv_dict_item_alloc('', tv, {a.freed(tv.vval.v_string)}) + tv = lua2typvalt('test') + alloc_log:check({a.str(tv.vval.v_string, #('test'))}) + check_tv_dict_item_alloc_len('', 0, tv, {a.freed(tv.vval.v_string)}) + end) + end) end) end) end) |