diff options
-rw-r--r-- | test/unit/eval/typval_spec.lua | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 2c9b7c66db..382ec79429 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -27,7 +27,7 @@ local typvalt2lua = eval_helpers.typvalt2lua local null_string = eval_helpers.null_string local lib = cimport('./src/nvim/eval/typval.h', './src/nvim/memory.h', - './src/nvim/mbyte.h') + './src/nvim/mbyte.h', './src/nvim/garray.h') local function list_items(l) local lis = {} @@ -95,6 +95,13 @@ after_each(function() alloc_log:after_each() end) +local function ga_alloc(itemsize, growsize) + 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 + describe('typval.c', function() describe('list', function() describe('item', function() @@ -1025,4 +1032,38 @@ describe('typval.c', function() end) end) end) + describe('join()', function() + local function list_join(l, sep, ret) + local ga = ga_alloc() + eq(ret or OK, lib.tv_list_join(ga, l, sep)) + if ga.ga_data == nil then return '' + else return ffi.string(ga.ga_data) + end + end + it('works', function() + local l + l = list('boo', 'far') + eq('boo far', list_join(l, ' ')) + eq('boofar', list_join(l, '')) + + l = list('boo') + eq('boo', list_join(l, ' ')) + + l = list() + eq('', list_join(l, ' ')) + + l = list({}, 'far') + eq('{} far', list_join(l, ' ')) + + local recursive_list = {} + recursive_list[1] = recursive_list + l = ffi.gc(list(recursive_list, 'far'), nil) + eq('[[...@0]] far', list_join(l, ' ')) + + local recursive_l = l.lv_first.li_tv.vval.v_list + local recursive_li = recursive_l.lv_first + lib.tv_list_item_remove(recursive_l, recursive_li) + lib.tv_list_free(l, true) + end) + end) end) |