From 42999a8d645ccf880222f0192671b8ce01bde361 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 30 Jan 2023 14:46:28 +0100 Subject: fix(test): fix issues detected by running unittests in ASAN/UBSAN --- test/unit/eval/typval_spec.lua | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'test/unit/eval') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 128625374e..825377813d 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -1677,7 +1677,7 @@ describe('typval.c', function() eq(nil, lib.tv_dict_find(nil, 'test', -1)) eq(nil, lib.tv_dict_find(nil, nil, 0)) end) - itp('works with NULL key', function() + itp('works with empty key', function() local lua_d = { ['']=0, t=1, @@ -1692,7 +1692,6 @@ describe('typval.c', function() alloc_log:check({}) local dis = dict_items(d) eq({0, '', dis['']}, {tv_dict_find(d, '', 0)}) - eq({0, '', dis['']}, {tv_dict_find(d, nil, 0)}) end) itp('works with len properly', function() local lua_d = { @@ -1910,8 +1909,6 @@ describe('typval.c', function() } local d = dict(lua_d) eq(lua_d, dct2tbl(d)) - eq({{type='fref', fref='tr'}, true}, - {tv_dict_get_callback(d, nil, 0)}) eq({{type='fref', fref='tr'}, true}, {tv_dict_get_callback(d, '', -1)}) eq({{type='none'}, true}, -- cgit From 6d267ad30cf539f520b46e3c92939f7031ce116f Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 23 Mar 2023 12:44:05 +0100 Subject: fix(api): make nvim_get_hl return 'cterm' attrs properly --- test/unit/eval/typval_spec.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'test/unit/eval') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 825377813d..ecee773ba8 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -1653,7 +1653,7 @@ describe('typval.c', function() 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()')) + 'E685: Internal error: hash_add(): duplicate key ""')) alloc_log:clear() lib.tv_dict_item_remove(d, di) alloc_log:check({ @@ -1947,7 +1947,7 @@ describe('typval.c', function() 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()')) + 'E685: Internal error: hash_add(): duplicate key "t-est"')) end) end) describe('list()', function() @@ -1964,7 +1964,7 @@ describe('typval.c', function() 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()')) + 'E685: Internal error: hash_add(): duplicate key "tes"')) eq(2, l.lv_refcount) alloc_log:clear() lib.emsg_skip = lib.emsg_skip + 1 @@ -1990,7 +1990,7 @@ describe('typval.c', function() 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()')) + 'E685: Internal error: hash_add(): duplicate key "tes"')) eq(2, d2.dv_refcount) alloc_log:clear() lib.emsg_skip = lib.emsg_skip + 1 @@ -2012,7 +2012,7 @@ describe('typval.c', function() 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()')) + '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, @@ -2032,7 +2032,7 @@ describe('typval.c', function() 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()')) + '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, @@ -2055,7 +2055,7 @@ describe('typval.c', function() }) 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()')) + '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, @@ -2085,7 +2085,7 @@ describe('typval.c', function() }) 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()')) + '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, -- cgit From d510bfbc8e447b1a60d5ec7faaa8f440eb4ef56f Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 2 Apr 2023 10:11:42 +0200 Subject: refactor: remove char_u (#22829) Closes https://github.com/neovim/neovim/issues/459 --- test/unit/eval/helpers.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/unit/eval') diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index b600f01ab2..9dd6b76de2 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -349,7 +349,7 @@ local special_vals = nil lua2typvalt = function(l, processed) if not special_vals then special_vals = { - [null_string] = {'VAR_STRING', {v_string=ffi.cast('char_u*', nil)}}, + [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}}, -- cgit From 8f69c5ed450337b9f77c50f9ee0d3eb32f649ca6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 14 Apr 2023 07:11:59 +0800 Subject: vim-patch:8.2.{0695,0725,0734,0753,0818,0819,0822} (#23075) vim-patch:8.2.0695: Vim9: cannot define a function inside a function Problem: Vim9: cannot define a function inside a function. Solution: Initial support for :def inside :def. https://github.com/vim/vim/commit/04b12697838b232b8b17c553ccc74cf1f1bdb81c vim-patch:8.2.0725: Vim9: cannot call a function declared later in Vim9 script Problem: Vim9: cannot call a function declared later in Vim9 script. Solution: Make two passes through the script file. https://github.com/vim/vim/commit/09689a02840be40fa7bb10b1921fb5bc5b2908f1 vim-patch:8.2.0734: Vim9: leaking memory when using :finish Problem: Vim9: leaking memory when using :finish. Solution: Do not check for next line in third pass. https://github.com/vim/vim/commit/04816717dfea6e2469ff4c9d40f68b59aaf03724 vim-patch:8.2.0753: Vim9: expressions are evaluated in the discovery phase Problem: Vim9: expressions are evaluated in the discovery phase. Solution: Bail out if an expression is not a constant. Require a type for declared constants. https://github.com/vim/vim/commit/32e351179eacfc84f64cd5029e221582d400bb38 vim-patch:8.2.0818: Vim9: using a discovery phase doesn't work well Problem: Vim9: using a discovery phase doesn't work well. Solution: Remove the discovery phase, instead compile a function only when it is used. Add :defcompile to compile def functions earlier. https://github.com/vim/vim/commit/822ba24743af9ee1b5e7f656a7a61a38f3638bca vim-patch:8.2.0819: compiler warning for unused variable Problem: Compiler warning for unused variable. Solution: Remove the variable. https://github.com/vim/vim/commit/f40e51a880a95f94dbbbecc9476559506c2cc345 vim-patch:8.2.0822: Vim9: code left over from discovery phase Problem: Vim9: code left over from discovery phase. Solution: Remove the dead code. https://github.com/vim/vim/commit/2eec37926db6d31beb36f162ac00357a30c093c8 Co-authored-by: Bram Moolenaar --- test/unit/eval/helpers.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/unit/eval') diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index 9dd6b76de2..0694fceaec 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -512,7 +512,7 @@ end local function eval0(expr) local tv = ffi.gc(ffi.new('typval_T', {v_type=eval.VAR_UNKNOWN}), eval.tv_clear) - if eval.eval0(to_cstr(expr), tv, nil, true) == 0 then + if eval.eval0(to_cstr(expr), tv, nil, eval.EVAL_EVALUATE) == 0 then return nil else return tv -- cgit From bd83b587b18bb6f2ac555a992fa5b7d907de7e79 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 14 Apr 2023 07:22:01 +0800 Subject: vim-patch:8.2.1047: Vim9: script cannot use line continuation like :def function Problem: Vim9: script cannot use line continuation like in a :def function. Solution: Pass the getline function pointer to the eval() functions. Use it for addition and multiplication operators. https://github.com/vim/vim/commit/5409f5d8c95007216ae1190565a7a8ee9ebd7100 Omit source_nextline() and eval_next_non_blank(): Vim9 script only. N/A patches for version.c: vim-patch:8.2.1048: build failure without the eval feature Problem: Build failure without the eval feature. Solution: Add dummy typedef. https://github.com/vim/vim/commit/9d40c63c7dc8c3eb3886c58dcd334bc7f37eceba vim-patch:8.2.1052: build failure with older compilers Problem: Build failure with older compilers. Solution: Move declaration to start of block. https://github.com/vim/vim/commit/7acde51832f383f9a6d2e740cd0420b433ea841a Co-authored-by: Bram Moolenaar --- test/unit/eval/helpers.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/unit/eval') diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index 0694fceaec..883f01bd84 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -512,7 +512,8 @@ end local function eval0(expr) local tv = ffi.gc(ffi.new('typval_T', {v_type=eval.VAR_UNKNOWN}), eval.tv_clear) - if eval.eval0(to_cstr(expr), tv, nil, eval.EVAL_EVALUATE) == 0 then + 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 return tv -- cgit From 75119fcc86e055895af824f7fdbba2f42c1cbbe8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 5 May 2023 07:02:43 +0800 Subject: vim-patch:8.2.3135: Vim9: builtin function arguments not checked at compile time Problem: Vim9: builtin function arguments not checked at compile time. Solution: Add more type checks. (Yegappan Lakshmanan, closes vim/vim#8539) https://github.com/vim/vim/commit/5b73992d8f82be7ac4b6f46c17f53ffb9640e5fa Co-authored-by: Yegappan Lakshmanan --- test/unit/eval/typval_spec.lua | 52 +++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'test/unit/eval') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index ecee773ba8..59d150e63f 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -1468,10 +1468,10 @@ describe('typval.c', function() local l = list(1, empty_list, {}) eq('', tv_list_find_str(l, 0, 'E806: using Float as a String')) - eq('', tv_list_find_str(l, 1, 'E730: using List as a String')) - eq('', tv_list_find_str(l, 2, 'E731: using Dictionary as a String')) - eq('', tv_list_find_str(l, -1, 'E731: using Dictionary as a String')) - eq('', tv_list_find_str(l, -2, 'E730: using List as a String')) + eq('', tv_list_find_str(l, 1, 'E730: Using a List as a String')) + eq('', tv_list_find_str(l, 2, 'E731: Using a Dictionary as a String')) + eq('', tv_list_find_str(l, -1, 'E731: Using a Dictionary as a String')) + eq('', tv_list_find_str(l, -2, 'E730: Using a List as a String')) eq('', tv_list_find_str(l, -3, 'E806: using Float as a String')) end) end) @@ -1745,7 +1745,7 @@ describe('typval.c', function() 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 Dictionary as a String'))) + '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) @@ -1785,7 +1785,7 @@ describe('typval.c', function() return s_ret end local d = ffi.gc(dict({test={}}), nil) - eq('', tv_dict_get_string_alloc(d, 'test', 'E731: using Dictionary as a String')) + 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) alloc_log:clear() eq(nil, tv_dict_get_string_alloc(d, 'test')) @@ -2832,10 +2832,10 @@ describe('typval.c', function() for _, v in ipairs({ {lib.VAR_NUMBER, nil}, {lib.VAR_FLOAT, 'E806: using Float as a String'}, - {lib.VAR_PARTIAL, 'E729: using Funcref as a String'}, - {lib.VAR_FUNC, 'E729: using Funcref as a String'}, - {lib.VAR_LIST, 'E730: using List as a String'}, - {lib.VAR_DICT, 'E731: using Dictionary as a String'}, + {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'}, @@ -2987,10 +2987,10 @@ describe('typval.c', function() {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}, 'E806: using Float as a String', ''}, - {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: using Funcref as a String', ''}, - {lib.VAR_FUNC, {v_string=NULL}, 'E729: using Funcref as a String', ''}, - {lib.VAR_LIST, {v_list=NULL}, 'E730: using List as a String', ''}, - {lib.VAR_DICT, {v_dict=NULL}, 'E731: using Dictionary as a String', ''}, + {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'}, @@ -3031,10 +3031,10 @@ describe('typval.c', function() {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}, 'E806: using Float as a String', nil}, - {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: using Funcref as a String', nil}, - {lib.VAR_FUNC, {v_string=NULL}, 'E729: using Funcref as a String', nil}, - {lib.VAR_LIST, {v_list=NULL}, 'E730: using List as a String', nil}, - {lib.VAR_DICT, {v_dict=NULL}, 'E731: using Dictionary as a String', nil}, + {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'}, @@ -3073,10 +3073,10 @@ describe('typval.c', function() {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}, 'E806: using Float as a String', ''}, - {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: using Funcref as a String', ''}, - {lib.VAR_FUNC, {v_string=NULL}, 'E729: using Funcref as a String', ''}, - {lib.VAR_LIST, {v_list=NULL}, 'E730: using List as a String', ''}, - {lib.VAR_DICT, {v_dict=NULL}, 'E731: using Dictionary as a String', ''}, + {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'}, @@ -3116,10 +3116,10 @@ describe('typval.c', function() {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}, 'E806: using Float as a String', nil}, - {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: using Funcref as a String', nil}, - {lib.VAR_FUNC, {v_string=NULL}, 'E729: using Funcref as a String', nil}, - {lib.VAR_LIST, {v_list=NULL}, 'E730: using List as a String', nil}, - {lib.VAR_DICT, {v_dict=NULL}, 'E731: using Dictionary as a String', nil}, + {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'}, -- cgit From 88cfb49bee3c9102082c7010acb92244e4ad1348 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 5 May 2023 07:14:39 +0800 Subject: vim-patch:8.2.4890: inconsistent capitalization in error messages Problem: Inconsistent capitalization in error messages. Solution: Make capitalization consistent. (Doug Kearns) https://github.com/vim/vim/commit/cf030578b26460643dca4a40e7f2e3bc19c749aa Co-authored-by: Bram Moolenaar --- test/unit/eval/typval_spec.lua | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'test/unit/eval') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 59d150e63f..7474d5ec99 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -1461,18 +1461,18 @@ describe('typval.c', function() itp('fails with error message when index is out of range', function() local l = list(int(1), int(2), int(3), int(4), int(5)) - eq(nil, tv_list_find_str(l, -6, 'E684: list index out of range: -6')) - eq(nil, tv_list_find_str(l, 5, 'E684: list index out of range: 5')) + eq(nil, tv_list_find_str(l, -6, 'E684: List index out of range: -6')) + eq(nil, tv_list_find_str(l, 5, 'E684: List index out of range: 5')) end) itp('fails with error message on invalid types', function() local l = list(1, empty_list, {}) - eq('', tv_list_find_str(l, 0, 'E806: using Float as a String')) + eq('', tv_list_find_str(l, 0, 'E806: Using Float as a String')) eq('', tv_list_find_str(l, 1, 'E730: Using a List as a String')) eq('', tv_list_find_str(l, 2, 'E731: Using a Dictionary as a String')) eq('', tv_list_find_str(l, -1, 'E731: Using a Dictionary as a String')) eq('', tv_list_find_str(l, -2, 'E730: Using a List as a String')) - eq('', tv_list_find_str(l, -3, 'E806: using Float as a String')) + eq('', tv_list_find_str(l, -3, 'E806: Using Float as a String')) end) end) end) @@ -1766,7 +1766,7 @@ describe('typval.c', function() eq(s43, dis.te.di_tv.vval.v_string) alloc_log:check({}) eq('', ffi.string(check_emsg(function() return lib.tv_dict_get_string(d, 't', false) end, - 'E806: using Float as a String'))) + 'E806: Using Float as a String'))) end) itp('allocates a string copy when requested', function() local function tv_dict_get_string_alloc(d, key, emsg) @@ -1792,7 +1792,7 @@ describe('typval.c', function() eq('42', tv_dict_get_string_alloc(d, 'tes')) eq('45', tv_dict_get_string_alloc(d, 'xx')) eq('43', tv_dict_get_string_alloc(d, 'te')) - eq('', tv_dict_get_string_alloc(d, 't', 'E806: using Float as a String')) + eq('', tv_dict_get_string_alloc(d, 't', 'E806: Using Float as a String')) end) end) describe('get_string_buf()', function() @@ -1827,7 +1827,7 @@ describe('typval.c', function() s, r, b = tv_dict_get_string_buf(d, 'test') neq(r, b) eq('tset', s) - s, r, b = tv_dict_get_string_buf(d, 't', nil, 'E806: using Float as a String') + s, r, b = tv_dict_get_string_buf(d, 't', nil, 'E806: Using Float as a String') neq(r, b) eq('', s) s, r, b = tv_dict_get_string_buf(d, 'te') @@ -1870,7 +1870,7 @@ describe('typval.c', function() neq(r, b) neq(r, def) eq('tset', s) - s, r, b, def = tv_dict_get_string_buf_chk(d, 'test', 1, nil, nil, 'E806: using Float as a String') + s, r, b, def = tv_dict_get_string_buf_chk(d, 'test', 1, nil, nil, 'E806: Using Float as a String') neq(r, b) neq(r, def) eq(nil, s) @@ -2831,14 +2831,14 @@ describe('typval.c', function() alloc_log:clear() for _, v in ipairs({ {lib.VAR_NUMBER, nil}, - {lib.VAR_FLOAT, 'E806: using Float as a String'}, + {lib.VAR_FLOAT, 'E806: Using Float as a String'}, {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_UNKNOWN, 'E908: Using an invalid value as a String'}, }) do local typ = v[1] local emsg = v[2] @@ -2986,7 +2986,7 @@ describe('typval.c', 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}, 'E806: using Float as a String', ''}, + {lib.VAR_FLOAT, {v_float=42.53}, 'E806: Using Float as a String', ''}, {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', ''}, @@ -2994,7 +2994,7 @@ describe('typval.c', function() {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_UNKNOWN, nil, 'E908: Using an invalid value as a String', ''}, }) do -- Using to_cstr in place of Neovim allocated string, cannot -- tv_clear() that. @@ -3030,7 +3030,7 @@ describe('typval.c', 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}, 'E806: using Float as a String', nil}, + {lib.VAR_FLOAT, {v_float=42.53}, 'E806: Using Float as a String', nil}, {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}, @@ -3038,7 +3038,7 @@ describe('typval.c', function() {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_UNKNOWN, nil, 'E908: Using an invalid value as a String', nil}, }) do -- Using to_cstr, cannot free with tv_clear local tv = ffi.gc(typvalt(v[1], v[2]), nil) @@ -3072,7 +3072,7 @@ describe('typval.c', 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}, 'E806: using Float as a String', ''}, + {lib.VAR_FLOAT, {v_float=42.53}, 'E806: Using Float as a String', ''}, {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', ''}, @@ -3080,7 +3080,7 @@ describe('typval.c', function() {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_UNKNOWN, nil, 'E908: Using an invalid value as a String', ''}, }) do -- Using to_cstr, cannot free with tv_clear local tv = ffi.gc(typvalt(v[1], v[2]), nil) @@ -3115,7 +3115,7 @@ describe('typval.c', 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}, 'E806: using Float as a String', nil}, + {lib.VAR_FLOAT, {v_float=42.53}, 'E806: Using Float as a String', nil}, {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}, @@ -3123,7 +3123,7 @@ describe('typval.c', function() {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_UNKNOWN, nil, 'E908: Using an invalid value as a String', nil}, }) do -- Using to_cstr, cannot free with tv_clear local tv = ffi.gc(typvalt(v[1], v[2]), nil) -- cgit From bdaaf2e8e113f8c32c70f83b60e0bf3f648357c1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 5 May 2023 09:00:35 +0800 Subject: vim-patch:9.0.0250: slightly inconsistent error messages Problem: Slightly inconsistent error messages. Solution: Make it "Using a Float". (closes vim/vim#10959) https://github.com/vim/vim/commit/dde77a7c4d72622284dc5fb72557bde42c314fa6 Co-authored-by: Bram Moolenaar --- test/unit/eval/typval_spec.lua | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'test/unit/eval') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 7474d5ec99..cde5a731cf 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -1467,12 +1467,12 @@ describe('typval.c', function() itp('fails with error message on invalid types', function() local l = list(1, empty_list, {}) - eq('', tv_list_find_str(l, 0, 'E806: Using Float as a String')) + eq('', tv_list_find_str(l, 0, 'E806: Using a Float as a String')) eq('', tv_list_find_str(l, 1, 'E730: Using a List as a String')) eq('', tv_list_find_str(l, 2, 'E731: Using a Dictionary as a String')) eq('', tv_list_find_str(l, -1, 'E731: Using a Dictionary as a String')) eq('', tv_list_find_str(l, -2, 'E730: Using a List as a String')) - eq('', tv_list_find_str(l, -3, 'E806: Using Float as a String')) + eq('', tv_list_find_str(l, -3, 'E806: Using a Float as a String')) end) end) end) @@ -1766,7 +1766,7 @@ describe('typval.c', function() eq(s43, dis.te.di_tv.vval.v_string) alloc_log:check({}) eq('', ffi.string(check_emsg(function() return lib.tv_dict_get_string(d, 't', false) end, - 'E806: Using Float as a String'))) + 'E806: Using a Float as a String'))) end) itp('allocates a string copy when requested', function() local function tv_dict_get_string_alloc(d, key, emsg) @@ -1792,7 +1792,7 @@ describe('typval.c', function() eq('42', tv_dict_get_string_alloc(d, 'tes')) eq('45', tv_dict_get_string_alloc(d, 'xx')) eq('43', tv_dict_get_string_alloc(d, 'te')) - eq('', tv_dict_get_string_alloc(d, 't', 'E806: Using Float as a String')) + eq('', tv_dict_get_string_alloc(d, 't', 'E806: Using a Float as a String')) end) end) describe('get_string_buf()', function() @@ -1827,7 +1827,7 @@ describe('typval.c', function() s, r, b = tv_dict_get_string_buf(d, 'test') neq(r, b) eq('tset', s) - s, r, b = tv_dict_get_string_buf(d, 't', nil, 'E806: Using Float as a String') + s, r, b = tv_dict_get_string_buf(d, 't', nil, 'E806: Using a Float as a String') neq(r, b) eq('', s) s, r, b = tv_dict_get_string_buf(d, 'te') @@ -1870,7 +1870,7 @@ describe('typval.c', function() neq(r, b) neq(r, def) eq('tset', s) - s, r, b, def = tv_dict_get_string_buf_chk(d, 'test', 1, nil, nil, 'E806: Using Float as a String') + s, r, b, def = tv_dict_get_string_buf_chk(d, 'test', 1, nil, nil, 'E806: Using a Float as a String') neq(r, b) neq(r, def) eq(nil, s) @@ -2831,7 +2831,7 @@ describe('typval.c', function() alloc_log:clear() for _, v in ipairs({ {lib.VAR_NUMBER, nil}, - {lib.VAR_FLOAT, 'E806: Using Float as a String'}, + {lib.VAR_FLOAT, 'E806: Using a Float as a String'}, {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'}, @@ -2986,7 +2986,7 @@ describe('typval.c', 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}, 'E806: Using Float as a String', ''}, + {lib.VAR_FLOAT, {v_float=42.53}, 'E806: Using a Float as a String', ''}, {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', ''}, @@ -3030,7 +3030,7 @@ describe('typval.c', 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}, 'E806: Using Float as a String', nil}, + {lib.VAR_FLOAT, {v_float=42.53}, 'E806: Using a Float as a String', nil}, {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}, @@ -3072,7 +3072,7 @@ describe('typval.c', 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}, 'E806: Using Float as a String', ''}, + {lib.VAR_FLOAT, {v_float=42.53}, 'E806: Using a Float as a String', ''}, {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', ''}, @@ -3115,7 +3115,7 @@ describe('typval.c', 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}, 'E806: Using Float as a String', nil}, + {lib.VAR_FLOAT, {v_float=42.53}, 'E806: Using a Float as a String', nil}, {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}, -- cgit From 1ffd20a26eeb360bc0d2fe8e36120d43134b465a Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Fri, 24 Sep 2021 22:42:31 +0100 Subject: test(unit/eval/typval_spec): don't dereference NULL last_msg_hist If last_msg_hist is NULL, check_emsg will cause the running test process to SIGSEGV from trying to access the msg member. --- test/unit/eval/typval_spec.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'test/unit/eval') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index cde5a731cf..5e8677c69d 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -101,12 +101,13 @@ local function check_emsg(f, msg) saved_last_msg_hist = nil end 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, ffi.string(lib.last_msg_hist.msg)) + eq(msg, last_msg) neq(saved_last_msg_hist, lib.last_msg_hist) else if saved_last_msg_hist ~= lib.last_msg_hist then - eq(nil, ffi.string(lib.last_msg_hist.msg)) + eq(nil, last_msg) else eq(saved_last_msg_hist, lib.last_msg_hist) end -- cgit From 41ee7bc7dbcca4ce3d35c13450220d3bffcad15e Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Sat, 11 Sep 2021 21:25:29 +0100 Subject: test(unit/eval/typval_spec): adjust for Float to String conversion Adjust relevant Lua tests. Refactor testing logic for tv_get_string_* functions into test_string_fn(). Note that vim_snprintf(), which is used for stringifying floats, always calls xfree(tofree), even if tofree is NULL, so we need to expect that in the alloc log. --- test/unit/eval/typval_spec.lua | 228 ++++++++++++++++------------------------- 1 file changed, 90 insertions(+), 138 deletions(-) (limited to 'test/unit/eval') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 5e8677c69d..a60700287f 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -1430,15 +1430,16 @@ describe('typval.c', function() end describe('str()', function() itp('returns correct string', function() - local l = list(int(1), int(2), int(3), int(4), int(5)) + local l = list(int(1), 2.5, int(3), int(4), int(5)) alloc_log:clear() eq('1', tv_list_find_str(l, -5)) + eq('2.5', tv_list_find_str(l, 1)) eq('5', tv_list_find_str(l, 4)) eq('3', tv_list_find_str(l, 2)) eq('3', tv_list_find_str(l, -3)) - alloc_log:check({}) + alloc_log:check({a.freed(alloc_log.null)}) end) itp('returns string when used with VAR_STRING items', function() local l = list('1', '2', '3', '4', '5') @@ -1466,14 +1467,12 @@ describe('typval.c', function() eq(nil, tv_list_find_str(l, 5, 'E684: List index out of range: 5')) end) itp('fails with error message on invalid types', function() - local l = list(1, empty_list, {}) + local l = list(empty_list, {}) - eq('', tv_list_find_str(l, 0, 'E806: Using a Float as a String')) - eq('', tv_list_find_str(l, 1, 'E730: Using a List as a String')) - eq('', tv_list_find_str(l, 2, 'E731: Using a Dictionary as a String')) + eq('', tv_list_find_str(l, 0, 'E730: Using a List as a String')) + eq('', tv_list_find_str(l, 1, 'E731: Using a Dictionary as a String')) eq('', tv_list_find_str(l, -1, 'E731: Using a Dictionary as a String')) eq('', tv_list_find_str(l, -2, 'E730: Using a List as a String')) - eq('', tv_list_find_str(l, -3, 'E806: Using a Float as a String')) end) end) end) @@ -1766,18 +1765,24 @@ describe('typval.c', function() neq(s42, s43) eq(s43, dis.te.di_tv.vval.v_string) alloc_log:check({}) - eq('', ffi.string(check_emsg(function() return lib.tv_dict_get_string(d, 't', false) end, - 'E806: Using a Float as a String'))) + 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)}) end) itp('allocates a string copy when requested', function() - local function tv_dict_get_string_alloc(d, key, emsg) + 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 s_ret = (ret ~= nil) and ffi.string(ret) or nil if not emsg then if s_ret then - alloc_log:check({a.str(ret, s_ret)}) + if is_float then + alloc_log:check({a.freed(alloc_log.null), a.str(ret, s_ret)}) + else + alloc_log:check({a.str(ret, s_ret)}) + end else alloc_log:check({}) end @@ -1793,18 +1798,22 @@ describe('typval.c', function() eq('42', tv_dict_get_string_alloc(d, 'tes')) eq('45', tv_dict_get_string_alloc(d, 'xx')) eq('43', tv_dict_get_string_alloc(d, 'te')) - eq('', tv_dict_get_string_alloc(d, 't', 'E806: Using a Float as a String')) + eq('44.0', tv_dict_get_string_alloc(d, 't', nil, true)) end) end) describe('get_string_buf()', function() - local function tv_dict_get_string_buf(d, key, buf, emsg) + 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 s_ret = (ret ~= nil) and ffi.string(ret) or nil if not emsg then - alloc_log:check({}) + if is_float then + alloc_log:check({a.freed(alloc_log.null)}) + else + alloc_log:check({}) + end end return s_ret, ret, buf end @@ -1828,16 +1837,16 @@ describe('typval.c', function() s, r, b = tv_dict_get_string_buf(d, 'test') neq(r, b) eq('tset', s) - s, r, b = tv_dict_get_string_buf(d, 't', nil, 'E806: Using a Float as a String') - neq(r, b) - eq('', s) + s, r, b = tv_dict_get_string_buf(d, 't', true) + eq(r, b) + eq('1.0', s) s, r, b = tv_dict_get_string_buf(d, 'te') eq(r, b) eq('2', s) end) end) describe('get_string_buf_chk()', function() - local function tv_dict_get_string_buf_chk(d, key, len, buf, def, emsg) + local function tv_dict_get_string_buf_chk(d, key, is_float, len, buf, def, emsg) buf = buf or ffi.gc(lib.xmalloc(lib.NUMBUFLEN), lib.xfree) def = def or ffi.gc(lib.xstrdup('DEFAULT'), lib.xfree) len = len or #key @@ -1846,7 +1855,11 @@ describe('typval.c', function() emsg) local s_ret = (ret ~= nil) and ffi.string(ret) or nil if not emsg then - alloc_log:check({}) + if is_float then + alloc_log:check({a.freed(alloc_log.null)}) + else + alloc_log:check({}) + end end return s_ret, ret, buf, def end @@ -1871,10 +1884,10 @@ describe('typval.c', function() neq(r, b) neq(r, def) eq('tset', s) - s, r, b, def = tv_dict_get_string_buf_chk(d, 'test', 1, nil, nil, 'E806: Using a Float as a String') - neq(r, b) + s, r, b, def = tv_dict_get_string_buf_chk(d, 'test', true, 1) + eq(r, b) neq(r, def) - eq(nil, s) + eq('1.0', s) s, r, b, def = tv_dict_get_string_buf_chk(d, 'te') eq(r, b) neq(r, def) @@ -2832,7 +2845,7 @@ describe('typval.c', function() alloc_log:clear() for _, v in ipairs({ {lib.VAR_NUMBER, nil}, - {lib.VAR_FLOAT, 'E806: Using a Float as a String'}, + {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'}, @@ -2979,15 +2992,47 @@ describe('typval.c', function() end end) end) + + local function test_string_fn(input, fn) + for _, v in ipairs(input) do + -- Using to_cstr in place of Neovim allocated string, cannot + -- tv_clear() that. + 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() + 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)}) + else + alloc_log:check({}) + end + end + end describe('string()', function() itp('works', function() local buf = lib.tv_get_string(lua2typvalt(int(1))) local buf_chk = lib.tv_get_string_chk(lua2typvalt(int(1))) neq(buf, buf_chk) - for _, v in ipairs({ + 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}, 'E806: Using a Float as a String', ''}, + {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', ''}, @@ -2996,42 +3041,18 @@ describe('typval.c', function() {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', ''}, - }) do - -- Using to_cstr in place of Neovim allocated string, cannot - -- tv_clear() that. - 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() - local res = lib.tv_get_string(tv) - if tv.v_type == lib.VAR_NUMBER 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() - else - alloc_log:check({}) - end - end + }, function(tv) + return lib.tv_get_string(tv), buf + end) end) end) describe('string_chk()', function() itp('works', function() local buf = lib.tv_get_string_chk(lua2typvalt(int(1))) - for _, v in ipairs({ + 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}, 'E806: Using a Float as a String', nil}, + {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}, @@ -3040,40 +3061,17 @@ describe('typval.c', function() {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}, - }) 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() - local res = lib.tv_get_string_chk(tv) - if tv.v_type == lib.VAR_NUMBER 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() - else - alloc_log:check({}) - end - end + }, function(tv) + return lib.tv_get_string_chk(tv), buf + end) end) end) describe('string_buf()', function() itp('works', function() - for _, v in ipairs({ + 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}, 'E806: Using a Float as a String', ''}, + {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', ''}, @@ -3082,41 +3080,18 @@ describe('typval.c', function() {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', ''}, - }) 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() - local buf = ffi.new('char[?]', lib.NUMBUFLEN, {0}) - local res = lib.tv_get_string_buf(tv, buf) - if tv.v_type == lib.VAR_NUMBER 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() - else - alloc_log:check({}) - end - end + }, function(tv) + local buf = ffi.new('char[?]', lib.NUMBUFLEN, {0}) + return lib.tv_get_string_buf(tv, buf), buf + end) end) end) describe('string_buf_chk()', function() itp('works', function() - for _, v in ipairs({ + 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}, 'E806: Using a Float as a String', nil}, + {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}, @@ -3125,33 +3100,10 @@ describe('typval.c', function() {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}, - }) 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() - local buf = ffi.new('char[?]', lib.NUMBUFLEN, {0}) - local res = lib.tv_get_string_buf_chk(tv, buf) - if tv.v_type == lib.VAR_NUMBER 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() - else - alloc_log:check({}) - end - end + }, function(tv) + local buf = ffi.new('char[?]', lib.NUMBUFLEN, {0}) + return lib.tv_get_string_buf_chk(tv, buf), buf + end) end) end) end) -- cgit From 842a47d6a4103a75e33c2c0023dbae5ad2c0f534 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 15 Aug 2023 19:16:19 +0800 Subject: vim-patch:9.0.1704: Cannot use positional arguments for printf() (#24719) Problem: Cannot use positional arguments for printf() Solution: Support positional arguments in string formatting closes: vim/vim#12140 https://github.com/vim/vim/commit/0c6181fec4c362eb9682d5af583341eb20cb1af5 Co-authored-by: Christ van Willegen --- test/unit/eval/typval_spec.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'test/unit/eval') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index a60700287f..6fb8ba5a1c 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -1439,7 +1439,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)}) + 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') @@ -1768,7 +1768,7 @@ describe('typval.c', function() 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)}) + 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) @@ -1779,7 +1779,7 @@ describe('typval.c', function() if not emsg then if s_ret then if is_float then - alloc_log:check({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)}) end @@ -1810,7 +1810,7 @@ describe('typval.c', function() 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)}) + alloc_log:check({a.freed(alloc_log.null), a.freed(alloc_log.null)}) else alloc_log:check({}) end @@ -1856,7 +1856,7 @@ describe('typval.c', function() 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)}) + alloc_log:check({a.freed(alloc_log.null), a.freed(alloc_log.null)}) else alloc_log:check({}) end @@ -3018,7 +3018,7 @@ describe('typval.c', function() if emsg then alloc_log:clear() elseif tv.v_type == lib.VAR_FLOAT then - alloc_log:check({a.freed(alloc_log.null)}) + alloc_log:check({a.freed(alloc_log.null), a.freed(alloc_log.null)}) else alloc_log:check({}) end -- cgit From 79b6ff28ad1204fbb4199b9092f5c578d88cb28e Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 28 Nov 2023 20:31:00 +0100 Subject: refactor: fix headers with IWYU --- test/unit/eval/typval_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/unit/eval') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 6fb8ba5a1c..34a1299725 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -43,7 +43,7 @@ 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.h', + './src/nvim/eval.h', './src/nvim/vim_defs.h', './src/nvim/globals.h') local function vimconv_alloc() -- cgit