aboutsummaryrefslogtreecommitdiff
path: root/test/unit/eval/typval_spec.lua
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2017-12-24 01:43:42 +0300
committerZyX <kp-pav@yandex.ru>2017-12-24 14:09:35 +0300
commit0c533a488fbe453ae39017a586eff7813da8ed8a (patch)
treed20d469a3f065f48ab81fb12a728f7617ee08830 /test/unit/eval/typval_spec.lua
parent249bdb07dd3a9555972deff625d67e4ee0eddc86 (diff)
downloadrneovim-0c533a488fbe453ae39017a586eff7813da8ed8a.tar.gz
rneovim-0c533a488fbe453ae39017a586eff7813da8ed8a.tar.bz2
rneovim-0c533a488fbe453ae39017a586eff7813da8ed8a.zip
*: Remove most calls to tv_list_item_alloc
Still left calls in eval/typval.c and test/unit/eval/helpers.lua. Latter is the only reason why function did not receive `static` modifier.
Diffstat (limited to 'test/unit/eval/typval_spec.lua')
-rw-r--r--test/unit/eval/typval_spec.lua60
1 files changed, 60 insertions, 0 deletions
diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua
index bec74f05fc..2ae69ec04b 100644
--- a/test/unit/eval/typval_spec.lua
+++ b/test/unit/eval/typval_spec.lua
@@ -678,6 +678,66 @@ describe('typval.c', function()
eq({int(-100500), int(100500)}, typvalt2lua(l_tv))
end)
end)
+ describe('tv()', function()
+ itp('works', function()
+ local l_tv = lua2typvalt(empty_list)
+ local l = l_tv.vval.v_list
+
+ local l_l_tv = lua2typvalt(empty_list)
+ alloc_log:clear()
+ local l_l = l_l_tv.vval.v_list
+ eq(1, l_l.lv_refcount)
+ lib.tv_list_append_tv(l, l_l_tv)
+ eq(2, l_l.lv_refcount)
+ eq(l_l, l.lv_first.li_tv.vval.v_list)
+ alloc_log:check({
+ a.li(l.lv_first),
+ })
+
+ local l_s_tv = lua2typvalt('test')
+ alloc_log:check({
+ a.str(l_s_tv.vval.v_string, 'test'),
+ })
+ lib.tv_list_append_tv(l, l_s_tv)
+ alloc_log:check({
+ a.li(l.lv_last),
+ a.str(l.lv_last.li_tv.vval.v_string, 'test'),
+ })
+
+ eq({empty_list, 'test'}, typvalt2lua(l_tv))
+ end)
+ end)
+ describe('owned tv()', function()
+ itp('works', function()
+ local l_tv = lua2typvalt(empty_list)
+ local l = l_tv.vval.v_list
+
+ local l_l_tv = lua2typvalt(empty_list)
+ alloc_log:clear()
+ local l_l = l_l_tv.vval.v_list
+ eq(1, l_l.lv_refcount)
+ lib.tv_list_append_owned_tv(l, l_l_tv)
+ eq(1, l_l.lv_refcount)
+ l_l.lv_refcount = l_l.lv_refcount + 1
+ eq(l_l, l.lv_first.li_tv.vval.v_list)
+ alloc_log:check({
+ a.li(l.lv_first),
+ })
+
+ local l_s_tv = ffi.gc(lua2typvalt('test'), nil)
+ alloc_log:check({
+ a.str(l_s_tv.vval.v_string, 'test'),
+ })
+ lib.tv_list_append_owned_tv(l, l_s_tv)
+ eq(l_s_tv.vval.v_string, l.lv_last.li_tv.vval.v_string)
+ l_s_tv.vval.v_string = nil
+ alloc_log:check({
+ a.li(l.lv_last),
+ })
+
+ eq({empty_list, 'test'}, typvalt2lua(l_tv))
+ end)
+ end)
end)
describe('copy()', function()
local function tv_list_copy(...)