diff options
author | ZyX <kp-pav@yandex.ru> | 2017-04-01 23:57:34 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2017-05-10 15:52:48 +0300 |
commit | f4d5d5250a105b5593e3119f4ee37ea20272a34b (patch) | |
tree | 307cdf0118e0463266dca1c6637a487a8589078a /test/unit/eval/typval_spec.lua | |
parent | d9023b84e63f51611cf55f72ca5e021d64ba7ce9 (diff) | |
download | rneovim-f4d5d5250a105b5593e3119f4ee37ea20272a34b.tar.gz rneovim-f4d5d5250a105b5593e3119f4ee37ea20272a34b.tar.bz2 rneovim-f4d5d5250a105b5593e3119f4ee37ea20272a34b.zip |
eval: Refactor get_user_input to support dictionary
Diffstat (limited to 'test/unit/eval/typval_spec.lua')
-rw-r--r-- | test/unit/eval/typval_spec.lua | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 6308ae7367..5d543f914f 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -1751,6 +1751,55 @@ describe('typval.c', function() eq('2', s) end) end) + describe('get_string_buf_chk()', function() + local function tv_dict_get_string_buf_chk(d, key, len, buf, def, emsg) + buf = buf or ffi.gc(lib.xmalloc(lib.NUMBUFLEN), lib.xfree) + def = def or ffi.gc(lib.xstrdup('DEFAULT'), lib.xfree) + len = len or #key + alloc_log:clear() + local ret = check_emsg(function() return lib.tv_dict_get_string_buf_chk(d, key, len, buf, def) end, + emsg) + local s_ret = (ret ~= nil) and ffi.string(ret) or nil + if not emsg then + alloc_log:check({}) + end + return s_ret, ret, buf, def + end + itp('works with NULL dict', function() + eq('DEFAULT', tv_dict_get_string_buf_chk(nil, 'test')) + end) + itp('works', function() + local lua_d = { + ['']={}, + t=1, + te=int(2), + tes=empty_list, + test='tset', + testt=5, + } + local d = dict(lua_d) + alloc_log:clear() + eq(lua_d, dct2tbl(d)) + alloc_log:check({}) + local s, r, b, def + s, r, b, def = tv_dict_get_string_buf_chk(d, 'test') + neq(r, b) + neq(r, def) + eq('tset', s) + s, r, b, def = tv_dict_get_string_buf_chk(d, 'test', 1, nil, nil, 'E806: using Float as a String') + neq(r, b) + neq(r, def) + eq(nil, s) + s, r, b, def = tv_dict_get_string_buf_chk(d, 'te') + eq(r, b) + neq(r, def) + eq('2', s) + s, r, b, def = tv_dict_get_string_buf_chk(d, 'TEST') + eq(r, def) + neq(r, b) + eq('DEFAULT', s) + end) + end) describe('get_callback()', function() local function tv_dict_get_callback(d, key, key_len, emsg) key_len = key_len or #key |