diff options
Diffstat (limited to 'test/unit/eval')
-rw-r--r-- | test/unit/eval/decode_spec.lua | 41 | ||||
-rw-r--r-- | test/unit/eval/encode_spec.lua | 39 | ||||
-rw-r--r-- | test/unit/eval/helpers.lua | 285 | ||||
-rw-r--r-- | test/unit/eval/tricks_spec.lua | 3 | ||||
-rw-r--r-- | test/unit/eval/tv_clear_spec.lua | 14 | ||||
-rw-r--r-- | test/unit/eval/typval_spec.lua | 1549 |
6 files changed, 1152 insertions, 779 deletions
diff --git a/test/unit/eval/decode_spec.lua b/test/unit/eval/decode_spec.lua index 0c444b33f2..5a8374a2a6 100644 --- a/test/unit/eval/decode_spec.lua +++ b/test/unit/eval/decode_spec.lua @@ -6,9 +6,13 @@ local eq = helpers.eq local neq = helpers.neq local ffi = helpers.ffi -local decode = cimport('./src/nvim/eval/decode.h', './src/nvim/eval/typval.h', - './src/nvim/globals.h', './src/nvim/memory.h', - './src/nvim/message.h') +local decode = cimport( + './src/nvim/eval/decode.h', + './src/nvim/eval/typval.h', + './src/nvim/globals.h', + './src/nvim/memory.h', + './src/nvim/message.h' +) describe('json_decode_string()', function() local char = function(c) @@ -16,7 +20,7 @@ describe('json_decode_string()', function() end itp('does not overflow when running with `n…`, `t…`, `f…`', function() - local rettv = ffi.new('typval_T', {v_type=decode.VAR_UNKNOWN}) + local rettv = ffi.new('typval_T', { v_type = decode.VAR_UNKNOWN }) decode.emsg_silent = 1 -- This will not crash, but if `len` argument will be ignored it will parse -- `null` as `null` and if not it will parse `null` as `n`. @@ -43,7 +47,7 @@ describe('json_decode_string()', function() end) itp('does not overflow and crash when running with `n`, `t`, `f`', function() - local rettv = ffi.new('typval_T', {v_type=decode.VAR_UNKNOWN}) + local rettv = ffi.new('typval_T', { v_type = decode.VAR_UNKNOWN }) decode.emsg_silent = 1 eq(0, decode.json_decode_string(char('n'), 1, rettv)) eq(decode.VAR_UNKNOWN, rettv.v_type) @@ -54,7 +58,7 @@ describe('json_decode_string()', function() end) itp('does not overflow when running with `"…`', function() - local rettv = ffi.new('typval_T', {v_type=decode.VAR_UNKNOWN}) + local rettv = ffi.new('typval_T', { v_type = decode.VAR_UNKNOWN }) decode.emsg_silent = 1 eq(0, decode.json_decode_string('"t"', 2, rettv)) eq(decode.VAR_UNKNOWN, rettv.v_type) @@ -63,7 +67,7 @@ describe('json_decode_string()', function() end) local check_failure = function(s, len, msg) - local rettv = ffi.new('typval_T', {v_type=decode.VAR_UNKNOWN}) + local rettv = ffi.new('typval_T', { v_type = decode.VAR_UNKNOWN }) eq(0, decode.json_decode_string(s, len, rettv)) eq(decode.VAR_UNKNOWN, rettv.v_type) neq(nil, decode.last_msg_hist) @@ -74,8 +78,7 @@ describe('json_decode_string()', function() collectgarbage('restart') check_failure(']test', 1, 'E474: No container to close: ]') check_failure('[}test', 2, 'E474: Closing list with curly bracket: }') - check_failure('{]test', 2, - 'E474: Closing dictionary with square bracket: ]') + check_failure('{]test', 2, 'E474: Closing dictionary with square bracket: ]') check_failure('[1,]test', 4, 'E474: Trailing comma: ]') check_failure('{"1":}test', 6, 'E474: Expected value after colon: }') check_failure('{"1"}test', 5, 'E474: Expected value: }') @@ -93,16 +96,20 @@ describe('json_decode_string()', function() check_failure('ttest', 1, 'E474: Expected true: t') check_failure('ftest', 1, 'E474: Expected false: f') check_failure('"\\test', 2, 'E474: Unfinished escape sequence: "\\') - check_failure('"\\u"test', 4, - 'E474: Unfinished unicode escape sequence: "\\u"') - check_failure('"\\uXXXX"est', 8, - 'E474: Expected four hex digits after \\u: \\uXXXX"') + check_failure('"\\u"test', 4, 'E474: Unfinished unicode escape sequence: "\\u"') + check_failure('"\\uXXXX"est', 8, 'E474: Expected four hex digits after \\u: \\uXXXX"') check_failure('"\\?"test', 4, 'E474: Unknown escape sequence: \\?"') check_failure( - '"\t"test', 3, - 'E474: ASCII control characters cannot be present inside string: \t"') + '"\t"test', + 3, + 'E474: ASCII control characters cannot be present inside string: \t"' + ) check_failure('"\194"test', 3, 'E474: Only UTF-8 strings allowed: \194"') - check_failure('"\252\144\128\128\128\128"test', 8, 'E474: Only UTF-8 code points up to U+10FFFF are allowed to appear unescaped: \252\144\128\128\128\128"') + check_failure( + '"\252\144\128\128\128\128"test', + 8, + 'E474: Only UTF-8 code points up to U+10FFFF are allowed to appear unescaped: \252\144\128\128\128\128"' + ) check_failure('"test', 1, 'E474: Expected string end: "') check_failure('-test', 1, 'E474: Missing number after minus sign: -') check_failure('-1.test', 3, 'E474: Missing number after decimal dot: -1.') @@ -117,7 +124,7 @@ describe('json_decode_string()', function() end) itp('does not overflow and crash when running with `"`', function() - local rettv = ffi.new('typval_T', {v_type=decode.VAR_UNKNOWN}) + local rettv = ffi.new('typval_T', { v_type = decode.VAR_UNKNOWN }) decode.emsg_silent = 1 eq(0, decode.json_decode_string(char('"'), 1, rettv)) eq(decode.VAR_UNKNOWN, rettv.v_type) diff --git a/test/unit/eval/encode_spec.lua b/test/unit/eval/encode_spec.lua index 058c55093e..498346d7cc 100644 --- a/test/unit/eval/encode_spec.lua +++ b/test/unit/eval/encode_spec.lua @@ -22,80 +22,83 @@ describe('encode_list_write()', function() itp('writes empty string', function() local l = list() eq(0, encode_list_write(l, '')) - eq({[type_key]=list_type}, lst2tbl(l)) + eq({ [type_key] = list_type }, lst2tbl(l)) end) itp('writes ASCII string literal with printable characters', function() local l = list() eq(0, encode_list_write(l, 'abc')) - eq({'abc'}, lst2tbl(l)) + eq({ 'abc' }, lst2tbl(l)) end) itp('writes string starting with NL', function() local l = list() eq(0, encode_list_write(l, '\nabc')) - eq({null_string, 'abc'}, lst2tbl(l)) + eq({ null_string, 'abc' }, lst2tbl(l)) end) itp('writes string starting with NL twice', function() local l = list() eq(0, encode_list_write(l, '\nabc')) - eq({null_string, 'abc'}, lst2tbl(l)) + eq({ null_string, 'abc' }, lst2tbl(l)) eq(0, encode_list_write(l, '\nabc')) - eq({null_string, 'abc', 'abc'}, lst2tbl(l)) + eq({ null_string, 'abc', 'abc' }, lst2tbl(l)) end) itp('writes string ending with NL', function() local l = list() eq(0, encode_list_write(l, 'abc\n')) - eq({'abc', null_string}, lst2tbl(l)) + eq({ 'abc', null_string }, lst2tbl(l)) end) itp('writes string ending with NL twice', function() local l = list() eq(0, encode_list_write(l, 'abc\n')) - eq({'abc', null_string}, lst2tbl(l)) + eq({ 'abc', null_string }, lst2tbl(l)) eq(0, encode_list_write(l, 'abc\n')) - eq({'abc', 'abc', null_string}, lst2tbl(l)) + eq({ 'abc', 'abc', null_string }, lst2tbl(l)) end) itp('writes string starting, ending and containing NL twice', function() local l = list() eq(0, encode_list_write(l, '\na\nb\n')) - eq({null_string, 'a', 'b', null_string}, lst2tbl(l)) + eq({ null_string, 'a', 'b', null_string }, lst2tbl(l)) eq(0, encode_list_write(l, '\na\nb\n')) - eq({null_string, 'a', 'b', null_string, 'a', 'b', null_string}, lst2tbl(l)) + eq({ null_string, 'a', 'b', null_string, 'a', 'b', null_string }, lst2tbl(l)) end) itp('writes string starting, ending and containing NUL with NL between twice', function() local l = list() eq(0, encode_list_write(l, '\0\n\0\n\0')) - eq({'\n', '\n', '\n'}, lst2tbl(l)) + eq({ '\n', '\n', '\n' }, lst2tbl(l)) eq(0, encode_list_write(l, '\0\n\0\n\0')) - eq({'\n', '\n', '\n\n', '\n', '\n'}, lst2tbl(l)) + eq({ '\n', '\n', '\n\n', '\n', '\n' }, lst2tbl(l)) end) itp('writes string starting, ending and containing NL with NUL between twice', function() local l = list() eq(0, encode_list_write(l, '\n\0\n\0\n')) - eq({null_string, '\n', '\n', null_string}, lst2tbl(l)) + eq({ null_string, '\n', '\n', null_string }, lst2tbl(l)) eq(0, encode_list_write(l, '\n\0\n\0\n')) - eq({null_string, '\n', '\n', null_string, '\n', '\n', null_string}, lst2tbl(l)) + eq({ null_string, '\n', '\n', null_string, '\n', '\n', null_string }, lst2tbl(l)) end) itp('writes string containing a single NL twice', function() local l = list() eq(0, encode_list_write(l, '\n')) - eq({null_string, null_string}, lst2tbl(l)) + eq({ null_string, null_string }, lst2tbl(l)) eq(0, encode_list_write(l, '\n')) - eq({null_string, null_string, null_string}, lst2tbl(l)) + eq({ null_string, null_string, null_string }, lst2tbl(l)) end) itp('writes string containing a few NLs twice', function() local l = list() eq(0, encode_list_write(l, '\n\n\n')) - eq({null_string, null_string, null_string, null_string}, lst2tbl(l)) + eq({ null_string, null_string, null_string, null_string }, lst2tbl(l)) eq(0, encode_list_write(l, '\n\n\n')) - eq({null_string, null_string, null_string, null_string, null_string, null_string, null_string}, lst2tbl(l)) + eq( + { null_string, null_string, null_string, null_string, null_string, null_string, null_string }, + lst2tbl(l) + ) end) end) diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index 883f01bd84..6402e1f8c9 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -6,21 +6,25 @@ local to_cstr = helpers.to_cstr local ffi = helpers.ffi local eq = helpers.eq -local eval = cimport('./src/nvim/eval.h', './src/nvim/eval/typval.h', - './src/nvim/hashtab.h', './src/nvim/memory.h') - -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'} -local int_type = {[true]='int type'} -local flt_type = {[true]='flt type'} - -local nil_value = {[true]='nil'} +local eval = cimport( + './src/nvim/eval.h', + './src/nvim/eval/typval.h', + './src/nvim/hashtab.h', + './src/nvim/memory.h' +) + +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' } +local int_type = { [true] = 'int type' } +local flt_type = { [true] = 'flt type' } + +local nil_value = { [true] = 'nil' } local lua2typvalt @@ -35,11 +39,13 @@ end local function li_alloc(nogc) local gcfunc = tv_list_item_free - if nogc then gcfunc = nil end + if nogc then + gcfunc = nil + end local li = ffi.gc(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} + li.li_tv = { v_type = eval.VAR_UNKNOWN, v_lock = eval.VAR_UNLOCKED } return li end @@ -121,11 +127,11 @@ local function partial2lua(pt, processed) end end return { - [type_key]=func_type, - value=value, - auto=auto, - args=argv, - dict=dict, + [type_key] = func_type, + value = value, + auto = auto, + args = argv, + dict = dict, } end @@ -148,7 +154,7 @@ local function typvalt2lua_tab_init() })[tonumber(t.vval.v_special)] end, [tonumber(eval.VAR_NUMBER)] = function(t) - return {[type_key]=int_type, value=tonumber(t.vval.v_number)} + return { [type_key] = int_type, value = tonumber(t.vval.v_number) } end, [tonumber(eval.VAR_FLOAT)] = function(t) return tonumber(t.vval.v_float) @@ -168,7 +174,7 @@ local function typvalt2lua_tab_init() return dct2tbl(t.vval.v_dict, processed) end, [tonumber(eval.VAR_FUNC)] = function(t, processed) - return {[type_key]=func_type, value=typvalt2lua_tab[eval.VAR_STRING](t, processed or {})} + return { [type_key] = func_type, value = typvalt2lua_tab[eval.VAR_STRING](t, processed or {}) } end, [tonumber(eval.VAR_PARTIAL)] = function(t, processed) local p_key = ptr2key(t) @@ -182,15 +188,17 @@ end typvalt2lua = function(t, processed) typvalt2lua_tab_init() - return ((typvalt2lua_tab[tonumber(t.v_type)] or function(t_inner) - assert(false, 'Converting ' .. tonumber(t_inner.v_type) .. ' was not implemented yet') - end)(t, processed or {})) + return ( + (typvalt2lua_tab[tonumber(t.v_type)] or function(t_inner) + assert(false, 'Converting ' .. tonumber(t_inner.v_type) .. ' was not implemented yet') + end)(t, processed or {}) + ) end local function list_iter(l) local init_s = { - idx=0, - li=l.lv_first, + idx = 0, + li = l.lv_first, } local function f(s, _) -- (listitem_T *) NULL is equal to nil, but yet it is not false. @@ -222,7 +230,7 @@ lst2tbl = function(l, processed) if processed[p_key] then return processed[p_key] end - local ret = {[type_key]=list_type} + local ret = { [type_key] = list_type } processed[p_key] = ret for i, li in list_iter(l) do ret[i] = typvalt2lua(li.li_tv, processed) @@ -238,11 +246,13 @@ local hi_key_removed = nil local function dict_iter(d, return_hi) hi_key_removed = hi_key_removed or eval._hash_key_removed() local init_s = { - todo=d.dv_hashtab.ht_used, - hi=d.dv_hashtab.ht_array, + todo = d.dv_hashtab.ht_used, + hi = d.dv_hashtab.ht_array, } local function f(s, _) - if s.todo == 0 then return nil end + if s.todo == 0 then + return nil + end while s.todo > 0 do if s.hi.hi_key ~= nil and s.hi.hi_key ~= hi_key_removed then local key = ffi.string(s.hi.hi_key) @@ -250,8 +260,7 @@ local function dict_iter(d, return_hi) if return_hi then ret = s.hi else - ret = ffi.cast('dictitem_T*', - s.hi.hi_key - ffi.offsetof('dictitem_T', 'di_key')) + ret = ffi.cast('dictitem_T*', s.hi.hi_key - ffi.offsetof('dictitem_T', 'di_key')) end s.todo = s.todo - 1 s.hi = s.hi + 1 @@ -269,7 +278,7 @@ local function first_di(d) end local function dict_items(d) - local ret = {[0]=0} + local ret = { [0] = 0 } for k, hi in dict_iter(d) do ret[k] = hi ret[0] = ret[0] + 1 @@ -301,12 +310,12 @@ 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.tv_clear) + return ffi.gc(ffi.new('typval_T', { v_type = typ, vval = vval }), eval.tv_clear) end local lua2typvalt_type_tab = { [int_type] = function(l, _) - return typvalt(eval.VAR_NUMBER, {v_number=l.value}) + return typvalt(eval.VAR_NUMBER, { v_number = l.value }) end, [flt_type] = function(l, processed) return lua2typvalt(l.value, processed) @@ -314,31 +323,34 @@ local lua2typvalt_type_tab = { [list_type] = function(l, processed) if processed[l] then processed[l].lv_refcount = processed[l].lv_refcount + 1 - return typvalt(eval.VAR_LIST, {v_list=processed[l]}) + return typvalt(eval.VAR_LIST, { v_list = processed[l] }) end local lst = populate_list(eval.tv_list_alloc(#l), l, processed) - return typvalt(eval.VAR_LIST, {v_list=lst}) + 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]}) + return typvalt(eval.VAR_DICT, { v_dict = processed[l] }) end local dct = populate_dict(eval.tv_dict_alloc(), l, processed) - return typvalt(eval.VAR_DICT, {v_dict=dct}) + return typvalt(eval.VAR_DICT, { v_dict = dct }) end, [func_type] = function(l, processed) if processed[l] then processed[l].pt_refcount = processed[l].pt_refcount + 1 - return typvalt(eval.VAR_PARTIAL, {v_partial=processed[l]}) + return typvalt(eval.VAR_PARTIAL, { v_partial = processed[l] }) end if l.args or l.dict then - 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}) + 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, { - v_string=eval.xmemdupz(to_cstr(l.value), #l.value) + v_string = eval.xmemdupz(to_cstr(l.value), #l.value), }) end end, @@ -349,12 +361,12 @@ local special_vals = nil lua2typvalt = function(l, processed) if not special_vals then special_vals = { - [null_string] = {'VAR_STRING', {v_string=ffi.cast('char*', nil)}}, - [null_list] = {'VAR_LIST', {v_list=ffi.cast('list_T*', nil)}}, - [null_dict] = {'VAR_DICT', {v_dict=ffi.cast('dict_T*', nil)}}, - [nil_value] = {'VAR_SPECIAL', {v_special=eval.kSpecialVarNull}}, - [true] = {'VAR_BOOL', {v_bool=eval.kBoolVarTrue}}, - [false] = {'VAR_BOOL', {v_bool=eval.kBoolVarFalse}}, + [null_string] = { 'VAR_STRING', { v_string = ffi.cast('char*', nil) } }, + [null_list] = { 'VAR_LIST', { v_list = ffi.cast('list_T*', nil) } }, + [null_dict] = { 'VAR_DICT', { v_dict = ffi.cast('dict_T*', nil) } }, + [nil_value] = { 'VAR_SPECIAL', { v_special = eval.kSpecialVarNull } }, + [true] = { 'VAR_BOOL', { v_bool = eval.kBoolVarTrue } }, + [false] = { 'VAR_BOOL', { v_bool = eval.kBoolVarFalse } }, } for k, v in pairs(special_vals) do @@ -382,9 +394,9 @@ lua2typvalt = function(l, processed) end end elseif type(l) == 'number' then - return typvalt(eval.VAR_FLOAT, {v_float=l}) + return typvalt(eval.VAR_FLOAT, { v_float = l }) elseif type(l) == 'string' then - return typvalt(eval.VAR_STRING, {v_string=eval.xmemdupz(to_cstr(l), #l)}) + 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.tv_copy(l, tv) @@ -408,43 +420,64 @@ local function alloc_len(len, get_ptr) 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='calloc', args={1, ffi.sizeof('dict_T')}, ret=void(d)} end, + 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 = 'calloc', args = { 1, 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)} + 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) - size = alloc_len(size, function() return s end) - return {func='malloc', args={size + 1}, ret=void(s)} + size = alloc_len(size, function() + return s + end) + return { func = 'malloc', args = { size + 1 }, ret = void(s) } end, - dwatcher = function(w) return {func='malloc', args={ffi.sizeof('DictWatcher')}, ret=void(w)} 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, + 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_pt = function(pt) + return { func = 'calloc', args = { 1, ffi.sizeof('partial_T') }, ret = void(pt) } + end, lua_tvs = function(argv, argc) argc = alloc_len(argc) - return {func='malloc', args={ffi.sizeof('typval_T')*argc}, ret=void(argv)} + return { func = 'malloc', args = { ffi.sizeof('typval_T') * argc }, ret = void(argv) } end, } local function int(n) - return {[type_key]=int_type, value=n} + return { [type_key] = int_type, value = n } end local function list(...) - return populate_list(ffi.gc(eval.tv_list_alloc(select('#', ...)), - eval.tv_list_unref), - {...}, {}) + return populate_list( + ffi.gc(eval.tv_list_alloc(select('#', ...)), eval.tv_list_unref), + { ... }, + {} + ) end local function dict(d) - return populate_dict(ffi.gc(eval.tv_dict_alloc(), eval.tv_dict_free), - d or {}, {}) + return populate_dict(ffi.gc(eval.tv_dict_alloc(), eval.tv_dict_free), d or {}, {}) end local callback2tbl_type_tab = nil @@ -454,14 +487,16 @@ local function init_callback2tbl_type_tab() return end callback2tbl_type_tab = { - [tonumber(eval.kCallbackNone)] = function(_) return {type='none'} end, + [tonumber(eval.kCallbackNone)] = function(_) + return { type = 'none' } + end, [tonumber(eval.kCallbackFuncref)] = function(cb) - return {type='fref', fref=ffi.string(cb.data.funcref)} + 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 + return { type = 'pt', fref = ffi.string(lua_pt.value), pt = lua_pt } + end, } end @@ -473,15 +508,18 @@ end local function tbl2callback(tbl) local ret = nil if tbl.type == 'none' then - ret = ffi.new('Callback[1]', {{type=eval.kCallbackNone}}) + 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)}}}) + 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'))), nil) - ret = ffi.new('Callback[1]', {{type=eval.kCallbackPartial, - data={partial=populate_partial(pt, tbl.pt, {})}}}) + local pt = ffi.gc(ffi.cast('partial_T*', eval.xcalloc(1, ffi.sizeof('partial_T'))), nil) + ret = ffi.new( + 'Callback[1]', + { { type = eval.kCallbackPartial, data = { partial = populate_partial(pt, tbl.pt, {}) } } } + ) else assert(false) end @@ -495,24 +533,23 @@ local function dict_watchers(d) local qs = {} local key_patterns = {} while q ~= h do - local qitem = ffi.cast('DictWatcher *', - ffi.cast('char *', q) - ffi.offsetof('DictWatcher', 'node')) + 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, + 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} + key_patterns[#key_patterns + 1] = { qitem.key_pattern, qitem.key_pattern_len } q = q.next end 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) - local evalarg = ffi.new('evalarg_T', {eval_flags = eval.EVAL_EVALUATE}) + local tv = ffi.gc(ffi.new('typval_T', { v_type = eval.VAR_UNKNOWN }), eval.tv_clear) + local evalarg = ffi.new('evalarg_T', { eval_flags = eval.EVAL_EVALUATE }) if eval.eval0(to_cstr(expr), tv, nil, evalarg) == 0 then return nil else @@ -521,49 +558,49 @@ local function eval0(expr) end return { - int=int, + int = int, - null_string=null_string, - null_list=null_list, - null_dict=null_dict, - list_type=list_type, - dict_type=dict_type, - func_type=func_type, - int_type=int_type, - flt_type=flt_type, + null_string = null_string, + null_list = null_list, + null_dict = null_dict, + list_type = list_type, + dict_type = dict_type, + func_type = func_type, + int_type = int_type, + flt_type = flt_type, - nil_value=nil_value, + nil_value = nil_value, - type_key=type_key, - locks_key=locks_key, + type_key = type_key, + locks_key = locks_key, - list=list, - dict=dict, - lst2tbl=lst2tbl, - dct2tbl=dct2tbl, + list = list, + dict = dict, + lst2tbl = lst2tbl, + dct2tbl = dct2tbl, - lua2typvalt=lua2typvalt, - typvalt2lua=typvalt2lua, + lua2typvalt = lua2typvalt, + typvalt2lua = typvalt2lua, - typvalt=typvalt, + typvalt = typvalt, - li_alloc=li_alloc, - tv_list_item_free=tv_list_item_free, + li_alloc = li_alloc, + tv_list_item_free = tv_list_item_free, - dict_iter=dict_iter, - list_iter=list_iter, - first_di=first_di, + dict_iter = dict_iter, + list_iter = list_iter, + first_di = first_di, - alloc_logging_helpers=alloc_logging_helpers, + alloc_logging_helpers = alloc_logging_helpers, - list_items=list_items, - dict_items=dict_items, + list_items = list_items, + dict_items = dict_items, - dict_watchers=dict_watchers, - tbl2callback=tbl2callback, - callback2tbl=callback2tbl, + dict_watchers = dict_watchers, + tbl2callback = tbl2callback, + callback2tbl = callback2tbl, - eval0=eval0, + eval0 = eval0, - empty_list = {[type_key]=list_type}, + empty_list = { [type_key] = list_type }, } diff --git a/test/unit/eval/tricks_spec.lua b/test/unit/eval/tricks_spec.lua index 7aa0f0f6e6..ed26fd44e4 100644 --- a/test/unit/eval/tricks_spec.lua +++ b/test/unit/eval/tricks_spec.lua @@ -8,8 +8,7 @@ local eq = helpers.eq local eval0 = eval_helpers.eval0 -local eval = cimport('./src/nvim/eval.h', './src/nvim/eval/typval.h', - './src/nvim/memory.h') +local eval = cimport('./src/nvim/eval.h', './src/nvim/eval/typval.h', './src/nvim/memory.h') describe('NULL typval_T', function() itp('is produced by $XXX_UNEXISTENT_VAR_XXX', function() diff --git a/test/unit/eval/tv_clear_spec.lua b/test/unit/eval/tv_clear_spec.lua index ca37301b32..a34cf6082a 100644 --- a/test/unit/eval/tv_clear_spec.lua +++ b/test/unit/eval/tv_clear_spec.lua @@ -28,8 +28,8 @@ end) describe('tv_clear()', function() itp('successfully frees all lists in [&l [1], *l, *l]', function() - local l_inner = {1} - local list = {l_inner, l_inner, l_inner} + local l_inner = { 1 } + local list = { l_inner, l_inner, l_inner } local list_tv = ffi.gc(lua2typvalt(list), nil) local list_p = list_tv.vval.v_list local lis = list_items(list_p) @@ -55,8 +55,8 @@ describe('tv_clear()', function() }) end) itp('successfully frees all lists in [&l [], *l, *l]', function() - local l_inner = {[type_key]=list_type} - local list = {l_inner, l_inner, l_inner} + local l_inner = { [type_key] = list_type } + local list = { l_inner, l_inner, l_inner } local list_tv = ffi.gc(lua2typvalt(list), nil) local list_p = list_tv.vval.v_list local lis = list_items(list_p) @@ -80,7 +80,7 @@ describe('tv_clear()', function() end) itp('successfully frees all dictionaries in [&d {}, *d]', function() local d_inner = {} - local list = {d_inner, d_inner} + local list = { d_inner, d_inner } local list_tv = ffi.gc(lua2typvalt(list), nil) local list_p = list_tv.vval.v_list local lis = list_items(list_p) @@ -101,8 +101,8 @@ describe('tv_clear()', function() }) end) itp('successfully frees all dictionaries in [&d {a: 1}, *d]', function() - local d_inner = {a=1} - local list = {d_inner, d_inner} + local d_inner = { a = 1 } + local list = { d_inner, d_inner } local list_tv = ffi.gc(lua2typvalt(list), nil) local list_p = list_tv.vval.v_list local lis = list_items(list_p) diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 34a1299725..6edd164438 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -14,7 +14,7 @@ local cimport = helpers.cimport local to_cstr = helpers.to_cstr local alloc_log_new = helpers.alloc_log_new local concat_tables = helpers.concat_tables -local map = helpers.tbl_map +local map = vim.tbl_map local a = eval_helpers.alloc_logging_helpers local int = eval_helpers.int @@ -41,21 +41,25 @@ local callback2tbl = eval_helpers.callback2tbl local tbl2callback = eval_helpers.tbl2callback local dict_watchers = eval_helpers.dict_watchers -local lib = cimport('./src/nvim/eval/typval.h', './src/nvim/memory.h', - './src/nvim/mbyte.h', './src/nvim/garray.h', - './src/nvim/eval.h', './src/nvim/vim_defs.h', - './src/nvim/globals.h') +local lib = cimport( + './src/nvim/eval/typval.h', + './src/nvim/memory.h', + './src/nvim/mbyte.h', + './src/nvim/garray.h', + './src/nvim/eval.h', + './src/nvim/vim_defs.h', + './src/nvim/globals.h' +) local function vimconv_alloc() - return ffi.gc( - ffi.cast('vimconv_T*', lib.xcalloc(1, ffi.sizeof('vimconv_T'))), function(vc) - lib.convert_setup(vc, nil, nil) - lib.xfree(vc) - end) + return ffi.gc(ffi.cast('vimconv_T*', lib.xcalloc(1, ffi.sizeof('vimconv_T'))), function(vc) + lib.convert_setup(vc, nil, nil) + lib.xfree(vc) + end) end local function list_watch_alloc(li) - return ffi.cast('listwatch_T*', ffi.new('listwatch_T[1]', {{lw_item=li}})) + return ffi.cast('listwatch_T*', ffi.new('listwatch_T[1]', { { lw_item = li } })) end local function list_watch(l, li) @@ -66,12 +70,14 @@ end local function get_alloc_rets(exp_log, res) setmetatable(res, { - __index={ - freed=function(r, n) return {func='free', args={r[n]}} end - } + __index = { + freed = function(r, n) + return { func = 'free', args = { r[n] } } + end, + }, }) - for i = 1,#exp_log do - if ({malloc=true, calloc=true})[exp_log[i].func] then + for i = 1, #exp_log do + if ({ malloc = true, calloc = true })[exp_log[i].func] then res[#res + 1] = exp_log[i].ret end end @@ -89,8 +95,7 @@ after_each(function() end) local function ga_alloc(itemsize, growsize) - local ga = ffi.gc(ffi.cast('garray_T*', ffi.new('garray_T[1]', {})), - lib.ga_clear) + local ga = ffi.gc(ffi.cast('garray_T*', ffi.new('garray_T[1]', {})), lib.ga_clear) lib.ga_init(ga, itemsize or 1, growsize or 80) return ga end @@ -100,7 +105,7 @@ local function check_emsg(f, msg) if saved_last_msg_hist == nil then saved_last_msg_hist = nil end - local ret = {f()} + local ret = { f() } local last_msg = lib.last_msg_hist ~= nil and ffi.string(lib.last_msg_hist.msg) or nil if msg ~= nil then eq(msg, last_msg) @@ -167,8 +172,9 @@ describe('typval.c', function() a.str(lis[4].li_tv.vval.v_string, 1), a.li(lis[4]), }) - local strings = map(function(li) return li.li_tv.vval.v_string end, - lis) + local strings = map(function(li) + return li.li_tv.vval.v_string + end, lis) eq(lis[2], lib.tv_list_item_remove(l, lis[1])) alloc_log:check({ @@ -213,20 +219,26 @@ describe('typval.c', function() }) eq(lis[5], lib.tv_list_item_remove(l, lis[4])) - alloc_log:check({a.freed(lis[4])}) - eq({lis[1], lis[5], lis[7]}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item}) + alloc_log:check({ a.freed(lis[4]) }) + eq({ lis[1], lis[5], lis[7] }, { lws[1].lw_item, lws[2].lw_item, lws[3].lw_item }) eq(lis[3], lib.tv_list_item_remove(l, lis[2])) - alloc_log:check({a.freed(lis[2])}) - eq({lis[1], lis[5], lis[7]}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item}) + alloc_log:check({ a.freed(lis[2]) }) + eq({ lis[1], lis[5], lis[7] }, { lws[1].lw_item, lws[2].lw_item, lws[3].lw_item }) eq(nil, lib.tv_list_item_remove(l, lis[7])) - alloc_log:check({a.freed(lis[7])}) - eq({lis[1], lis[5], nil}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil}) + alloc_log:check({ a.freed(lis[7]) }) + eq( + { lis[1], lis[5], nil }, + { lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil } + ) eq(lis[3], lib.tv_list_item_remove(l, lis[1])) - alloc_log:check({a.freed(lis[1])}) - eq({lis[3], lis[5], nil}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil}) + alloc_log:check({ a.freed(lis[1]) }) + eq( + { lis[3], lis[5], nil }, + { lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil } + ) lib.tv_list_watch_remove(l, lws[2]) lib.tv_list_watch_remove(l, lws[3]) @@ -285,7 +297,7 @@ describe('typval.c', function() alloc_log:check(get_alloc_rets({ a.list(l1), a.li(l1.lv_first), - a.str(l1.lv_last.li_tv.vval.v_string, #('abc')), + a.str(l1.lv_last.li_tv.vval.v_string, #'abc'), a.li(l1.lv_last), a.list(l2), a.dict(l2.lv_first.li_tv.vval.v_dict), @@ -324,7 +336,7 @@ describe('typval.c', function() alloc_log:check(get_alloc_rets({ a.list(l1), a.li(l1.lv_first), - a.str(l1.lv_last.li_tv.vval.v_string, #('abc')), + a.str(l1.lv_last.li_tv.vval.v_string, #'abc'), a.li(l1.lv_last), a.list(l2), a.dict(l2.lv_first.li_tv.vval.v_dict), @@ -348,8 +360,7 @@ describe('typval.c', function() end) end) describe('free_contents()', function() - itp('recursively frees list, except for the list structure itself', - function() + itp('recursively frees list, except for the list structure itself', function() local l1 = ffi.gc(list(1, 'abc'), nil) local l2 = ffi.gc(list({}), nil) local l3 = ffi.gc(list(empty_list), nil) @@ -357,7 +368,7 @@ describe('typval.c', function() alloc_log:check(get_alloc_rets({ a.list(l1), a.li(l1.lv_first), - a.str(l1.lv_last.li_tv.vval.v_string, #('abc')), + a.str(l1.lv_last.li_tv.vval.v_string, #'abc'), a.li(l1.lv_last), a.list(l2), a.dict(l2.lv_first.li_tv.vval.v_dict), @@ -406,7 +417,7 @@ describe('typval.c', function() end) describe('drop_items()', function() itp('works', function() - local l_tv = lua2typvalt({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}) + local l_tv = lua2typvalt({ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }) local l = l_tv.vval.v_list local lis = list_items(l) -- Three watchers: pointing to first, middle and last elements. @@ -418,20 +429,29 @@ describe('typval.c', function() alloc_log:clear() lib.tv_list_drop_items(l, lis[1], lis[3]) - eq({4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, typvalt2lua(l_tv)) - eq({lis[4], lis[7], lis[13]}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item}) + eq({ 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }, typvalt2lua(l_tv)) + eq({ lis[4], lis[7], lis[13] }, { lws[1].lw_item, lws[2].lw_item, lws[3].lw_item }) lib.tv_list_drop_items(l, lis[11], lis[13]) - eq({4, 5, 6, 7, 8, 9, 10}, typvalt2lua(l_tv)) - eq({lis[4], lis[7], nil}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil}) + eq({ 4, 5, 6, 7, 8, 9, 10 }, typvalt2lua(l_tv)) + eq( + { lis[4], lis[7], nil }, + { lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil } + ) lib.tv_list_drop_items(l, lis[6], lis[8]) - eq({4, 5, 9, 10}, typvalt2lua(l_tv)) - eq({lis[4], lis[9], nil}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil}) + eq({ 4, 5, 9, 10 }, typvalt2lua(l_tv)) + eq( + { lis[4], lis[9], nil }, + { lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil } + ) lib.tv_list_drop_items(l, lis[4], lis[10]) eq(empty_list, typvalt2lua(l_tv)) - eq({true, true, true}, {lws[1].lw_item == nil, lws[2].lw_item == nil, lws[3].lw_item == nil}) + eq( + { true, true, true }, + { lws[1].lw_item == nil, lws[2].lw_item == nil, lws[3].lw_item == nil } + ) lib.tv_list_watch_remove(l, lws[1]) lib.tv_list_watch_remove(l, lws[2]) @@ -442,10 +462,13 @@ describe('typval.c', function() end) describe('remove_items()', function() itp('works', function() - local l_tv = lua2typvalt({'1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13'}) + local l_tv = + lua2typvalt({ '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13' }) local l = l_tv.vval.v_list local lis = list_items(l) - local strings = map(function(li) return li.li_tv.vval.v_string end, lis) + local strings = map(function(li) + return li.li_tv.vval.v_string + end, lis) -- Three watchers: pointing to first, middle and last elements. local lws = { list_watch(l, lis[1]), @@ -455,8 +478,8 @@ describe('typval.c', function() alloc_log:clear() lib.tv_list_remove_items(l, lis[1], lis[3]) - eq({'4', '5', '6', '7', '8', '9', '10', '11', '12', '13'}, typvalt2lua(l_tv)) - eq({lis[4], lis[7], lis[13]}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item}) + eq({ '4', '5', '6', '7', '8', '9', '10', '11', '12', '13' }, typvalt2lua(l_tv)) + eq({ lis[4], lis[7], lis[13] }, { lws[1].lw_item, lws[2].lw_item, lws[3].lw_item }) alloc_log:check({ a.freed(strings[1]), a.freed(lis[1]), @@ -467,8 +490,11 @@ describe('typval.c', function() }) lib.tv_list_remove_items(l, lis[11], lis[13]) - eq({'4', '5', '6', '7', '8', '9', '10'}, typvalt2lua(l_tv)) - eq({lis[4], lis[7], nil}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil}) + eq({ '4', '5', '6', '7', '8', '9', '10' }, typvalt2lua(l_tv)) + eq( + { lis[4], lis[7], nil }, + { lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil } + ) alloc_log:check({ a.freed(strings[11]), a.freed(lis[11]), @@ -479,8 +505,11 @@ describe('typval.c', function() }) lib.tv_list_remove_items(l, lis[6], lis[8]) - eq({'4', '5', '9', '10'}, typvalt2lua(l_tv)) - eq({lis[4], lis[9], nil}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil}) + eq({ '4', '5', '9', '10' }, typvalt2lua(l_tv)) + eq( + { lis[4], lis[9], nil }, + { lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil } + ) alloc_log:check({ a.freed(strings[6]), a.freed(lis[6]), @@ -492,7 +521,10 @@ describe('typval.c', function() lib.tv_list_remove_items(l, lis[4], lis[10]) eq(empty_list, typvalt2lua(l_tv)) - eq({true, true, true}, {lws[1].lw_item == nil, lws[2].lw_item == nil, lws[3].lw_item == nil}) + eq( + { true, true, true }, + { lws[1].lw_item == nil, lws[2].lw_item == nil, lws[3].lw_item == nil } + ) alloc_log:check({ a.freed(strings[4]), a.freed(lis[4]), @@ -514,28 +546,28 @@ describe('typval.c', function() describe('insert', function() describe('()', function() itp('works', function() - local l_tv = lua2typvalt({1, 2, 3, 4, 5, 6, 7}) + local l_tv = lua2typvalt({ 1, 2, 3, 4, 5, 6, 7 }) local l = l_tv.vval.v_list local lis = list_items(l) local li li = li_alloc(true) - li.li_tv = {v_type=lib.VAR_FLOAT, vval={v_float=100500}} + li.li_tv = { v_type = lib.VAR_FLOAT, vval = { v_float = 100500 } } lib.tv_list_insert(l, li, nil) eq(l.lv_last, li) - eq({1, 2, 3, 4, 5, 6, 7, 100500}, typvalt2lua(l_tv)) + eq({ 1, 2, 3, 4, 5, 6, 7, 100500 }, typvalt2lua(l_tv)) li = li_alloc(true) - li.li_tv = {v_type=lib.VAR_FLOAT, vval={v_float=0}} + li.li_tv = { v_type = lib.VAR_FLOAT, vval = { v_float = 0 } } lib.tv_list_insert(l, li, lis[1]) eq(l.lv_first, li) - eq({0, 1, 2, 3, 4, 5, 6, 7, 100500}, typvalt2lua(l_tv)) + eq({ 0, 1, 2, 3, 4, 5, 6, 7, 100500 }, typvalt2lua(l_tv)) li = li_alloc(true) - li.li_tv = {v_type=lib.VAR_FLOAT, vval={v_float=4.5}} + li.li_tv = { v_type = lib.VAR_FLOAT, vval = { v_float = 4.5 } } lib.tv_list_insert(l, li, lis[5]) eq(list_items(l)[6], li) - eq({0, 1, 2, 3, 4, 4.5, 5, 6, 7, 100500}, typvalt2lua(l_tv)) + eq({ 0, 1, 2, 3, 4, 4.5, 5, 6, 7, 100500 }, typvalt2lua(l_tv)) end) itp('works with an empty list', function() local l_tv = lua2typvalt(empty_list) @@ -545,10 +577,10 @@ describe('typval.c', function() eq(nil, l.lv_last) local li = li_alloc(true) - li.li_tv = {v_type=lib.VAR_FLOAT, vval={v_float=100500}} + li.li_tv = { v_type = lib.VAR_FLOAT, vval = { v_float = 100500 } } lib.tv_list_insert(l, li, nil) eq(l.lv_last, li) - eq({100500}, typvalt2lua(l_tv)) + eq({ 100500 }, typvalt2lua(l_tv)) end) end) describe('tv()', function() @@ -577,7 +609,7 @@ describe('typval.c', function() a.str(l.lv_first.li_tv.vval.v_string, 'test'), }) - eq({'test', empty_list}, typvalt2lua(l_tv)) + eq({ 'test', empty_list }, typvalt2lua(l_tv)) end) end) end) @@ -602,7 +634,7 @@ describe('typval.c', function() a.li(l.lv_last), }) - eq({{1}, null_list}, typvalt2lua(l_tv)) + eq({ { 1 }, null_list }, typvalt2lua(l_tv)) end) end) describe('dict()', function() @@ -610,7 +642,7 @@ describe('typval.c', function() local l_tv = lua2typvalt(empty_list) local l = l_tv.vval.v_list - local l_d_tv = lua2typvalt({test=1}) + local l_d_tv = lua2typvalt({ test = 1 }) local l_d = l_d_tv.vval.v_dict alloc_log:clear() eq(1, l_d.dv_refcount) @@ -626,7 +658,7 @@ describe('typval.c', function() a.li(l.lv_last), }) - eq({{test=1}, null_dict}, typvalt2lua(l_tv)) + eq({ { test = 1 }, null_dict }, typvalt2lua(l_tv)) end) end) describe('string()', function() @@ -657,7 +689,7 @@ describe('typval.c', function() a.li(l.lv_last), }) - eq({'tes', null_string, null_string, 'test'}, typvalt2lua(l_tv)) + eq({ 'tes', null_string, null_string, 'test' }, typvalt2lua(l_tv)) end) end) describe('allocated string()', function() @@ -682,7 +714,7 @@ describe('typval.c', function() a.li(l.lv_last), }) - eq({'test', null_string, null_string}, typvalt2lua(l_tv)) + eq({ 'test', null_string, null_string }, typvalt2lua(l_tv)) end) end) describe('number()', function() @@ -701,7 +733,7 @@ describe('typval.c', function() a.li(l.lv_last), }) - eq({int(-100500), int(100500)}, typvalt2lua(l_tv)) + eq({ int(-100500), int(100500) }, typvalt2lua(l_tv)) end) end) describe('tv()', function() @@ -730,7 +762,7 @@ describe('typval.c', function() a.str(l.lv_last.li_tv.vval.v_string, 'test'), }) - eq({empty_list, 'test'}, typvalt2lua(l_tv)) + eq({ empty_list, 'test' }, typvalt2lua(l_tv)) end) end) describe('owned tv()', function() @@ -761,7 +793,7 @@ describe('typval.c', function() a.li(l.lv_last), }) - eq({empty_list, 'test'}, typvalt2lua(l_tv)) + eq({ empty_list, 'test' }, typvalt2lua(l_tv)) end) end) end) @@ -777,7 +809,7 @@ describe('typval.c', function() end) itp('copies list correctly without converting items', function() do - local v = {{['«']='»'}, {'„'}, 1, '“', null_string, null_list, null_dict} + local v = { { ['«'] = '»' }, { '„' }, 1, '“', null_string, null_list, null_dict } local l_tv = lua2typvalt(v) local l = l_tv.vval.v_list local lis = list_items(l) @@ -821,7 +853,7 @@ describe('typval.c', function() a.list(l_deepcopy1), a.li(lis_deepcopy1[1]), a.dict(lis_deepcopy1[1].li_tv.vval.v_dict), - a.di(di_deepcopy1, #('«')), + a.di(di_deepcopy1, #'«'), a.str(di_deepcopy1.di_tv.vval.v_string, #v[1]['«']), a.li(lis_deepcopy1[2]), a.list(lis_deepcopy1[2].li_tv.vval.v_list), @@ -842,7 +874,7 @@ describe('typval.c', function() -- UTF-8 ↔ latin1 conversions needs no iconv eq(OK, lib.convert_setup(vc, to_cstr('utf-8'), to_cstr('latin1'))) - local v = {{['«']='»'}, {'„'}, 1, '“', null_string, null_list, null_dict} + local v = { { ['«'] = '»' }, { '„' }, 1, '“', null_string, null_list, null_dict } local l_tv = lua2typvalt(v) local l = l_tv.vval.v_list local lis = list_items(l) @@ -857,8 +889,10 @@ describe('typval.c', function() local lis_deepcopy1 = list_items(l_deepcopy1) neq(lis[1].li_tv.vval.v_dict, lis_deepcopy1[1].li_tv.vval.v_dict) neq(lis[2].li_tv.vval.v_list, lis_deepcopy1[2].li_tv.vval.v_list) - eq({{['\171']='\187'}, {'\191'}, 1, '\191', null_string, null_list, null_dict}, - lst2tbl(l_deepcopy1)) + eq( + { { ['\171'] = '\187' }, { '\191' }, 1, '\191', null_string, null_list, null_dict }, + lst2tbl(l_deepcopy1) + ) local di_deepcopy1 = first_di(lis_deepcopy1[1].li_tv.vval.v_dict) alloc_log:clear_tmp_allocs() alloc_log:check({ @@ -881,18 +915,18 @@ describe('typval.c', function() end) itp('returns different/same containers with(out) copyID', function() local l_inner_tv = lua2typvalt(empty_list) - local l_tv = lua2typvalt({l_inner_tv, l_inner_tv}) + local l_tv = lua2typvalt({ l_inner_tv, l_inner_tv }) eq(3, l_inner_tv.vval.v_list.lv_refcount) local l = l_tv.vval.v_list eq(l.lv_first.li_tv.vval.v_list, l.lv_last.li_tv.vval.v_list) local l_copy1 = tv_list_copy(nil, l, true, 0) neq(l_copy1.lv_first.li_tv.vval.v_list, l_copy1.lv_last.li_tv.vval.v_list) - eq({empty_list, empty_list}, lst2tbl(l_copy1)) + eq({ empty_list, empty_list }, lst2tbl(l_copy1)) local l_copy2 = tv_list_copy(nil, l, true, 2) eq(l_copy2.lv_first.li_tv.vval.v_list, l_copy2.lv_last.li_tv.vval.v_list) - eq({empty_list, empty_list}, lst2tbl(l_copy2)) + eq({ empty_list, empty_list }, lst2tbl(l_copy2)) eq(3, l_inner_tv.vval.v_list.lv_refcount) end) @@ -934,7 +968,7 @@ describe('typval.c', function() }) eq(1, l.lv_refcount) eq(2, l.lv_last.li_tv.vval.v_dict.dv_refcount) - eq({1, {}, 1, {}}, lst2tbl(l)) + eq({ 1, {}, 1, {} }, lst2tbl(l)) l = list(1, {}) alloc_log:clear() @@ -946,7 +980,7 @@ describe('typval.c', function() a.li(l.lv_last.li_prev.li_prev), a.li(l.lv_last.li_prev), }) - eq({1, 1, {}, {}}, lst2tbl(l)) + eq({ 1, 1, {}, {} }, lst2tbl(l)) eq(1, l.lv_refcount) eq(2, l.lv_last.li_tv.vval.v_dict.dv_refcount) @@ -960,7 +994,7 @@ describe('typval.c', function() a.li(l.lv_first), a.li(l.lv_first.li_next), }) - eq({1, {}, 1, {}}, lst2tbl(l)) + eq({ 1, {}, 1, {} }, lst2tbl(l)) eq(1, l.lv_refcount) eq(2, l.lv_last.li_tv.vval.v_dict.dv_refcount) end) @@ -973,28 +1007,25 @@ describe('typval.c', function() eq(1, el.lv_refcount) lib.tv_list_extend(l, el, nil) - alloc_log:check({ - }) + alloc_log:check({}) eq(1, l.lv_refcount) eq(1, l.lv_last.li_tv.vval.v_dict.dv_refcount) eq(1, el.lv_refcount) - eq({1, {}}, lst2tbl(l)) + eq({ 1, {} }, lst2tbl(l)) lib.tv_list_extend(l, el, l.lv_first) - alloc_log:check({ - }) + alloc_log:check({}) eq(1, l.lv_refcount) eq(1, l.lv_last.li_tv.vval.v_dict.dv_refcount) eq(1, el.lv_refcount) - eq({1, {}}, lst2tbl(l)) + eq({ 1, {} }, lst2tbl(l)) lib.tv_list_extend(l, el, l.lv_last) - alloc_log:check({ - }) + alloc_log:check({}) eq(1, l.lv_refcount) eq(1, l.lv_last.li_tv.vval.v_dict.dv_refcount) eq(1, el.lv_refcount) - eq({1, {}}, lst2tbl(l)) + eq({ 1, {} }, lst2tbl(l)) end) itp('can extend list with another non-empty list', function() local l @@ -1014,7 +1045,7 @@ describe('typval.c', function() }) eq(1, l2.lv_refcount) eq(2, l2.lv_last.li_tv.vval.v_list.lv_refcount) - eq({1, {}, 42, empty_list}, lst2tbl(l)) + eq({ 1, {}, 42, empty_list }, lst2tbl(l)) lib.tv_list_free(l) eq(1, l2.lv_last.li_tv.vval.v_list.lv_refcount) @@ -1030,7 +1061,7 @@ describe('typval.c', function() }) eq(1, l2.lv_refcount) eq(2, l2.lv_last.li_tv.vval.v_list.lv_refcount) - eq({42, empty_list, 1, {}}, lst2tbl(l)) + eq({ 42, empty_list, 1, {} }, lst2tbl(l)) lib.tv_list_free(l) eq(1, l2.lv_last.li_tv.vval.v_list.lv_refcount) @@ -1046,7 +1077,7 @@ describe('typval.c', function() }) eq(1, l2.lv_refcount) eq(2, l2.lv_last.li_tv.vval.v_list.lv_refcount) - eq({1, 42, empty_list, {}}, lst2tbl(l)) + eq({ 1, 42, empty_list, {} }, lst2tbl(l)) lib.tv_list_free(l) eq(1, l2.lv_last.li_tv.vval.v_list.lv_refcount) end) @@ -1062,7 +1093,7 @@ describe('typval.c', function() eq(OK, lib.tv_list_concat(nil, l, rettv1)) eq(1, l.lv_refcount) eq(tonumber(lib.VAR_LIST), tonumber(rettv1.v_type)) - eq({1, {}}, typvalt2lua(rettv1)) + eq({ 1, {} }, typvalt2lua(rettv1)) eq(1, rettv1.vval.v_list.lv_refcount) alloc_log:check({ a.list(rettv1.vval.v_list), @@ -1075,7 +1106,7 @@ describe('typval.c', function() eq(OK, lib.tv_list_concat(l, nil, rettv2)) eq(1, l.lv_refcount) eq(tonumber(lib.VAR_LIST), tonumber(rettv2.v_type)) - eq({1, {}}, typvalt2lua(rettv2)) + eq({ 1, {} }, typvalt2lua(rettv2)) eq(1, rettv2.vval.v_list.lv_refcount) alloc_log:check({ a.list(rettv2.vval.v_list), @@ -1112,7 +1143,7 @@ describe('typval.c', function() a.li(rettv.vval.v_list.lv_last.li_prev), a.li(rettv.vval.v_list.lv_last), }) - eq({1, {}, 3, empty_list}, typvalt2lua(rettv)) + eq({ 1, {}, 3, empty_list }, typvalt2lua(rettv)) end) itp('can concatenate list with itself', function() local l = list(1, {}) @@ -1131,7 +1162,7 @@ describe('typval.c', function() a.li(rettv.vval.v_list.lv_last.li_prev), a.li(rettv.vval.v_list.lv_last), }) - eq({1, {}, 1, {}}, typvalt2lua(rettv)) + eq({ 1, {}, 1, {} }, typvalt2lua(rettv)) end) itp('can concatenate empty non-NULL lists', function() local l = list(1, {}) @@ -1154,7 +1185,7 @@ describe('typval.c', function() a.li(rettv1.vval.v_list.lv_first), a.li(rettv1.vval.v_list.lv_last), }) - eq({1, {}}, typvalt2lua(rettv1)) + eq({ 1, {} }, typvalt2lua(rettv1)) local rettv2 = typvalt() eq(OK, lib.tv_list_concat(le, l, rettv2)) @@ -1167,7 +1198,7 @@ describe('typval.c', function() a.li(rettv2.vval.v_list.lv_first), a.li(rettv2.vval.v_list.lv_last), }) - eq({1, {}}, typvalt2lua(rettv2)) + eq({ 1, {} }, typvalt2lua(rettv2)) local rettv3 = typvalt() eq(OK, lib.tv_list_concat(le, le, rettv3)) @@ -1257,15 +1288,15 @@ describe('typval.c', function() -- indicates that tv_equal_recurse_limit and recursive_cnt were set which -- is essential. This argument will be set when comparing inner lists. itp('compares lists correctly when case is not ignored', function() - local l1 = list('abc', {1, 2, 'Abc'}, 'def') - local l2 = list('abc', {1, 2, 'Abc'}) - local l3 = list('abc', {1, 2, 'Abc'}, 'Def') - local l4 = list('abc', {1, 2, 'Abc', 4}, 'def') - local l5 = list('Abc', {1, 2, 'Abc'}, 'def') - local l6 = list('abc', {1, 2, 'Abc'}, 'def') - local l7 = list('abc', {1, 2, 'abc'}, 'def') + local l1 = list('abc', { 1, 2, 'Abc' }, 'def') + local l2 = list('abc', { 1, 2, 'Abc' }) + local l3 = list('abc', { 1, 2, 'Abc' }, 'Def') + local l4 = list('abc', { 1, 2, 'Abc', 4 }, 'def') + local l5 = list('Abc', { 1, 2, 'Abc' }, 'def') + local l6 = list('abc', { 1, 2, 'Abc' }, 'def') + local l7 = list('abc', { 1, 2, 'abc' }, 'def') local l8 = list('abc', nil, 'def') - local l9 = list('abc', {1, 2, nil}, 'def') + local l9 = list('abc', { 1, 2, nil }, 'def') eq(true, lib.tv_list_equal(l1, l1, false, false)) eq(false, lib.tv_list_equal(l1, l2, false, false)) @@ -1278,15 +1309,15 @@ describe('typval.c', function() eq(false, lib.tv_list_equal(l1, l9, false, false)) end) itp('compares lists correctly when case is ignored', function() - local l1 = list('abc', {1, 2, 'Abc'}, 'def') - local l2 = list('abc', {1, 2, 'Abc'}) - local l3 = list('abc', {1, 2, 'Abc'}, 'Def') - local l4 = list('abc', {1, 2, 'Abc', 4}, 'def') - local l5 = list('Abc', {1, 2, 'Abc'}, 'def') - local l6 = list('abc', {1, 2, 'Abc'}, 'def') - local l7 = list('abc', {1, 2, 'abc'}, 'def') + local l1 = list('abc', { 1, 2, 'Abc' }, 'def') + local l2 = list('abc', { 1, 2, 'Abc' }) + local l3 = list('abc', { 1, 2, 'Abc' }, 'Def') + local l4 = list('abc', { 1, 2, 'Abc', 4 }, 'def') + local l5 = list('Abc', { 1, 2, 'Abc' }, 'def') + local l6 = list('abc', { 1, 2, 'Abc' }, 'def') + local l7 = list('abc', { 1, 2, 'abc' }, 'def') local l8 = list('abc', nil, 'def') - local l9 = list('abc', {1, 2, nil}, 'def') + local l9 = list('abc', { 1, 2, nil }, 'def') eq(true, lib.tv_list_equal(l1, l1, true, false)) eq(false, lib.tv_list_equal(l1, l2, true, false)) @@ -1355,7 +1386,7 @@ describe('typval.c', function() describe('nr()', function() local function tv_list_find_nr(l, n, msg) return check_emsg(function() - local err = ffi.new('bool[1]', {false}) + local err = ffi.new('bool[1]', { false }) local ret = lib.tv_list_find_nr(l, n, err) return (err[0] == true), ret end, msg) @@ -1364,10 +1395,10 @@ describe('typval.c', function() local l = list(int(1), int(2), int(3), int(4), int(5)) alloc_log:clear() - eq({false, 1}, {tv_list_find_nr(l, -5)}) - eq({false, 5}, {tv_list_find_nr(l, 4)}) - eq({false, 3}, {tv_list_find_nr(l, 2)}) - eq({false, 3}, {tv_list_find_nr(l, -3)}) + eq({ false, 1 }, { tv_list_find_nr(l, -5) }) + eq({ false, 5 }, { tv_list_find_nr(l, 4) }) + eq({ false, 3 }, { tv_list_find_nr(l, 2) }) + eq({ false, 3 }, { tv_list_find_nr(l, -3) }) alloc_log:check({}) end) @@ -1375,10 +1406,10 @@ describe('typval.c', function() local l = list('1', '2', '3', '4', '5') alloc_log:clear() - eq({false, 1}, {tv_list_find_nr(l, -5)}) - eq({false, 5}, {tv_list_find_nr(l, 4)}) - eq({false, 3}, {tv_list_find_nr(l, 2)}) - eq({false, 3}, {tv_list_find_nr(l, -3)}) + eq({ false, 1 }, { tv_list_find_nr(l, -5) }) + eq({ false, 5 }, { tv_list_find_nr(l, 4) }) + eq({ false, 3 }, { tv_list_find_nr(l, 2) }) + eq({ false, 3 }, { tv_list_find_nr(l, -3) }) alloc_log:check({}) end) @@ -1386,15 +1417,15 @@ describe('typval.c', function() local l = list(null_string) alloc_log:clear() - eq({false, 0}, {tv_list_find_nr(l, 0)}) + eq({ false, 0 }, { tv_list_find_nr(l, 0) }) alloc_log:check({}) end) itp('errors out on NULL lists', function() - eq({true, -1}, {tv_list_find_nr(nil, -5)}) - eq({true, -1}, {tv_list_find_nr(nil, 4)}) - eq({true, -1}, {tv_list_find_nr(nil, 2)}) - eq({true, -1}, {tv_list_find_nr(nil, -3)}) + eq({ true, -1 }, { tv_list_find_nr(nil, -5) }) + eq({ true, -1 }, { tv_list_find_nr(nil, 4) }) + eq({ true, -1 }, { tv_list_find_nr(nil, 2) }) + eq({ true, -1 }, { tv_list_find_nr(nil, -3) }) alloc_log:check({}) end) @@ -1402,20 +1433,20 @@ describe('typval.c', function() local l = list(int(1), int(2), int(3), int(4), int(5)) alloc_log:clear() - eq({true, -1}, {tv_list_find_nr(l, -6)}) - eq({true, -1}, {tv_list_find_nr(l, 5)}) + eq({ true, -1 }, { tv_list_find_nr(l, -6) }) + eq({ true, -1 }, { tv_list_find_nr(l, 5) }) alloc_log:check({}) end) itp('errors out on invalid types', function() local l = list(1, empty_list, {}) - eq({true, 0}, {tv_list_find_nr(l, 0, 'E805: Using a Float as a Number')}) - eq({true, 0}, {tv_list_find_nr(l, 1, 'E745: Using a List as a Number')}) - eq({true, 0}, {tv_list_find_nr(l, 2, 'E728: Using a Dictionary as a Number')}) - eq({true, 0}, {tv_list_find_nr(l, -1, 'E728: Using a Dictionary as a Number')}) - eq({true, 0}, {tv_list_find_nr(l, -2, 'E745: Using a List as a Number')}) - eq({true, 0}, {tv_list_find_nr(l, -3, 'E805: Using a Float as a Number')}) + eq({ true, 0 }, { tv_list_find_nr(l, 0, 'E805: Using a Float as a Number') }) + eq({ true, 0 }, { tv_list_find_nr(l, 1, 'E745: Using a List as a Number') }) + eq({ true, 0 }, { tv_list_find_nr(l, 2, 'E728: Using a Dictionary as a Number') }) + eq({ true, 0 }, { tv_list_find_nr(l, -1, 'E728: Using a Dictionary as a Number') }) + eq({ true, 0 }, { tv_list_find_nr(l, -2, 'E745: Using a List as a Number') }) + eq({ true, 0 }, { tv_list_find_nr(l, -3, 'E805: Using a Float as a Number') }) end) end) local function tv_list_find_str(l, n, msg) @@ -1439,7 +1470,7 @@ describe('typval.c', function() eq('3', tv_list_find_str(l, 2)) eq('3', tv_list_find_str(l, -3)) - alloc_log:check({a.freed(alloc_log.null), a.freed(alloc_log.null)}) + alloc_log:check({ a.freed(alloc_log.null), a.freed(alloc_log.null) }) end) itp('returns string when used with VAR_STRING items', function() local l = list('1', '2', '3', '4', '5') @@ -1499,7 +1530,7 @@ describe('typval.c', function() itp('works with an empty key', function() local d = dict({}) eq({}, dict_watchers(d)) - local cb = ffi.gc(tbl2callback({type='none'}), nil) + local cb = ffi.gc(tbl2callback({ type = 'none' }), nil) alloc_log:clear() lib.tv_dict_watcher_add(d, '*', 0, cb[0]) local ws, qs = dict_watchers(d) @@ -1508,7 +1539,7 @@ describe('typval.c', function() a.dwatcher(qs[1]), a.str(key_p, 0), }) - eq({{busy=false, cb={type='none'}, pat=''}}, ws) + eq({ { busy = false, cb = { type = 'none' }, pat = '' } }, ws) eq(true, lib.tv_dict_watcher_remove(d, 'x', 0, cb[0])) alloc_log:check({ a.freed(key_p), @@ -1519,19 +1550,29 @@ describe('typval.c', function() itp('works with multiple callbacks', function() local d = dict({}) eq({}, dict_watchers(d)) - alloc_log:check({a.dict(d)}) + alloc_log:check({ a.dict(d) }) local cbs = {} - cbs[1] = {'te', ffi.gc(tbl2callback({type='none'}), nil)} + cbs[1] = { 'te', ffi.gc(tbl2callback({ type = 'none' }), nil) } alloc_log:check({}) - cbs[2] = {'foo', ffi.gc(tbl2callback({type='fref', fref='tr'}), nil)} + cbs[2] = { 'foo', ffi.gc(tbl2callback({ type = 'fref', fref = 'tr' }), nil) } alloc_log:check({ - a.str(cbs[2][2].data.funcref, #('tr')), + a.str(cbs[2][2].data.funcref, #'tr'), }) - cbs[3] = {'te', ffi.gc(tbl2callback({type='pt', fref='tr', pt={ - value='tr', - args={'test'}, - dict={}, - }}), nil)} + cbs[3] = { + 'te', + ffi.gc( + tbl2callback({ + type = 'pt', + fref = 'tr', + pt = { + value = 'tr', + args = { 'test' }, + dict = {}, + }, + }), + nil + ), + } local pt3 = cbs[3][2].data.partial local pt3_argv = pt3.pt_argv local pt3_dict = pt3.pt_dict @@ -1540,22 +1581,32 @@ describe('typval.c', function() alloc_log:check({ a.lua_pt(pt3), a.lua_tvs(pt3_argv, pt3.pt_argc), - a.str(pt3_str_arg, #('test')), + a.str(pt3_str_arg, #'test'), a.dict(pt3_dict), - a.str(pt3_name, #('tr')), + a.str(pt3_name, #'tr'), }) for _, v in ipairs(cbs) do - lib.tv_dict_watcher_add(d, v[1], #(v[1]), v[2][0]) + lib.tv_dict_watcher_add(d, v[1], #v[1], v[2][0]) end local ws, qs, kps = dict_watchers(d) - eq({{busy=false, pat=cbs[1][1], cb={type='none'}}, - {busy=false, pat=cbs[2][1], cb={type='fref', fref='tr'}}, - {busy=false, pat=cbs[3][1], cb={type='pt', fref='tr', pt={ - [type_key]=func_type, - value='tr', - args={'test'}, - dict={}, - }}}}, ws) + eq({ + { busy = false, pat = cbs[1][1], cb = { type = 'none' } }, + { busy = false, pat = cbs[2][1], cb = { type = 'fref', fref = 'tr' } }, + { + busy = false, + pat = cbs[3][1], + cb = { + type = 'pt', + fref = 'tr', + pt = { + [type_key] = func_type, + value = 'tr', + args = { 'test' }, + dict = {}, + }, + }, + }, + }, ws) alloc_log:check({ a.dwatcher(qs[1]), a.str(kps[1][1], kps[1][2]), @@ -1571,13 +1622,23 @@ describe('typval.c', function() a.freed(qs[2]), }) eq(false, lib.tv_dict_watcher_remove(d, cbs[2][1], #cbs[2][1], cbs[2][2][0])) - eq({{busy=false, pat=cbs[1][1], cb={type='none'}}, - {busy=false, pat=cbs[3][1], cb={type='pt', fref='tr', pt={ - [type_key]=func_type, - value='tr', - args={'test'}, - dict={}, - }}}}, dict_watchers(d)) + eq({ + { busy = false, pat = cbs[1][1], cb = { type = 'none' } }, + { + busy = false, + pat = cbs[3][1], + cb = { + type = 'pt', + fref = 'tr', + pt = { + [type_key] = func_type, + value = 'tr', + args = { 'test' }, + dict = {}, + }, + }, + }, + }, dict_watchers(d)) eq(true, lib.tv_dict_watcher_remove(d, cbs[3][1], #cbs[3][1], cbs[3][2][0])) alloc_log:check({ a.freed(pt3_str_arg), @@ -1589,7 +1650,7 @@ describe('typval.c', function() a.freed(qs[3]), }) eq(false, lib.tv_dict_watcher_remove(d, cbs[3][1], #cbs[3][1], cbs[3][2][0])) - eq({{busy=false, pat=cbs[1][1], cb={type='none'}}}, dict_watchers(d)) + eq({ { busy = false, pat = cbs[1][1], cb = { type = 'none' } } }, dict_watchers(d)) eq(true, lib.tv_dict_watcher_remove(d, cbs[1][1], #cbs[1][1], cbs[1][2][0])) alloc_log:check({ a.freed(kps[1][1]), @@ -1615,14 +1676,14 @@ describe('typval.c', function() 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)}) + alloc_log:check({ a.di(di, len) }) if tv then di.di_tv = ffi.gc(tv, nil) 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)})) + 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) @@ -1634,26 +1695,30 @@ describe('typval.c', function() 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)}) + 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)}) + 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) describe('add()/remove()', function() itp('works', function() local d = dict() eq({}, dct2tbl(d)) - alloc_log:check({a.dict(d)}) + alloc_log:check({ a.dict(d) }) local di = ffi.gc(lib.tv_dict_item_alloc(''), nil) local tv = lua2typvalt('test') di.di_tv = ffi.gc(tv, nil) - alloc_log:check({a.di(di, ''), a.str(tv.vval.v_string, 'test')}) + 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(): duplicate key ""')) + eq( + FAIL, + check_emsg(function() + return lib.tv_dict_add(d, di) + end, 'E685: Internal error: hash_add(): duplicate key ""') + ) alloc_log:clear() lib.tv_dict_item_remove(d, di) alloc_log:check({ @@ -1679,28 +1744,28 @@ describe('typval.c', function() end) itp('works with empty key', function() local lua_d = { - ['']=0, - t=1, - te=2, - tes=3, - test=4, - testt=5, + [''] = 0, + t = 1, + te = 2, + tes = 3, + test = 4, + testt = 5, } local d = dict(lua_d) alloc_log:clear() eq(lua_d, dct2tbl(d)) alloc_log:check({}) local dis = dict_items(d) - eq({0, '', dis['']}, {tv_dict_find(d, '', 0)}) + eq({ 0, '', dis[''] }, { tv_dict_find(d, '', 0) }) end) itp('works with len properly', function() local lua_d = { - ['']=0, - t=1, - te=2, - tes=3, - test=4, - testt=5, + [''] = 0, + t = 1, + te = 2, + tes = 3, + test = 4, + testt = 5, } local d = dict(lua_d) alloc_log:clear() @@ -1708,80 +1773,125 @@ describe('typval.c', function() alloc_log:check({}) for i = 0, 5 do local v, k = tv_dict_find(d, 'testt', i) - eq({i, ('testt'):sub(1, i)}, {v, k}) + eq({ i, ('testt'):sub(1, i) }, { v, k }) end - eq(nil, tv_dict_find(d, 'testt', 6)) -- Should take NUL byte + eq(nil, tv_dict_find(d, 'testt', 6)) -- Should take NUL byte eq(5, tv_dict_find(d, 'testt', -1)) alloc_log:check({}) end) end) describe('get_number()', function() itp('works with NULL dict', function() - eq(0, check_emsg(function() return lib.tv_dict_get_number(nil, 'test') end, - nil)) + eq( + 0, + check_emsg(function() + return lib.tv_dict_get_number(nil, 'test') + end, nil) + ) end) itp('works', function() - local d = ffi.gc(dict({test={}}), nil) - eq(0, check_emsg(function() return lib.tv_dict_get_number(d, 'test') end, - 'E728: Using a Dictionary as a Number')) - d = ffi.gc(dict({tes=int(42), t=44, te='43'}), nil) + local d = ffi.gc(dict({ test = {} }), nil) + eq( + 0, + check_emsg(function() + return lib.tv_dict_get_number(d, 'test') + end, 'E728: Using a Dictionary as a Number') + ) + d = ffi.gc(dict({ tes = int(42), t = 44, te = '43' }), nil) alloc_log:clear() - eq(0, check_emsg(function() return lib.tv_dict_get_number(d, 'test') end, - nil)) - eq(42, check_emsg(function() return lib.tv_dict_get_number(d, 'tes') end, - nil)) - eq(43, check_emsg(function() return lib.tv_dict_get_number(d, 'te') end, - nil)) + eq( + 0, + check_emsg(function() + return lib.tv_dict_get_number(d, 'test') + end, nil) + ) + eq( + 42, + check_emsg(function() + return lib.tv_dict_get_number(d, 'tes') + end, nil) + ) + eq( + 43, + check_emsg(function() + return lib.tv_dict_get_number(d, 'te') + end, nil) + ) alloc_log:check({}) - eq(0, check_emsg(function() return lib.tv_dict_get_number(d, 't') end, - 'E805: Using a Float as a Number')) + eq( + 0, + check_emsg(function() + return lib.tv_dict_get_number(d, 't') + end, 'E805: Using a Float as a Number') + ) end) end) describe('get_string()', function() itp('works with NULL dict', function() - eq(nil, check_emsg(function() return lib.tv_dict_get_string(nil, 'test', false) end, - nil)) + eq( + nil, + check_emsg(function() + return lib.tv_dict_get_string(nil, 'test', false) + end, nil) + ) end) itp('works', function() - local d = ffi.gc(dict({test={}}), nil) - eq('', ffi.string(check_emsg(function() return lib.tv_dict_get_string(d, 'test', false) end, - 'E731: Using a Dictionary as a String'))) - d = ffi.gc(dict({tes=int(42), t=44, te='43', xx=int(45)}), nil) + local d = ffi.gc(dict({ test = {} }), nil) + eq( + '', + ffi.string(check_emsg(function() + return lib.tv_dict_get_string(d, 'test', false) + end, 'E731: Using a Dictionary as a String')) + ) + d = ffi.gc(dict({ tes = int(42), t = 44, te = '43', xx = int(45) }), nil) alloc_log:clear() local dis = dict_items(d) - eq(nil, check_emsg(function() return lib.tv_dict_get_string(d, 'test', false) end, - nil)) - local s42 = check_emsg(function() return lib.tv_dict_get_string(d, 'tes', false) end, - nil) + eq( + nil, + check_emsg(function() + return lib.tv_dict_get_string(d, 'test', false) + end, nil) + ) + local s42 = check_emsg(function() + return lib.tv_dict_get_string(d, 'tes', false) + end, nil) eq('42', ffi.string(s42)) - local s45 = check_emsg(function() return lib.tv_dict_get_string(d, 'xx', false) end, - nil) + local s45 = check_emsg(function() + return lib.tv_dict_get_string(d, 'xx', false) + end, nil) eq(s42, s45) eq('45', ffi.string(s45)) eq('45', ffi.string(s42)) - local s43 = check_emsg(function() return lib.tv_dict_get_string(d, 'te', false) end, - nil) + local s43 = check_emsg(function() + return lib.tv_dict_get_string(d, 'te', false) + end, nil) eq('43', ffi.string(s43)) neq(s42, s43) eq(s43, dis.te.di_tv.vval.v_string) alloc_log:check({}) - local s44 = check_emsg(function() return lib.tv_dict_get_string(d, 't', false) end, - nil) + local s44 = check_emsg(function() + return lib.tv_dict_get_string(d, 't', false) + end, nil) eq('44.0', ffi.string(s44)) - alloc_log:check({a.freed(alloc_log.null), a.freed(alloc_log.null)}) + alloc_log:check({ a.freed(alloc_log.null), a.freed(alloc_log.null) }) end) itp('allocates a string copy when requested', function() local function tv_dict_get_string_alloc(d, key, emsg, is_float) alloc_log:clear() - local ret = check_emsg(function() return lib.tv_dict_get_string(d, key, true) end, - emsg) + local ret = check_emsg(function() + return lib.tv_dict_get_string(d, key, true) + end, emsg) local s_ret = (ret ~= nil) and ffi.string(ret) or nil if not emsg then if s_ret then if is_float then - alloc_log:check({a.freed(alloc_log.null), a.freed(alloc_log.null), a.str(ret, s_ret)}) + alloc_log:check({ + a.freed(alloc_log.null), + a.freed(alloc_log.null), + a.str(ret, s_ret), + }) else - alloc_log:check({a.str(ret, s_ret)}) + alloc_log:check({ a.str(ret, s_ret) }) end else alloc_log:check({}) @@ -1790,9 +1900,9 @@ describe('typval.c', function() lib.xfree(ret) return s_ret end - local d = ffi.gc(dict({test={}}), nil) + local d = ffi.gc(dict({ test = {} }), nil) eq('', tv_dict_get_string_alloc(d, 'test', 'E731: Using a Dictionary as a String')) - d = ffi.gc(dict({tes=int(42), t=44, te='43', xx=int(45)}), nil) + d = ffi.gc(dict({ tes = int(42), t = 44, te = '43', xx = int(45) }), nil) alloc_log:clear() eq(nil, tv_dict_get_string_alloc(d, 'test')) eq('42', tv_dict_get_string_alloc(d, 'tes')) @@ -1805,12 +1915,13 @@ describe('typval.c', function() local function tv_dict_get_string_buf(d, key, is_float, buf, emsg) buf = buf or ffi.gc(lib.xmalloc(lib.NUMBUFLEN), lib.xfree) alloc_log:clear() - local ret = check_emsg(function() return lib.tv_dict_get_string_buf(d, key, buf) end, - emsg) + local ret = check_emsg(function() + return lib.tv_dict_get_string_buf(d, key, buf) + end, emsg) local s_ret = (ret ~= nil) and ffi.string(ret) or nil if not emsg then if is_float then - alloc_log:check({a.freed(alloc_log.null), a.freed(alloc_log.null)}) + alloc_log:check({ a.freed(alloc_log.null), a.freed(alloc_log.null) }) else alloc_log:check({}) end @@ -1822,12 +1933,12 @@ describe('typval.c', function() end) itp('works', function() local lua_d = { - ['']={}, - t=1, - te=int(2), - tes=empty_list, - test='tset', - testt=5, + [''] = {}, + t = 1, + te = int(2), + tes = empty_list, + test = 'tset', + testt = 5, } local d = dict(lua_d) alloc_log:clear() @@ -1851,12 +1962,13 @@ describe('typval.c', function() 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 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 if is_float then - alloc_log:check({a.freed(alloc_log.null), a.freed(alloc_log.null)}) + alloc_log:check({ a.freed(alloc_log.null), a.freed(alloc_log.null) }) else alloc_log:check({}) end @@ -1868,12 +1980,12 @@ describe('typval.c', function() end) itp('works', function() local lua_d = { - ['']={}, - t=1, - te=int(2), - tes=empty_list, - test='tset', - testt=5, + [''] = {}, + t = 1, + te = int(2), + tes = empty_list, + test = 'tset', + testt = 5, } local d = dict(lua_d) alloc_log:clear() @@ -1901,7 +2013,8 @@ describe('typval.c', function() describe('get_callback()', function() local function tv_dict_get_callback(d, key, key_len, emsg) key_len = key_len or #key - local cb = ffi.gc(ffi.cast('Callback*', lib.xmalloc(ffi.sizeof('Callback'))), lib.callback_free) + local cb = + ffi.gc(ffi.cast('Callback*', lib.xmalloc(ffi.sizeof('Callback'))), lib.callback_free) alloc_log:clear() local ret = check_emsg(function() return lib.tv_dict_get_callback(d, key, key_len, cb) @@ -1910,35 +2023,59 @@ describe('typval.c', function() return cb_lua, ret end itp('works with NULL dict', function() - eq({{type='none'}, true}, {tv_dict_get_callback(nil, '')}) + eq({ { type = 'none' }, true }, { tv_dict_get_callback(nil, '') }) end) itp('works', function() local lua_d = { - ['']='tr', - t=int(1), - te={[type_key]=func_type, value='tr'}, - tes={[type_key]=func_type, value='tr', args={'a', 'b'}}, - test={[type_key]=func_type, value='Test', dict={test=1}, args={}}, - testt={[type_key]=func_type, value='Test', dict={test=1}, args={1}}, + [''] = 'tr', + t = int(1), + te = { [type_key] = func_type, value = 'tr' }, + tes = { [type_key] = func_type, value = 'tr', args = { 'a', 'b' } }, + test = { [type_key] = func_type, value = 'Test', dict = { test = 1 }, args = {} }, + testt = { [type_key] = func_type, value = 'Test', dict = { test = 1 }, args = { 1 } }, } local d = dict(lua_d) eq(lua_d, dct2tbl(d)) - eq({{type='fref', fref='tr'}, true}, - {tv_dict_get_callback(d, '', -1)}) - eq({{type='none'}, true}, - {tv_dict_get_callback(d, 'x', -1)}) - eq({{type='fref', fref='tr'}, true}, - {tv_dict_get_callback(d, 'testt', 0)}) - eq({{type='none'}, false}, - {tv_dict_get_callback(d, 'test', 1, 'E6000: Argument is not a function or function name')}) - eq({{type='fref', fref='tr'}, true}, - {tv_dict_get_callback(d, 'testt', 2)}) - eq({{ type='pt', fref='tr', pt={ [type_key]=func_type, value='tr', args={ 'a', 'b' } } }, true}, - {tv_dict_get_callback(d, 'testt', 3)}) - eq({{ type='pt', fref='Test', pt={ [type_key]=func_type, value='Test', dict={ test=1 }, args={} } }, true}, - {tv_dict_get_callback(d, 'testt', 4)}) - eq({{ type='pt', fref='Test', pt={ [type_key]=func_type, value='Test', dict={ test=1 }, args={1} } }, true}, - {tv_dict_get_callback(d, 'testt', 5)}) + eq({ { type = 'fref', fref = 'tr' }, true }, { tv_dict_get_callback(d, '', -1) }) + eq({ { type = 'none' }, true }, { tv_dict_get_callback(d, 'x', -1) }) + eq({ { type = 'fref', fref = 'tr' }, true }, { tv_dict_get_callback(d, 'testt', 0) }) + eq({ { type = 'none' }, false }, { + tv_dict_get_callback( + d, + 'test', + 1, + 'E6000: Argument is not a function or function name' + ), + }) + eq({ { type = 'fref', fref = 'tr' }, true }, { tv_dict_get_callback(d, 'testt', 2) }) + eq({ + { + type = 'pt', + fref = 'tr', + pt = { + [type_key] = func_type, + value = 'tr', + args = { 'a', 'b' }, + }, + }, + true, + }, { tv_dict_get_callback(d, 'testt', 3) }) + eq({ + { + type = 'pt', + fref = 'Test', + pt = { [type_key] = func_type, value = 'Test', dict = { test = 1 }, args = {} }, + }, + true, + }, { tv_dict_get_callback(d, 'testt', 4) }) + eq({ + { + type = 'pt', + fref = 'Test', + pt = { [type_key] = func_type, value = 'Test', dict = { test = 1 }, args = { 1 } }, + }, + true, + }, { tv_dict_get_callback(d, 'testt', 5) }) end) end) end) @@ -1946,22 +2083,26 @@ describe('typval.c', function() describe('()', function() itp('works', function() local di = lib.tv_dict_item_alloc_len('t-est', 5) - alloc_log:check({a.di(di, 't-est')}) + alloc_log:check({ a.di(di, 't-est') }) di.di_tv.v_type = lib.VAR_NUMBER di.di_tv.vval.v_number = 42 - local d = dict({test=10}) + local d = dict({ test = 10 }) local dis = dict_items(d) alloc_log:check({ a.dict(d), - a.di(dis.test, 'test') + a.di(dis.test, 'test'), }) - eq({test=10}, dct2tbl(d)) + eq({ test = 10 }, dct2tbl(d)) alloc_log:clear() eq(OK, lib.tv_dict_add(d, di)) alloc_log:check({}) - eq({test=10, ['t-est']=int(42)}, dct2tbl(d)) - eq(FAIL, check_emsg(function() return lib.tv_dict_add(d, di) end, - 'E685: Internal error: hash_add(): duplicate key "t-est"')) + eq({ test = 10, ['t-est'] = int(42) }, dct2tbl(d)) + eq( + FAIL, + check_emsg(function() + return lib.tv_dict_add(d, di) + end, 'E685: Internal error: hash_add(): duplicate key "t-est"') + ) end) end) describe('list()', function() @@ -1969,21 +2110,29 @@ describe('typval.c', function() local l = list(1, 2, 3) alloc_log:clear() eq(1, l.lv_refcount) - local d = dict({test=10}) + local d = dict({ test = 10 }) alloc_log:clear() - eq({test=10}, dct2tbl(d)) + eq({ test = 10 }, dct2tbl(d)) eq(OK, lib.tv_dict_add_list(d, 'testt', 3, l)) local dis = dict_items(d) - alloc_log:check({a.di(dis.tes, 'tes')}) - eq({test=10, tes={1, 2, 3}}, dct2tbl(d)) + alloc_log:check({ a.di(dis.tes, 'tes') }) + eq({ test = 10, tes = { 1, 2, 3 } }, dct2tbl(d)) eq(2, l.lv_refcount) - eq(FAIL, check_emsg(function() return lib.tv_dict_add_list(d, 'testt', 3, l) end, - 'E685: Internal error: hash_add(): duplicate key "tes"')) + eq( + FAIL, + check_emsg(function() + return lib.tv_dict_add_list(d, 'testt', 3, l) + end, 'E685: Internal error: hash_add(): duplicate key "tes"') + ) eq(2, l.lv_refcount) alloc_log:clear() lib.emsg_skip = lib.emsg_skip + 1 - eq(FAIL, check_emsg(function() return lib.tv_dict_add_list(d, 'testt', 3, l) end, - nil)) + eq( + FAIL, + check_emsg(function() + return lib.tv_dict_add_list(d, 'testt', 3, l) + end, nil) + ) eq(2, l.lv_refcount) lib.emsg_skip = lib.emsg_skip - 1 alloc_log:clear_tmp_allocs() @@ -1992,24 +2141,32 @@ describe('typval.c', function() end) describe('dict()', function() itp('works', function() - local d2 = dict({foo=42}) + local d2 = dict({ foo = 42 }) alloc_log:clear() eq(1, d2.dv_refcount) - local d = dict({test=10}) + local d = dict({ test = 10 }) alloc_log:clear() - eq({test=10}, dct2tbl(d)) + eq({ test = 10 }, dct2tbl(d)) eq(OK, lib.tv_dict_add_dict(d, 'testt', 3, d2)) local dis = dict_items(d) - alloc_log:check({a.di(dis.tes, 'tes')}) - eq({test=10, tes={foo=42}}, dct2tbl(d)) + alloc_log:check({ a.di(dis.tes, 'tes') }) + eq({ test = 10, tes = { foo = 42 } }, dct2tbl(d)) eq(2, d2.dv_refcount) - eq(FAIL, check_emsg(function() return lib.tv_dict_add_dict(d, 'testt', 3, d2) end, - 'E685: Internal error: hash_add(): duplicate key "tes"')) + eq( + FAIL, + check_emsg(function() + return lib.tv_dict_add_dict(d, 'testt', 3, d2) + end, 'E685: Internal error: hash_add(): duplicate key "tes"') + ) eq(2, d2.dv_refcount) alloc_log:clear() lib.emsg_skip = lib.emsg_skip + 1 - eq(FAIL, check_emsg(function() return lib.tv_dict_add_dict(d, 'testt', 3, d2) end, - nil)) + eq( + FAIL, + check_emsg(function() + return lib.tv_dict_add_dict(d, 'testt', 3, d2) + end, nil) + ) eq(2, d2.dv_refcount) lib.emsg_skip = lib.emsg_skip - 1 alloc_log:clear_tmp_allocs() @@ -2018,19 +2175,27 @@ describe('typval.c', function() end) describe('nr()', function() itp('works', function() - local d = dict({test=10}) + local d = dict({ test = 10 }) alloc_log:clear() - eq({test=10}, dct2tbl(d)) + eq({ test = 10 }, dct2tbl(d)) eq(OK, lib.tv_dict_add_nr(d, 'testt', 3, 2)) local dis = dict_items(d) - alloc_log:check({a.di(dis.tes, 'tes')}) - eq({test=10, tes=int(2)}, dct2tbl(d)) - eq(FAIL, check_emsg(function() return lib.tv_dict_add_nr(d, 'testt', 3, 2) end, - 'E685: Internal error: hash_add(): duplicate key "tes"')) + alloc_log:check({ a.di(dis.tes, 'tes') }) + eq({ test = 10, tes = int(2) }, dct2tbl(d)) + eq( + FAIL, + check_emsg(function() + return lib.tv_dict_add_nr(d, 'testt', 3, 2) + end, 'E685: Internal error: hash_add(): duplicate key "tes"') + ) alloc_log:clear() lib.emsg_skip = lib.emsg_skip + 1 - eq(FAIL, check_emsg(function() return lib.tv_dict_add_nr(d, 'testt', 3, 2) end, - nil)) + eq( + FAIL, + check_emsg(function() + return lib.tv_dict_add_nr(d, 'testt', 3, 2) + end, nil) + ) lib.emsg_skip = lib.emsg_skip - 1 alloc_log:clear_tmp_allocs() alloc_log:check({}) @@ -2038,19 +2203,27 @@ describe('typval.c', function() end) describe('float()', function() itp('works', function() - local d = dict({test=10}) + local d = dict({ test = 10 }) alloc_log:clear() - eq({test=10}, dct2tbl(d)) + eq({ test = 10 }, dct2tbl(d)) eq(OK, lib.tv_dict_add_float(d, 'testt', 3, 1.5)) local dis = dict_items(d) - alloc_log:check({a.di(dis.tes, 'tes')}) - eq({test=10, tes=1.5}, dct2tbl(d)) - eq(FAIL, check_emsg(function() return lib.tv_dict_add_float(d, 'testt', 3, 1.5) end, - 'E685: Internal error: hash_add(): duplicate key "tes"')) + alloc_log:check({ a.di(dis.tes, 'tes') }) + eq({ test = 10, tes = 1.5 }, dct2tbl(d)) + eq( + FAIL, + check_emsg(function() + return lib.tv_dict_add_float(d, 'testt', 3, 1.5) + end, 'E685: Internal error: hash_add(): duplicate key "tes"') + ) alloc_log:clear() lib.emsg_skip = lib.emsg_skip + 1 - eq(FAIL, check_emsg(function() return lib.tv_dict_add_float(d, 'testt', 3, 1.5) end, - nil)) + eq( + FAIL, + check_emsg(function() + return lib.tv_dict_add_float(d, 'testt', 3, 1.5) + end, nil) + ) lib.emsg_skip = lib.emsg_skip - 1 alloc_log:clear_tmp_allocs() alloc_log:check({}) @@ -2058,22 +2231,30 @@ describe('typval.c', function() end) describe('str()', function() itp('works', function() - local d = dict({test=10}) + local d = dict({ test = 10 }) alloc_log:clear() - eq({test=10}, dct2tbl(d)) + eq({ test = 10 }, dct2tbl(d)) eq(OK, lib.tv_dict_add_str(d, 'testt', 3, 'TEST')) local dis = dict_items(d) alloc_log:check({ a.str(dis.tes.di_tv.vval.v_string, 'TEST'), a.di(dis.tes, 'tes'), }) - eq({test=10, tes='TEST'}, dct2tbl(d)) - eq(FAIL, check_emsg(function() return lib.tv_dict_add_str(d, 'testt', 3, 'TEST') end, - 'E685: Internal error: hash_add(): duplicate key "tes"')) + eq({ test = 10, tes = 'TEST' }, dct2tbl(d)) + eq( + FAIL, + check_emsg(function() + return lib.tv_dict_add_str(d, 'testt', 3, 'TEST') + end, 'E685: Internal error: hash_add(): duplicate key "tes"') + ) alloc_log:clear() lib.emsg_skip = lib.emsg_skip + 1 - eq(FAIL, check_emsg(function() return lib.tv_dict_add_str(d, 'testt', 3, 'TEST') end, - nil)) + eq( + FAIL, + check_emsg(function() + return lib.tv_dict_add_str(d, 'testt', 3, 'TEST') + end, nil) + ) lib.emsg_skip = lib.emsg_skip - 1 alloc_log:clear_tmp_allocs() alloc_log:check({}) @@ -2081,8 +2262,8 @@ describe('typval.c', function() end) describe('allocated_str()', function() itp('works', function() - local d = dict({test=10}) - eq({test=10}, dct2tbl(d)) + local d = dict({ test = 10 }) + eq({ test = 10 }, dct2tbl(d)) alloc_log:clear() local s1 = lib.xstrdup('TEST') local s2 = lib.xstrdup('TEST') @@ -2097,13 +2278,21 @@ describe('typval.c', function() alloc_log:check({ a.di(dis.tes, 'tes'), }) - eq({test=10, tes='TEST'}, dct2tbl(d)) - eq(FAIL, check_emsg(function() return lib.tv_dict_add_allocated_str(d, 'testt', 3, s2) end, - 'E685: Internal error: hash_add(): duplicate key "tes"')) + eq({ test = 10, tes = 'TEST' }, dct2tbl(d)) + eq( + FAIL, + check_emsg(function() + return lib.tv_dict_add_allocated_str(d, 'testt', 3, s2) + end, 'E685: Internal error: hash_add(): duplicate key "tes"') + ) alloc_log:clear() lib.emsg_skip = lib.emsg_skip + 1 - eq(FAIL, check_emsg(function() return lib.tv_dict_add_allocated_str(d, 'testt', 3, s3) end, - nil)) + eq( + FAIL, + check_emsg(function() + return lib.tv_dict_add_allocated_str(d, 'testt', 3, s3) + end, nil) + ) lib.emsg_skip = lib.emsg_skip - 1 alloc_log:clear_tmp_allocs() alloc_log:check({ @@ -2115,7 +2304,7 @@ describe('typval.c', function() describe('clear()', function() itp('works', function() local d = dict() - alloc_log:check({a.dict(d)}) + alloc_log:check({ a.dict(d) }) eq({}, dct2tbl(d)) lib.tv_dict_clear(d) eq({}, dct2tbl(d)) @@ -2123,32 +2312,34 @@ describe('typval.c', function() local dis = dict_items(d) local di = dis.TES local di_s = di.di_tv.vval.v_string - alloc_log:check({a.str(di_s), a.di(di)}) - eq({TES='tEsT'}, dct2tbl(d)) + alloc_log:check({ a.str(di_s), a.di(di) }) + eq({ TES = 'tEsT' }, dct2tbl(d)) lib.tv_dict_clear(d) - alloc_log:check({a.freed(di_s), a.freed(di)}) + alloc_log:check({ a.freed(di_s), a.freed(di) }) eq({}, dct2tbl(d)) end) end) describe('extend()', function() local function tv_dict_extend(d1, d2, action, emsg) - action = action or "force" - check_emsg(function() return lib.tv_dict_extend(d1, d2, action) end, emsg) + action = action or 'force' + check_emsg(function() + return lib.tv_dict_extend(d1, d2, action) + end, emsg) end itp('works', function() local d1 = dict() - alloc_log:check({a.dict(d1)}) + alloc_log:check({ a.dict(d1) }) eq({}, dct2tbl(d1)) local d2 = dict() - alloc_log:check({a.dict(d2)}) + alloc_log:check({ a.dict(d2) }) eq({}, dct2tbl(d2)) tv_dict_extend(d1, d2, 'error') tv_dict_extend(d1, d2, 'keep') tv_dict_extend(d1, d2, 'force') alloc_log:check({}) - d1 = dict({a='TEST'}) - eq({a='TEST'}, dct2tbl(d1)) + d1 = dict({ a = 'TEST' }) + eq({ a = 'TEST' }, dct2tbl(d1)) local dis1 = dict_items(d1) local a1_s = dis1.a.di_tv.vval.v_string alloc_log:clear_tmp_allocs() @@ -2157,8 +2348,8 @@ describe('typval.c', function() a.di(dis1.a), a.str(a1_s), }) - d2 = dict({a='TSET'}) - eq({a='TSET'}, dct2tbl(d2)) + d2 = dict({ a = 'TSET' }) + eq({ a = 'TSET' }, dct2tbl(d2)) local dis2 = dict_items(d2) local a2_s = dis2.a.di_tv.vval.v_string alloc_log:clear_tmp_allocs() @@ -2169,72 +2360,66 @@ describe('typval.c', function() }) tv_dict_extend(d1, d2, 'error', 'E737: Key already exists: a') - eq({a='TEST'}, dct2tbl(d1)) - eq({a='TSET'}, dct2tbl(d2)) + eq({ a = 'TEST' }, dct2tbl(d1)) + eq({ a = 'TSET' }, dct2tbl(d2)) alloc_log:clear() tv_dict_extend(d1, d2, 'keep') alloc_log:check({}) - eq({a='TEST'}, dct2tbl(d1)) - eq({a='TSET'}, dct2tbl(d2)) + eq({ a = 'TEST' }, dct2tbl(d1)) + eq({ a = 'TSET' }, dct2tbl(d2)) tv_dict_extend(d1, d2, 'force') alloc_log:check({ a.freed(a1_s), a.str(dis1.a.di_tv.vval.v_string), }) - eq({a='TSET'}, dct2tbl(d1)) - eq({a='TSET'}, dct2tbl(d2)) + eq({ a = 'TSET' }, dct2tbl(d1)) + eq({ a = 'TSET' }, dct2tbl(d2)) end) pending('disallows overriding builtin or user functions: here be the dragons', function() -- pending: see TODO below local d = dict() d.dv_scope = lib.VAR_DEF_SCOPE local f_lua = { - [type_key]=func_type, - value='tr', + [type_key] = func_type, + value = 'tr', } local f_tv = lua2typvalt(f_lua) local p_lua = { - [type_key]=func_type, - value='tr', - args={1}, + [type_key] = func_type, + value = 'tr', + args = { 1 }, } local p_tv = lua2typvalt(p_lua) eq(lib.VAR_PARTIAL, p_tv.v_type) - local d2 = dict({tr=f_tv}) - local d3 = dict({tr=p_tv}) - local d4 = dict({['TEST:THIS']=p_tv}) - local d5 = dict({Test=f_tv}) - local d6 = dict({Test=p_tv}) + local d2 = dict({ tr = f_tv }) + local d3 = dict({ tr = p_tv }) + local d4 = dict({ ['TEST:THIS'] = p_tv }) + local d5 = dict({ Test = f_tv }) + local d6 = dict({ Test = p_tv }) eval0([[execute("function Test()\nendfunction")]]) -- TODO: test breaks at this point - tv_dict_extend(d, d2, 'force', - 'E704: Funcref variable name must start with a capital: tr') - tv_dict_extend(d, d3, 'force', - 'E704: Funcref variable name must start with a capital: tr') - tv_dict_extend(d, d4, 'force', - 'E461: Illegal variable name: TEST:THIS') - tv_dict_extend(d, d5, 'force', - 'E705: Variable name conflicts with existing function: Test') - tv_dict_extend(d, d6, 'force', - 'E705: Variable name conflicts with existing function: Test') + tv_dict_extend(d, d2, 'force', 'E704: Funcref variable name must start with a capital: tr') + tv_dict_extend(d, d3, 'force', 'E704: Funcref variable name must start with a capital: tr') + tv_dict_extend(d, d4, 'force', 'E461: Illegal variable name: TEST:THIS') + tv_dict_extend(d, d5, 'force', 'E705: Variable name conflicts with existing function: Test') + tv_dict_extend(d, d6, 'force', 'E705: Variable name conflicts with existing function: Test') eq({}, dct2tbl(d)) d.dv_scope = lib.VAR_SCOPE - tv_dict_extend(d, d4, 'force', - 'E461: Illegal variable name: TEST:THIS') + tv_dict_extend(d, d4, 'force', 'E461: Illegal variable name: TEST:THIS') eq({}, dct2tbl(d)) tv_dict_extend(d, d2, 'force') - eq({tr=f_lua}, dct2tbl(d)) + eq({ tr = f_lua }, dct2tbl(d)) tv_dict_extend(d, d3, 'force') - eq({tr=p_lua}, dct2tbl(d)) + eq({ tr = p_lua }, dct2tbl(d)) tv_dict_extend(d, d5, 'force') - eq({tr=p_lua, Test=f_lua}, dct2tbl(d)) + eq({ tr = p_lua, Test = f_lua }, dct2tbl(d)) tv_dict_extend(d, d6, 'force') - eq({tr=p_lua, Test=p_lua}, dct2tbl(d)) + eq({ tr = p_lua, Test = p_lua }, dct2tbl(d)) end) itp('cares about locks and read-only items', function() - local d_lua = {tv_locked=1, tv_fixed=2, di_ro=3, di_ro_sbx=4} + local d_lua = { tv_locked = 1, tv_fixed = 2, di_ro = 3, di_ro_sbx = 4 } local d = dict(d_lua) local dis = dict_items(d) dis.tv_locked.di_tv.v_lock = lib.VAR_LOCKED @@ -2242,14 +2427,19 @@ describe('typval.c', function() dis.di_ro.di_flags = bit.bor(dis.di_ro.di_flags, lib.DI_FLAGS_RO) dis.di_ro_sbx.di_flags = bit.bor(dis.di_ro_sbx.di_flags, lib.DI_FLAGS_RO_SBX) lib.sandbox = true - local d1 = dict({tv_locked=41}) - local d2 = dict({tv_fixed=42}) - local d3 = dict({di_ro=43}) - local d4 = dict({di_ro_sbx=44}) + local d1 = dict({ tv_locked = 41 }) + local d2 = dict({ tv_fixed = 42 }) + local d3 = dict({ di_ro = 43 }) + local d4 = dict({ di_ro_sbx = 44 }) tv_dict_extend(d, d1, 'force', 'E741: Value is locked: extend() argument') tv_dict_extend(d, d2, 'force', 'E742: Cannot change value of extend() argument') tv_dict_extend(d, d3, 'force', 'E46: Cannot change read-only variable "extend() argument"') - tv_dict_extend(d, d4, 'force', 'E794: Cannot set variable in the sandbox: "extend() argument"') + tv_dict_extend( + d, + d4, + 'force', + 'E794: Cannot set variable in the sandbox: "extend() argument"' + ) eq(d_lua, dct2tbl(d)) lib.sandbox = false tv_dict_extend(d, d4, 'force') @@ -2264,20 +2454,20 @@ describe('typval.c', function() itp('works', function() eq(true, tv_dict_equal(nil, nil)) local d1 = dict() - alloc_log:check({a.dict(d1)}) + alloc_log:check({ a.dict(d1) }) eq(1, d1.dv_refcount) eq(true, tv_dict_equal(nil, d1)) eq(true, tv_dict_equal(d1, nil)) eq(true, tv_dict_equal(d1, d1)) eq(1, d1.dv_refcount) alloc_log:check({}) - local d_upper = dict({a='TEST'}) + local d_upper = dict({ a = 'TEST' }) local dis_upper = dict_items(d_upper) - local d_lower = dict({a='test'}) + local d_lower = dict({ a = 'test' }) local dis_lower = dict_items(d_lower) - local d_kupper_upper = dict({A='TEST'}) + local d_kupper_upper = dict({ A = 'TEST' }) local dis_kupper_upper = dict_items(d_kupper_upper) - local d_kupper_lower = dict({A='test'}) + local d_kupper_lower = dict({ A = 'test' }) local dis_kupper_lower = dict_items(d_kupper_lower) alloc_log:clear_tmp_allocs() alloc_log:check({ @@ -2320,7 +2510,15 @@ describe('typval.c', function() end) itp('copies dict correctly without converting items', function() do - local v = {a={['«']='»'}, b={'„'}, ['1']=1, ['«»']='“', ns=null_string, nl=null_list, nd=null_dict} + local v = { + a = { ['«'] = '»' }, + b = { '„' }, + ['1'] = 1, + ['«»'] = '“', + ns = null_string, + nl = null_list, + nd = null_dict, + } local d_tv = lua2typvalt(v) local d = d_tv.vval.v_dict local dis = dict_items(d) @@ -2358,7 +2556,15 @@ describe('typval.c', function() -- UTF-8 ↔ latin1 conversions need no iconv eq(OK, lib.convert_setup(vc, to_cstr('utf-8'), to_cstr('latin1'))) - local v = {a={['«']='»'}, b={'„'}, ['1']=1, ['«»']='“', ns=null_string, nl=null_list, nd=null_dict} + local v = { + a = { ['«'] = '»' }, + b = { '„' }, + ['1'] = 1, + ['«»'] = '“', + ns = null_string, + nl = null_list, + nd = null_dict, + } local d_tv = lua2typvalt(v) local d = d_tv.vval.v_dict local dis = dict_items(d) @@ -2373,14 +2579,21 @@ describe('typval.c', function() local dis_deepcopy1 = dict_items(d_deepcopy1) neq(dis.a.di_tv.vval.v_dict, dis_deepcopy1.a.di_tv.vval.v_dict) neq(dis.b.di_tv.vval.v_list, dis_deepcopy1.b.di_tv.vval.v_list) - eq({a={['\171']='\187'}, b={'\191'}, ['1']=1, ['\171\187']='\191', ns=null_string, nl=null_list, nd=null_dict}, - dct2tbl(d_deepcopy1)) + eq({ + a = { ['\171'] = '\187' }, + b = { '\191' }, + ['1'] = 1, + ['\171\187'] = '\191', + ns = null_string, + nl = null_list, + nd = null_dict, + }, dct2tbl(d_deepcopy1)) alloc_log:clear_tmp_allocs() alloc_log:clear() end) itp('returns different/same containers with(out) copyID', function() local d_inner_tv = lua2typvalt({}) - local d_tv = lua2typvalt({a=d_inner_tv, b=d_inner_tv}) + local d_tv = lua2typvalt({ a = d_inner_tv, b = d_inner_tv }) eq(3, d_inner_tv.vval.v_dict.dv_refcount) local d = d_tv.vval.v_dict local dis = dict_items(d) @@ -2389,12 +2602,12 @@ describe('typval.c', function() local d_copy1 = tv_dict_copy(nil, d, true, 0) local dis_copy1 = dict_items(d_copy1) neq(dis_copy1.a.di_tv.vval.v_dict, dis_copy1.b.di_tv.vval.v_dict) - eq({a={}, b={}}, dct2tbl(d_copy1)) + eq({ a = {}, b = {} }, dct2tbl(d_copy1)) local d_copy2 = tv_dict_copy(nil, d, true, 2) local dis_copy2 = dict_items(d_copy2) eq(dis_copy2.a.di_tv.vval.v_dict, dis_copy2.b.di_tv.vval.v_dict) - eq({a={}, b={}}, dct2tbl(d_copy2)) + eq({ a = {}, b = {} }, dct2tbl(d_copy2)) eq(3, d_inner_tv.vval.v_dict.dv_refcount) end) @@ -2420,9 +2633,9 @@ describe('typval.c', function() end) describe('set_keys_readonly()', function() itp('works', function() - local d = dict({a=true}) + local d = dict({ a = true }) local dis = dict_items(d) - alloc_log:check({a.dict(d), a.di(dis.a)}) + alloc_log:check({ a.dict(d), a.di(dis.a) }) eq(0, bit.band(dis.a.di_flags, lib.DI_FLAGS_RO)) eq(0, bit.band(dis.a.di_flags, lib.DI_FLAGS_FIX)) lib.tv_dict_set_keys_readonly(d) @@ -2472,23 +2685,52 @@ describe('typval.c', function() local dd_d = nil dd.dd = dd for _, v in ipairs({ - {nil_value}, - {null_string, nil, function() return {a.freed(alloc_log.null)} end}, - {0}, - {int(0)}, - {true}, - {false}, - {'true', function(tv) return {a.str(tv.vval.v_string)} end}, - {{}, function(tv) return {a.dict(tv.vval.v_dict)} end}, - {empty_list, function(tv) return {a.list(tv.vval.v_list)} end}, - {ll, function(tv) - ll_l = tv.vval.v_list - return {a.list(tv.vval.v_list), a.li(tv.vval.v_list.lv_first)} - end, defalloc}, - {dd, function(tv) - dd_d = tv.vval.v_dict - return {a.dict(tv.vval.v_dict), a.di(first_di(tv.vval.v_dict))} - end, defalloc}, + { nil_value }, + { + null_string, + nil, + function() + return { a.freed(alloc_log.null) } + end, + }, + { 0 }, + { int(0) }, + { true }, + { false }, + { + 'true', + function(tv) + return { a.str(tv.vval.v_string) } + end, + }, + { + {}, + function(tv) + return { a.dict(tv.vval.v_dict) } + end, + }, + { + empty_list, + function(tv) + return { a.list(tv.vval.v_list) } + end, + }, + { + ll, + function(tv) + ll_l = tv.vval.v_list + return { a.list(tv.vval.v_list), a.li(tv.vval.v_list.lv_first) } + end, + defalloc, + }, + { + dd, + function(tv) + dd_d = tv.vval.v_dict + return { a.dict(tv.vval.v_dict), a.di(first_di(tv.vval.v_dict)) } + end, + defalloc, + }, }) do local tv = lua2typvalt(v[1]) local alloc_rets = {} @@ -2503,26 +2745,45 @@ describe('typval.c', function() describe('copy()', function() itp('works', function() local function strallocs(tv) - return {a.str(tv.vval.v_string)} + return { a.str(tv.vval.v_string) } end for _, v in ipairs({ - {nil_value}, - {null_string}, - {0}, - {int(0)}, - {true}, - {false}, - {{}, function(tv) return {a.dict(tv.vval.v_dict)} end, nil, function(from, to) - eq(2, to.vval.v_dict.dv_refcount) - eq(to.vval.v_dict, from.vval.v_dict) - end}, - {empty_list, function(tv) return {a.list(tv.vval.v_list)} end, nil, function(from, to) - eq(2, to.vval.v_list.lv_refcount) - eq(to.vval.v_list, from.vval.v_list) - end}, - {'test', strallocs, strallocs, function(from, to) - neq(to.vval.v_string, from.vval.v_string) - end}, + { nil_value }, + { null_string }, + { 0 }, + { int(0) }, + { true }, + { false }, + { + {}, + function(tv) + return { a.dict(tv.vval.v_dict) } + end, + nil, + function(from, to) + eq(2, to.vval.v_dict.dv_refcount) + eq(to.vval.v_dict, from.vval.v_dict) + end, + }, + { + empty_list, + function(tv) + return { a.list(tv.vval.v_list) } + end, + nil, + function(from, to) + eq(2, to.vval.v_list.lv_refcount) + eq(to.vval.v_list, from.vval.v_list) + end, + }, + { + 'test', + strallocs, + strallocs, + function(from, to) + neq(to.vval.v_string, from.vval.v_string) + end, + }, }) do local from = lua2typvalt(v[1]) alloc_log:check((v[2] or defalloc)(from)) @@ -2540,9 +2801,9 @@ describe('typval.c', function() describe('item_lock()', function() itp('does not alter VAR_PARTIAL', function() local p_tv = lua2typvalt({ - [type_key]=func_type, - value='tr', - dict={}, + [type_key] = func_type, + value = 'tr', + dict = {}, }) lib.tv_item_lock(p_tv, -1, true, false) eq(lib.VAR_UNLOCKED, p_tv.vval.v_partial.pt_dict.dv_lock) @@ -2641,18 +2902,18 @@ describe('typval.c', function() end itp('works', function() eq(false, tv_check_lock(lib.VAR_UNLOCKED, 'test', 3)) - eq(true, tv_check_lock(lib.VAR_LOCKED, 'test', 3, - 'E741: Value is locked: tes')) - eq(true, tv_check_lock(lib.VAR_FIXED, 'test', 3, - 'E742: Cannot change value of tes')) - eq(true, tv_check_lock(lib.VAR_LOCKED, nil, 0, - 'E741: Value is locked: Unknown')) - eq(true, tv_check_lock(lib.VAR_FIXED, nil, 0, - 'E742: Cannot change value of Unknown')) - eq(true, tv_check_lock(lib.VAR_LOCKED, nil, lib.kTVCstring, - 'E741: Value is locked: Unknown')) - eq(true, tv_check_lock(lib.VAR_FIXED, 'test', lib.kTVCstring, - 'E742: Cannot change value of test')) + eq(true, tv_check_lock(lib.VAR_LOCKED, 'test', 3, 'E741: Value is locked: tes')) + eq(true, tv_check_lock(lib.VAR_FIXED, 'test', 3, 'E742: Cannot change value of tes')) + eq(true, tv_check_lock(lib.VAR_LOCKED, nil, 0, 'E741: Value is locked: Unknown')) + eq(true, tv_check_lock(lib.VAR_FIXED, nil, 0, 'E742: Cannot change value of Unknown')) + eq( + true, + tv_check_lock(lib.VAR_LOCKED, nil, lib.kTVCstring, 'E741: Value is locked: Unknown') + ) + eq( + true, + tv_check_lock(lib.VAR_FIXED, 'test', lib.kTVCstring, 'E742: Cannot change value of test') + ) end) end) describe('equal()', function() @@ -2683,15 +2944,15 @@ describe('typval.c', function() -- indicates that tv_equal_recurse_limit and recursive_cnt were set which -- is essential. This argument will be set when comparing inner lists. itp('compares lists correctly when case is not ignored', function() - local l1 = lua2typvalt({'abc', {1, 2, 'Abc'}, 'def'}) - local l2 = lua2typvalt({'abc', {1, 2, 'Abc'}}) - local l3 = lua2typvalt({'abc', {1, 2, 'Abc'}, 'Def'}) - local l4 = lua2typvalt({'abc', {1, 2, 'Abc', 4}, 'def'}) - local l5 = lua2typvalt({'Abc', {1, 2, 'Abc'}, 'def'}) - local l6 = lua2typvalt({'abc', {1, 2, 'Abc'}, 'def'}) - local l7 = lua2typvalt({'abc', {1, 2, 'abc'}, 'def'}) - local l8 = lua2typvalt({'abc', nil, 'def'}) - local l9 = lua2typvalt({'abc', {1, 2, nil}, 'def'}) + local l1 = lua2typvalt({ 'abc', { 1, 2, 'Abc' }, 'def' }) + local l2 = lua2typvalt({ 'abc', { 1, 2, 'Abc' } }) + local l3 = lua2typvalt({ 'abc', { 1, 2, 'Abc' }, 'Def' }) + local l4 = lua2typvalt({ 'abc', { 1, 2, 'Abc', 4 }, 'def' }) + local l5 = lua2typvalt({ 'Abc', { 1, 2, 'Abc' }, 'def' }) + local l6 = lua2typvalt({ 'abc', { 1, 2, 'Abc' }, 'def' }) + local l7 = lua2typvalt({ 'abc', { 1, 2, 'abc' }, 'def' }) + local l8 = lua2typvalt({ 'abc', nil, 'def' }) + local l9 = lua2typvalt({ 'abc', { 1, 2, nil }, 'def' }) eq(true, lib.tv_equal(l1, l1, false, false)) eq(false, lib.tv_equal(l1, l2, false, false)) @@ -2704,15 +2965,15 @@ describe('typval.c', function() eq(false, lib.tv_equal(l1, l9, false, false)) end) itp('compares lists correctly when case is ignored', function() - local l1 = lua2typvalt({'abc', {1, 2, 'Abc'}, 'def'}) - local l2 = lua2typvalt({'abc', {1, 2, 'Abc'}}) - local l3 = lua2typvalt({'abc', {1, 2, 'Abc'}, 'Def'}) - local l4 = lua2typvalt({'abc', {1, 2, 'Abc', 4}, 'def'}) - local l5 = lua2typvalt({'Abc', {1, 2, 'Abc'}, 'def'}) - local l6 = lua2typvalt({'abc', {1, 2, 'Abc'}, 'def'}) - local l7 = lua2typvalt({'abc', {1, 2, 'abc'}, 'def'}) - local l8 = lua2typvalt({'abc', nil, 'def'}) - local l9 = lua2typvalt({'abc', {1, 2, nil}, 'def'}) + local l1 = lua2typvalt({ 'abc', { 1, 2, 'Abc' }, 'def' }) + local l2 = lua2typvalt({ 'abc', { 1, 2, 'Abc' } }) + local l3 = lua2typvalt({ 'abc', { 1, 2, 'Abc' }, 'Def' }) + local l4 = lua2typvalt({ 'abc', { 1, 2, 'Abc', 4 }, 'def' }) + local l5 = lua2typvalt({ 'Abc', { 1, 2, 'Abc' }, 'def' }) + local l6 = lua2typvalt({ 'abc', { 1, 2, 'Abc' }, 'def' }) + local l7 = lua2typvalt({ 'abc', { 1, 2, 'abc' }, 'def' }) + local l8 = lua2typvalt({ 'abc', nil, 'def' }) + local l9 = lua2typvalt({ 'abc', { 1, 2, nil }, 'def' }) eq(true, lib.tv_equal(l1, l1, true, false)) eq(false, lib.tv_equal(l1, l2, true, false)) @@ -2732,20 +2993,20 @@ describe('typval.c', function() eq(true, tv_equal(nd, nd)) alloc_log:check({}) local d1 = lua2typvalt({}) - alloc_log:check({a.dict(d1.vval.v_dict)}) + alloc_log:check({ a.dict(d1.vval.v_dict) }) eq(1, d1.vval.v_dict.dv_refcount) eq(true, tv_equal(nd, d1)) eq(true, tv_equal(d1, nd)) eq(true, tv_equal(d1, d1)) eq(1, d1.vval.v_dict.dv_refcount) alloc_log:check({}) - local d_upper = lua2typvalt({a='TEST'}) + local d_upper = lua2typvalt({ a = 'TEST' }) local dis_upper = dict_items(d_upper.vval.v_dict) - local d_lower = lua2typvalt({a='test'}) + local d_lower = lua2typvalt({ a = 'test' }) local dis_lower = dict_items(d_lower.vval.v_dict) - local d_kupper_upper = lua2typvalt({A='TEST'}) + local d_kupper_upper = lua2typvalt({ A = 'TEST' }) local dis_kupper_upper = dict_items(d_kupper_upper.vval.v_dict) - local d_kupper_lower = lua2typvalt({A='test'}) + local d_kupper_lower = lua2typvalt({ A = 'test' }) local dis_kupper_lower = dict_items(d_kupper_lower.vval.v_dict) alloc_log:clear_tmp_allocs() alloc_log:check({ @@ -2781,24 +3042,31 @@ describe('typval.c', function() itp('works', function() local tv = typvalt() local mem = lib.xmalloc(1) - tv.vval.v_list = mem -- Should crash when actually accessed + tv.vval.v_list = mem -- Should crash when actually accessed alloc_log:clear() for _, v in ipairs({ - {lib.VAR_NUMBER, nil}, - {lib.VAR_FLOAT, 'E805: Expected a Number or a String, Float found'}, - {lib.VAR_PARTIAL, 'E703: Expected a Number or a String, Funcref found'}, - {lib.VAR_FUNC, 'E703: Expected a Number or a String, Funcref found'}, - {lib.VAR_LIST, 'E745: Expected a Number or a String, List found'}, - {lib.VAR_DICT, 'E728: Expected a Number or a String, Dictionary found'}, - {lib.VAR_SPECIAL, 'E5300: Expected a Number or a String'}, - {lib.VAR_UNKNOWN, 'E685: Internal error: tv_check_str_or_nr(UNKNOWN)'}, + { lib.VAR_NUMBER, nil }, + { lib.VAR_FLOAT, 'E805: Expected a Number or a String, Float found' }, + { lib.VAR_PARTIAL, 'E703: Expected a Number or a String, Funcref found' }, + { lib.VAR_FUNC, 'E703: Expected a Number or a String, Funcref found' }, + { lib.VAR_LIST, 'E745: Expected a Number or a String, List found' }, + { lib.VAR_DICT, 'E728: Expected a Number or a String, Dictionary found' }, + { lib.VAR_SPECIAL, 'E5300: Expected a Number or a String' }, + { lib.VAR_UNKNOWN, 'E685: Internal error: tv_check_str_or_nr(UNKNOWN)' }, }) do local typ = v[1] local emsg = v[2] local ret = true - if emsg then ret = false end + if emsg then + ret = false + end tv.v_type = typ - eq(ret, check_emsg(function() return lib.tv_check_str_or_nr(tv) end, emsg)) + eq( + ret, + check_emsg(function() + return lib.tv_check_str_or_nr(tv) + end, emsg) + ) if emsg then alloc_log:clear() else @@ -2811,24 +3079,31 @@ describe('typval.c', function() itp('works', function() local tv = typvalt() local mem = lib.xmalloc(1) - tv.vval.v_list = mem -- Should crash when actually accessed + tv.vval.v_list = mem -- Should crash when actually accessed alloc_log:clear() for _, v in ipairs({ - {lib.VAR_NUMBER, nil}, - {lib.VAR_FLOAT, 'E805: Using a Float as a Number'}, - {lib.VAR_PARTIAL, 'E703: Using a Funcref as a Number'}, - {lib.VAR_FUNC, 'E703: Using a Funcref as a Number'}, - {lib.VAR_LIST, 'E745: Using a List as a Number'}, - {lib.VAR_DICT, 'E728: Using a Dictionary as a Number'}, - {lib.VAR_SPECIAL, nil}, - {lib.VAR_UNKNOWN, 'E685: using an invalid value as a Number'}, + { lib.VAR_NUMBER, nil }, + { lib.VAR_FLOAT, 'E805: Using a Float as a Number' }, + { lib.VAR_PARTIAL, 'E703: Using a Funcref as a Number' }, + { lib.VAR_FUNC, 'E703: Using a Funcref as a Number' }, + { lib.VAR_LIST, 'E745: Using a List as a Number' }, + { lib.VAR_DICT, 'E728: Using a Dictionary as a Number' }, + { lib.VAR_SPECIAL, nil }, + { lib.VAR_UNKNOWN, 'E685: using an invalid value as a Number' }, }) do local typ = v[1] local emsg = v[2] local ret = true - if emsg then ret = false end + if emsg then + ret = false + end tv.v_type = typ - eq(ret, check_emsg(function() return lib.tv_check_num(tv) end, emsg)) + eq( + ret, + check_emsg(function() + return lib.tv_check_num(tv) + end, emsg) + ) if emsg then alloc_log:clear() else @@ -2841,25 +3116,32 @@ describe('typval.c', function() itp('works', function() local tv = typvalt() local mem = lib.xmalloc(1) - tv.vval.v_list = mem -- Should crash when actually accessed + tv.vval.v_list = mem -- Should crash when actually accessed alloc_log:clear() for _, v in ipairs({ - {lib.VAR_NUMBER, nil}, - {lib.VAR_FLOAT, nil}, - {lib.VAR_PARTIAL, 'E729: Using a Funcref as a String'}, - {lib.VAR_FUNC, 'E729: Using a Funcref as a String'}, - {lib.VAR_LIST, 'E730: Using a List as a String'}, - {lib.VAR_DICT, 'E731: Using a Dictionary as a String'}, - {lib.VAR_BOOL, nil}, - {lib.VAR_SPECIAL, nil}, - {lib.VAR_UNKNOWN, 'E908: Using an invalid value as a String'}, + { lib.VAR_NUMBER, nil }, + { lib.VAR_FLOAT, nil }, + { lib.VAR_PARTIAL, 'E729: Using a Funcref as a String' }, + { lib.VAR_FUNC, 'E729: Using a Funcref as a String' }, + { lib.VAR_LIST, 'E730: Using a List as a String' }, + { lib.VAR_DICT, 'E731: Using a Dictionary as a String' }, + { lib.VAR_BOOL, nil }, + { lib.VAR_SPECIAL, nil }, + { lib.VAR_UNKNOWN, 'E908: Using an invalid value as a String' }, }) do local typ = v[1] local emsg = v[2] local ret = true - if emsg then ret = false end + if emsg then + ret = false + end tv.v_type = typ - eq(ret, check_emsg(function() return lib.tv_check_str(tv) end, emsg)) + eq( + ret, + check_emsg(function() + return lib.tv_check_str(tv) + end, emsg) + ) if emsg then alloc_log:clear() else @@ -2873,24 +3155,29 @@ describe('typval.c', function() describe('number()', function() itp('works', function() for _, v in ipairs({ - {lib.VAR_NUMBER, {v_number=42}, nil, 42}, - {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, 100500}, - {lib.VAR_FLOAT, {v_float=42.53}, 'E805: Using a Float as a Number', 0}, - {lib.VAR_PARTIAL, {v_partial=NULL}, 'E703: Using a Funcref as a Number', 0}, - {lib.VAR_FUNC, {v_string=NULL}, 'E703: Using a Funcref as a Number', 0}, - {lib.VAR_LIST, {v_list=NULL}, 'E745: Using a List as a Number', 0}, - {lib.VAR_DICT, {v_dict=NULL}, 'E728: Using a Dictionary as a Number', 0}, - {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarNull}, nil, 0}, - {lib.VAR_BOOL, {v_bool=lib.kBoolVarTrue}, nil, 1}, - {lib.VAR_BOOL, {v_bool=lib.kBoolVarFalse}, nil, 0}, - {lib.VAR_UNKNOWN, nil, 'E685: Internal error: tv_get_number(UNKNOWN)', 0}, + { lib.VAR_NUMBER, { v_number = 42 }, nil, 42 }, + { lib.VAR_STRING, { v_string = to_cstr('100500') }, nil, 100500 }, + { lib.VAR_FLOAT, { v_float = 42.53 }, 'E805: Using a Float as a Number', 0 }, + { lib.VAR_PARTIAL, { v_partial = NULL }, 'E703: Using a Funcref as a Number', 0 }, + { lib.VAR_FUNC, { v_string = NULL }, 'E703: Using a Funcref as a Number', 0 }, + { lib.VAR_LIST, { v_list = NULL }, 'E745: Using a List as a Number', 0 }, + { lib.VAR_DICT, { v_dict = NULL }, 'E728: Using a Dictionary as a Number', 0 }, + { lib.VAR_SPECIAL, { v_special = lib.kSpecialVarNull }, nil, 0 }, + { lib.VAR_BOOL, { v_bool = lib.kBoolVarTrue }, nil, 1 }, + { lib.VAR_BOOL, { v_bool = lib.kBoolVarFalse }, nil, 0 }, + { lib.VAR_UNKNOWN, nil, 'E685: Internal error: tv_get_number(UNKNOWN)', 0 }, }) do -- Using to_cstr, cannot free with tv_clear local tv = ffi.gc(typvalt(v[1], v[2]), nil) alloc_log:check({}) local emsg = v[3] local ret = v[4] - eq(ret, check_emsg(function() return lib.tv_get_number(tv) end, emsg)) + eq( + ret, + check_emsg(function() + return lib.tv_get_number(tv) + end, emsg) + ) if emsg then alloc_log:clear() else @@ -2902,28 +3189,31 @@ describe('typval.c', function() describe('number_chk()', function() itp('works', function() for _, v in ipairs({ - {lib.VAR_NUMBER, {v_number=42}, nil, 42}, - {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, 100500}, - {lib.VAR_FLOAT, {v_float=42.53}, 'E805: Using a Float as a Number', 0}, - {lib.VAR_PARTIAL, {v_partial=NULL}, 'E703: Using a Funcref as a Number', 0}, - {lib.VAR_FUNC, {v_string=NULL}, 'E703: Using a Funcref as a Number', 0}, - {lib.VAR_LIST, {v_list=NULL}, 'E745: Using a List as a Number', 0}, - {lib.VAR_DICT, {v_dict=NULL}, 'E728: Using a Dictionary as a Number', 0}, - {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarNull}, nil, 0}, - {lib.VAR_BOOL, {v_bool=lib.kBoolVarTrue}, nil, 1}, - {lib.VAR_BOOL, {v_bool=lib.kBoolVarFalse}, nil, 0}, - {lib.VAR_UNKNOWN, nil, 'E685: Internal error: tv_get_number(UNKNOWN)', 0}, + { lib.VAR_NUMBER, { v_number = 42 }, nil, 42 }, + { lib.VAR_STRING, { v_string = to_cstr('100500') }, nil, 100500 }, + { lib.VAR_FLOAT, { v_float = 42.53 }, 'E805: Using a Float as a Number', 0 }, + { lib.VAR_PARTIAL, { v_partial = NULL }, 'E703: Using a Funcref as a Number', 0 }, + { lib.VAR_FUNC, { v_string = NULL }, 'E703: Using a Funcref as a Number', 0 }, + { lib.VAR_LIST, { v_list = NULL }, 'E745: Using a List as a Number', 0 }, + { lib.VAR_DICT, { v_dict = NULL }, 'E728: Using a Dictionary as a Number', 0 }, + { lib.VAR_SPECIAL, { v_special = lib.kSpecialVarNull }, nil, 0 }, + { lib.VAR_BOOL, { v_bool = lib.kBoolVarTrue }, nil, 1 }, + { lib.VAR_BOOL, { v_bool = lib.kBoolVarFalse }, nil, 0 }, + { lib.VAR_UNKNOWN, nil, 'E685: Internal error: tv_get_number(UNKNOWN)', 0 }, }) do -- Using to_cstr, cannot free with tv_clear local tv = ffi.gc(typvalt(v[1], v[2]), nil) alloc_log:check({}) local emsg = v[3] - local ret = {v[4], not not emsg} - eq(ret, check_emsg(function() - local err = ffi.new('bool[1]', {false}) - local res = lib.tv_get_number_chk(tv, err) - return {res, err[0]} - end, emsg)) + local ret = { v[4], not not emsg } + eq( + ret, + check_emsg(function() + local err = ffi.new('bool[1]', { false }) + local res = lib.tv_get_number_chk(tv, err) + return { res, err[0] } + end, emsg) + ) if emsg then alloc_log:clear() else @@ -2935,18 +3225,18 @@ describe('typval.c', function() describe('lnum()', function() itp('works', function() for _, v in ipairs({ - {lib.VAR_NUMBER, {v_number=42}, nil, 42}, - {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, 100500}, - {lib.VAR_STRING, {v_string=to_cstr('.')}, nil, 46}, - {lib.VAR_FLOAT, {v_float=42.53}, 'E805: Using a Float as a Number', -1}, - {lib.VAR_PARTIAL, {v_partial=NULL}, 'E703: Using a Funcref as a Number', -1}, - {lib.VAR_FUNC, {v_string=NULL}, 'E703: Using a Funcref as a Number', -1}, - {lib.VAR_LIST, {v_list=NULL}, 'E745: Using a List as a Number', -1}, - {lib.VAR_DICT, {v_dict=NULL}, 'E728: Using a Dictionary as a Number', -1}, - {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarNull}, nil, 0}, - {lib.VAR_BOOL, {v_bool=lib.kBoolVarTrue}, nil, 1}, - {lib.VAR_BOOL, {v_bool=lib.kBoolVarFalse}, nil, 0}, - {lib.VAR_UNKNOWN, nil, 'E685: Internal error: tv_get_number(UNKNOWN)', -1}, + { lib.VAR_NUMBER, { v_number = 42 }, nil, 42 }, + { lib.VAR_STRING, { v_string = to_cstr('100500') }, nil, 100500 }, + { lib.VAR_STRING, { v_string = to_cstr('.') }, nil, 46 }, + { lib.VAR_FLOAT, { v_float = 42.53 }, 'E805: Using a Float as a Number', -1 }, + { lib.VAR_PARTIAL, { v_partial = NULL }, 'E703: Using a Funcref as a Number', -1 }, + { lib.VAR_FUNC, { v_string = NULL }, 'E703: Using a Funcref as a Number', -1 }, + { lib.VAR_LIST, { v_list = NULL }, 'E745: Using a List as a Number', -1 }, + { lib.VAR_DICT, { v_dict = NULL }, 'E728: Using a Dictionary as a Number', -1 }, + { lib.VAR_SPECIAL, { v_special = lib.kSpecialVarNull }, nil, 0 }, + { lib.VAR_BOOL, { v_bool = lib.kBoolVarTrue }, nil, 1 }, + { lib.VAR_BOOL, { v_bool = lib.kBoolVarFalse }, nil, 0 }, + { lib.VAR_UNKNOWN, nil, 'E685: Internal error: tv_get_number(UNKNOWN)', -1 }, }) do lib.curwin.w_cursor.lnum = 46 -- Using to_cstr, cannot free with tv_clear @@ -2954,7 +3244,12 @@ describe('typval.c', function() alloc_log:check({}) local emsg = v[3] local ret = v[4] - eq(ret, check_emsg(function() return lib.tv_get_lnum(tv) end, emsg)) + eq( + ret, + check_emsg(function() + return lib.tv_get_lnum(tv) + end, emsg) + ) if emsg then alloc_log:clear() else @@ -2966,24 +3261,49 @@ describe('typval.c', function() describe('float()', function() itp('works', function() for _, v in ipairs({ - {lib.VAR_NUMBER, {v_number=42}, nil, 42}, - {lib.VAR_STRING, {v_string=to_cstr('100500')}, 'E892: Using a String as a Float', 0}, - {lib.VAR_FLOAT, {v_float=42.53}, nil, 42.53}, - {lib.VAR_PARTIAL, {v_partial=NULL}, 'E891: Using a Funcref as a Float', 0}, - {lib.VAR_FUNC, {v_string=NULL}, 'E891: Using a Funcref as a Float', 0}, - {lib.VAR_LIST, {v_list=NULL}, 'E893: Using a List as a Float', 0}, - {lib.VAR_DICT, {v_dict=NULL}, 'E894: Using a Dictionary as a Float', 0}, - {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarNull}, 'E907: Using a special value as a Float', 0}, - {lib.VAR_BOOL, {v_bool=lib.kBoolVarTrue}, 'E362: Using a boolean value as a Float', 0}, - {lib.VAR_BOOL, {v_bool=lib.kBoolVarFalse}, 'E362: Using a boolean value as a Float', 0}, - {lib.VAR_UNKNOWN, nil, 'E685: Internal error: tv_get_float(UNKNOWN)', 0}, + { lib.VAR_NUMBER, { v_number = 42 }, nil, 42 }, + { + lib.VAR_STRING, + { v_string = to_cstr('100500') }, + 'E892: Using a String as a Float', + 0, + }, + { lib.VAR_FLOAT, { v_float = 42.53 }, nil, 42.53 }, + { lib.VAR_PARTIAL, { v_partial = NULL }, 'E891: Using a Funcref as a Float', 0 }, + { lib.VAR_FUNC, { v_string = NULL }, 'E891: Using a Funcref as a Float', 0 }, + { lib.VAR_LIST, { v_list = NULL }, 'E893: Using a List as a Float', 0 }, + { lib.VAR_DICT, { v_dict = NULL }, 'E894: Using a Dictionary as a Float', 0 }, + { + lib.VAR_SPECIAL, + { v_special = lib.kSpecialVarNull }, + 'E907: Using a special value as a Float', + 0, + }, + { + lib.VAR_BOOL, + { v_bool = lib.kBoolVarTrue }, + 'E362: Using a boolean value as a Float', + 0, + }, + { + lib.VAR_BOOL, + { v_bool = lib.kBoolVarFalse }, + 'E362: Using a boolean value as a Float', + 0, + }, + { lib.VAR_UNKNOWN, nil, 'E685: Internal error: tv_get_float(UNKNOWN)', 0 }, }) do -- Using to_cstr, cannot free with tv_clear local tv = ffi.gc(typvalt(v[1], v[2]), nil) alloc_log:check({}) local emsg = v[3] local ret = v[4] - eq(ret, check_emsg(function() return lib.tv_get_float(tv) end, emsg)) + eq( + ret, + check_emsg(function() + return lib.tv_get_float(tv) + end, emsg) + ) if emsg then alloc_log:clear() else @@ -3001,24 +3321,31 @@ describe('typval.c', function() alloc_log:check({}) local emsg = v[3] local ret = v[4] - eq(ret, check_emsg(function() - local res, buf = fn(tv) - if tv.v_type == lib.VAR_NUMBER or tv.v_type == lib.VAR_FLOAT - or tv.v_type == lib.VAR_SPECIAL or tv.v_type == lib.VAR_BOOL then - eq(buf, res) - else - neq(buf, res) - end - if res ~= nil then - return ffi.string(res) - else - return nil - end - end, emsg)) + eq( + ret, + check_emsg(function() + local res, buf = fn(tv) + if + tv.v_type == lib.VAR_NUMBER + or tv.v_type == lib.VAR_FLOAT + or tv.v_type == lib.VAR_SPECIAL + or tv.v_type == lib.VAR_BOOL + then + eq(buf, res) + else + neq(buf, res) + end + if res ~= nil then + return ffi.string(res) + else + return nil + end + end, emsg) + ) if emsg then alloc_log:clear() elseif tv.v_type == lib.VAR_FLOAT then - alloc_log:check({a.freed(alloc_log.null), a.freed(alloc_log.null)}) + alloc_log:check({ a.freed(alloc_log.null), a.freed(alloc_log.null) }) else alloc_log:check({}) end @@ -3030,17 +3357,17 @@ describe('typval.c', function() local buf_chk = lib.tv_get_string_chk(lua2typvalt(int(1))) neq(buf, buf_chk) test_string_fn({ - {lib.VAR_NUMBER, {v_number=42}, nil, '42'}, - {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, '100500'}, - {lib.VAR_FLOAT, {v_float=42.53}, nil, '42.53'}, - {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: Using a Funcref as a String', ''}, - {lib.VAR_FUNC, {v_string=NULL}, 'E729: Using a Funcref as a String', ''}, - {lib.VAR_LIST, {v_list=NULL}, 'E730: Using a List as a String', ''}, - {lib.VAR_DICT, {v_dict=NULL}, 'E731: Using a Dictionary as a String', ''}, - {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarNull}, nil, 'v:null'}, - {lib.VAR_BOOL, {v_bool=lib.kBoolVarTrue}, nil, 'v:true'}, - {lib.VAR_BOOL, {v_bool=lib.kBoolVarFalse}, nil, 'v:false'}, - {lib.VAR_UNKNOWN, nil, 'E908: Using an invalid value as a String', ''}, + { lib.VAR_NUMBER, { v_number = 42 }, nil, '42' }, + { lib.VAR_STRING, { v_string = to_cstr('100500') }, nil, '100500' }, + { lib.VAR_FLOAT, { v_float = 42.53 }, nil, '42.53' }, + { lib.VAR_PARTIAL, { v_partial = NULL }, 'E729: Using a Funcref as a String', '' }, + { lib.VAR_FUNC, { v_string = NULL }, 'E729: Using a Funcref as a String', '' }, + { lib.VAR_LIST, { v_list = NULL }, 'E730: Using a List as a String', '' }, + { lib.VAR_DICT, { v_dict = NULL }, 'E731: Using a Dictionary as a String', '' }, + { lib.VAR_SPECIAL, { v_special = lib.kSpecialVarNull }, nil, 'v:null' }, + { lib.VAR_BOOL, { v_bool = lib.kBoolVarTrue }, nil, 'v:true' }, + { lib.VAR_BOOL, { v_bool = lib.kBoolVarFalse }, nil, 'v:false' }, + { lib.VAR_UNKNOWN, nil, 'E908: Using an invalid value as a String', '' }, }, function(tv) return lib.tv_get_string(tv), buf end) @@ -3050,17 +3377,17 @@ describe('typval.c', function() itp('works', function() local buf = lib.tv_get_string_chk(lua2typvalt(int(1))) test_string_fn({ - {lib.VAR_NUMBER, {v_number=42}, nil, '42'}, - {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, '100500'}, - {lib.VAR_FLOAT, {v_float=42.53}, nil, '42.53'}, - {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: Using a Funcref as a String', nil}, - {lib.VAR_FUNC, {v_string=NULL}, 'E729: Using a Funcref as a String', nil}, - {lib.VAR_LIST, {v_list=NULL}, 'E730: Using a List as a String', nil}, - {lib.VAR_DICT, {v_dict=NULL}, 'E731: Using a Dictionary as a String', nil}, - {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarNull}, nil, 'v:null'}, - {lib.VAR_BOOL, {v_bool=lib.kBoolVarTrue}, nil, 'v:true'}, - {lib.VAR_BOOL, {v_bool=lib.kBoolVarFalse}, nil, 'v:false'}, - {lib.VAR_UNKNOWN, nil, 'E908: Using an invalid value as a String', nil}, + { lib.VAR_NUMBER, { v_number = 42 }, nil, '42' }, + { lib.VAR_STRING, { v_string = to_cstr('100500') }, nil, '100500' }, + { lib.VAR_FLOAT, { v_float = 42.53 }, nil, '42.53' }, + { lib.VAR_PARTIAL, { v_partial = NULL }, 'E729: Using a Funcref as a String', nil }, + { lib.VAR_FUNC, { v_string = NULL }, 'E729: Using a Funcref as a String', nil }, + { lib.VAR_LIST, { v_list = NULL }, 'E730: Using a List as a String', nil }, + { lib.VAR_DICT, { v_dict = NULL }, 'E731: Using a Dictionary as a String', nil }, + { lib.VAR_SPECIAL, { v_special = lib.kSpecialVarNull }, nil, 'v:null' }, + { lib.VAR_BOOL, { v_bool = lib.kBoolVarTrue }, nil, 'v:true' }, + { lib.VAR_BOOL, { v_bool = lib.kBoolVarFalse }, nil, 'v:false' }, + { lib.VAR_UNKNOWN, nil, 'E908: Using an invalid value as a String', nil }, }, function(tv) return lib.tv_get_string_chk(tv), buf end) @@ -3069,19 +3396,19 @@ describe('typval.c', function() describe('string_buf()', function() itp('works', function() test_string_fn({ - {lib.VAR_NUMBER, {v_number=42}, nil, '42'}, - {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, '100500'}, - {lib.VAR_FLOAT, {v_float=42.53}, nil, '42.53'}, - {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: Using a Funcref as a String', ''}, - {lib.VAR_FUNC, {v_string=NULL}, 'E729: Using a Funcref as a String', ''}, - {lib.VAR_LIST, {v_list=NULL}, 'E730: Using a List as a String', ''}, - {lib.VAR_DICT, {v_dict=NULL}, 'E731: Using a Dictionary as a String', ''}, - {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarNull}, nil, 'v:null'}, - {lib.VAR_BOOL, {v_bool=lib.kBoolVarTrue}, nil, 'v:true'}, - {lib.VAR_BOOL, {v_bool=lib.kBoolVarFalse}, nil, 'v:false'}, - {lib.VAR_UNKNOWN, nil, 'E908: Using an invalid value as a String', ''}, + { lib.VAR_NUMBER, { v_number = 42 }, nil, '42' }, + { lib.VAR_STRING, { v_string = to_cstr('100500') }, nil, '100500' }, + { lib.VAR_FLOAT, { v_float = 42.53 }, nil, '42.53' }, + { lib.VAR_PARTIAL, { v_partial = NULL }, 'E729: Using a Funcref as a String', '' }, + { lib.VAR_FUNC, { v_string = NULL }, 'E729: Using a Funcref as a String', '' }, + { lib.VAR_LIST, { v_list = NULL }, 'E730: Using a List as a String', '' }, + { lib.VAR_DICT, { v_dict = NULL }, 'E731: Using a Dictionary as a String', '' }, + { lib.VAR_SPECIAL, { v_special = lib.kSpecialVarNull }, nil, 'v:null' }, + { lib.VAR_BOOL, { v_bool = lib.kBoolVarTrue }, nil, 'v:true' }, + { lib.VAR_BOOL, { v_bool = lib.kBoolVarFalse }, nil, 'v:false' }, + { lib.VAR_UNKNOWN, nil, 'E908: Using an invalid value as a String', '' }, }, function(tv) - local buf = ffi.new('char[?]', lib.NUMBUFLEN, {0}) + local buf = ffi.new('char[?]', lib.NUMBUFLEN, { 0 }) return lib.tv_get_string_buf(tv, buf), buf end) end) @@ -3089,19 +3416,19 @@ describe('typval.c', function() describe('string_buf_chk()', function() itp('works', function() test_string_fn({ - {lib.VAR_NUMBER, {v_number=42}, nil, '42'}, - {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, '100500'}, - {lib.VAR_FLOAT, {v_float=42.53}, nil, '42.53'}, - {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: Using a Funcref as a String', nil}, - {lib.VAR_FUNC, {v_string=NULL}, 'E729: Using a Funcref as a String', nil}, - {lib.VAR_LIST, {v_list=NULL}, 'E730: Using a List as a String', nil}, - {lib.VAR_DICT, {v_dict=NULL}, 'E731: Using a Dictionary as a String', nil}, - {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarNull}, nil, 'v:null'}, - {lib.VAR_BOOL, {v_bool=lib.kBoolVarTrue}, nil, 'v:true'}, - {lib.VAR_BOOL, {v_bool=lib.kBoolVarFalse}, nil, 'v:false'}, - {lib.VAR_UNKNOWN, nil, 'E908: Using an invalid value as a String', nil}, + { lib.VAR_NUMBER, { v_number = 42 }, nil, '42' }, + { lib.VAR_STRING, { v_string = to_cstr('100500') }, nil, '100500' }, + { lib.VAR_FLOAT, { v_float = 42.53 }, nil, '42.53' }, + { lib.VAR_PARTIAL, { v_partial = NULL }, 'E729: Using a Funcref as a String', nil }, + { lib.VAR_FUNC, { v_string = NULL }, 'E729: Using a Funcref as a String', nil }, + { lib.VAR_LIST, { v_list = NULL }, 'E730: Using a List as a String', nil }, + { lib.VAR_DICT, { v_dict = NULL }, 'E731: Using a Dictionary as a String', nil }, + { lib.VAR_SPECIAL, { v_special = lib.kSpecialVarNull }, nil, 'v:null' }, + { lib.VAR_BOOL, { v_bool = lib.kBoolVarTrue }, nil, 'v:true' }, + { lib.VAR_BOOL, { v_bool = lib.kBoolVarFalse }, nil, 'v:false' }, + { lib.VAR_UNKNOWN, nil, 'E908: Using an invalid value as a String', nil }, }, function(tv) - local buf = ffi.new('char[?]', lib.NUMBUFLEN, {0}) + local buf = ffi.new('char[?]', lib.NUMBUFLEN, { 0 }) return lib.tv_get_string_buf_chk(tv, buf), buf end) end) |