mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
unittests: Test tv_copy()
This commit is contained in:
parent
f0bbd1e825
commit
ed4948a933
@ -132,10 +132,10 @@ local function typvalt2lua_tab_init()
|
|||||||
typvalt2lua_tab = {
|
typvalt2lua_tab = {
|
||||||
[tonumber(eval.VAR_SPECIAL)] = function(t)
|
[tonumber(eval.VAR_SPECIAL)] = function(t)
|
||||||
return ({
|
return ({
|
||||||
[eval.kSpecialVarFalse] = false,
|
[tonumber(eval.kSpecialVarFalse)] = false,
|
||||||
[eval.kSpecialVarNull] = nil_value,
|
[tonumber(eval.kSpecialVarNull)] = nil_value,
|
||||||
[eval.kSpecialVarTrue] = true,
|
[tonumber(eval.kSpecialVarTrue)] = true,
|
||||||
})[t.vval.v_special]
|
})[tonumber(t.vval.v_special)]
|
||||||
end,
|
end,
|
||||||
[tonumber(eval.VAR_NUMBER)] = function(t)
|
[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)}
|
||||||
|
@ -25,6 +25,7 @@ local typvalt = eval_helpers.typvalt
|
|||||||
local type_key = eval_helpers.type_key
|
local type_key = eval_helpers.type_key
|
||||||
local li_alloc = eval_helpers.li_alloc
|
local li_alloc = eval_helpers.li_alloc
|
||||||
local first_di = eval_helpers.first_di
|
local first_di = eval_helpers.first_di
|
||||||
|
local nil_value = eval_helpers.nil_value
|
||||||
local func_type = eval_helpers.func_type
|
local func_type = eval_helpers.func_type
|
||||||
local null_list = eval_helpers.null_list
|
local null_list = eval_helpers.null_list
|
||||||
local null_dict = eval_helpers.null_dict
|
local null_dict = eval_helpers.null_dict
|
||||||
@ -2223,6 +2224,9 @@ describe('typval.c', function()
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
local function defalloc()
|
||||||
|
return {}
|
||||||
|
end
|
||||||
describe('clear()', function()
|
describe('clear()', function()
|
||||||
itp('works', function()
|
itp('works', function()
|
||||||
local function deffrees(alloc_rets)
|
local function deffrees(alloc_rets)
|
||||||
@ -2232,9 +2236,6 @@ describe('typval.c', function()
|
|||||||
end
|
end
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
local function defalloc()
|
|
||||||
return {}
|
|
||||||
end
|
|
||||||
alloc_log:check({})
|
alloc_log:check({})
|
||||||
lib.tv_clear(nil)
|
lib.tv_clear(nil)
|
||||||
alloc_log:check({})
|
alloc_log:check({})
|
||||||
@ -2244,12 +2245,13 @@ describe('typval.c', function()
|
|||||||
local dd = {}
|
local dd = {}
|
||||||
dd.dd = dd
|
dd.dd = dd
|
||||||
for _, v in ipairs({
|
for _, v in ipairs({
|
||||||
{nil},
|
{nil_value},
|
||||||
{null_string, nil, function() return {a.freed(alloc_log.null)} end},
|
{null_string, nil, function() return {a.freed(alloc_log.null)} end},
|
||||||
{0},
|
{0},
|
||||||
{int(0)},
|
{int(0)},
|
||||||
{true},
|
{true},
|
||||||
{false},
|
{false},
|
||||||
|
{'true', function(tv) return {a.str(tv.vval.v_string)} end},
|
||||||
{{}, function(tv) return {a.dict(tv.vval.v_dict)} end},
|
{{}, function(tv) return {a.dict(tv.vval.v_dict)} end},
|
||||||
{empty_list, function(tv) return {a.list(tv.vval.v_list)} end},
|
{empty_list, function(tv) return {a.list(tv.vval.v_list)} end},
|
||||||
{ll, function(tv)
|
{ll, function(tv)
|
||||||
@ -2271,5 +2273,42 @@ describe('typval.c', function()
|
|||||||
eq(1, dd_d.dv_refcount)
|
eq(1, dd_d.dv_refcount)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
describe('copy()', function()
|
||||||
|
itp('works', function()
|
||||||
|
local function strallocs(tv)
|
||||||
|
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},
|
||||||
|
}) do
|
||||||
|
local from = lua2typvalt(v[1])
|
||||||
|
alloc_log:check((v[2] or defalloc)(from))
|
||||||
|
local to = typvalt(lib.VAR_UNKNOWN)
|
||||||
|
lib.tv_copy(from, to)
|
||||||
|
local res = v[1]
|
||||||
|
eq(res, typvalt2lua(to))
|
||||||
|
alloc_log:check((v[3] or defalloc)(to))
|
||||||
|
if v[4] then
|
||||||
|
v[4](from, to)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user