aboutsummaryrefslogtreecommitdiff
path: root/test/unit/eval/typval_spec.lua
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2017-07-02 19:01:09 +0300
committerZyX <kp-pav@yandex.ru>2017-07-02 19:01:09 +0300
commitdf040e55fbd3edc5a36462af927a7194d079d0b8 (patch)
tree45ac6b4f7e8024dff5b2295b58007482d5f87496 /test/unit/eval/typval_spec.lua
parent6140396d97d700ab6390b4ecfc4fd7da0ebdfd9f (diff)
downloadrneovim-df040e55fbd3edc5a36462af927a7194d079d0b8.tar.gz
rneovim-df040e55fbd3edc5a36462af927a7194d079d0b8.tar.bz2
rneovim-df040e55fbd3edc5a36462af927a7194d079d0b8.zip
eval/typval: Add tv_dict_add_allocated_str() function
Diffstat (limited to 'test/unit/eval/typval_spec.lua')
-rw-r--r--test/unit/eval/typval_spec.lua32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua
index 5d543f914f..33d5bb28be 100644
--- a/test/unit/eval/typval_spec.lua
+++ b/test/unit/eval/typval_spec.lua
@@ -1963,6 +1963,38 @@ describe('typval.c', function()
alloc_log:check({})
end)
end)
+ describe('allocated_str()', function()
+ itp('works', function()
+ local d = dict({test=10})
+ eq({test=10}, dct2tbl(d))
+ alloc_log:clear()
+ local s1 = lib.xstrdup('TEST')
+ local s2 = lib.xstrdup('TEST')
+ local s3 = lib.xstrdup('TEST')
+ alloc_log:check({
+ a.str(s1, 'TEST'),
+ a.str(s2, 'TEST'),
+ a.str(s3, 'TEST'),
+ })
+ eq(OK, lib.tv_dict_add_allocated_str(d, 'testt', 3, s1))
+ local dis = dict_items(d)
+ 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()'))
+ 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))
+ lib.emsg_skip = lib.emsg_skip - 1
+ alloc_log:clear_tmp_allocs()
+ alloc_log:check({
+ a.freed(s3),
+ })
+ end)
+ end)
end)
describe('clear()', function()
itp('works', function()