0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

patch 9.1.0387: Vim9: null value tests not sufficient

Problem:  Vim9: null value tests not sufficient
Solution: Add a more comprehensive test for null values
          (Yegappan Lakshmanan)

closes: #14701

Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Yegappan Lakshmanan
2024-05-02 13:02:36 +02:00
committed by Christian Brabandt
parent 3ca2ae180a
commit da9d345b3d
7 changed files with 36 additions and 32 deletions

View File

@@ -6403,9 +6403,9 @@ echo_string_core(
{
class_T *cl = tv->vval.v_class;
char *s = "class";
if (cl && IS_INTERFACE(cl))
if (cl != NULL && IS_INTERFACE(cl))
s = "interface";
else if (cl && IS_ENUM(cl))
else if (cl != NULL && IS_ENUM(cl))
s = "enum";
size_t len = STRLEN(s) + 1 +
(cl == NULL ? 9 : STRLEN(cl->class_name)) + 1;

View File

@@ -3958,7 +3958,7 @@ f_empty(typval_T *argvars, typval_T *rettv)
|| *argvars[0].vval.v_string == NUL;
break;
case VAR_PARTIAL:
n = FALSE;
n = argvars[0].vval.v_partial == NULL;
break;
case VAR_NUMBER:
n = argvars[0].vval.v_number == 0;
@@ -11497,7 +11497,7 @@ f_type(typval_T *argvars, typval_T *rettv)
case VAR_CLASS:
{
class_T *cl = argvars[0].vval.v_class;
if (cl && IS_ENUM(cl))
if (cl != NULL && IS_ENUM(cl))
n = VAR_TYPE_ENUM;
else
n = VAR_TYPE_CLASS;

View File

@@ -4783,8 +4783,6 @@ def Test_typename()
if has('channel')
assert_equal('channel', test_null_channel()->typename())
endif
assert_equal('class<Unknown>', typename(null_class))
assert_equal('object<Unknown>', typename(null_object))
var l: list<func(list<number>): number> = [function('min')]
assert_equal('list<func(list<number>): number>', typename(l))
enddef

View File

@@ -560,7 +560,7 @@ def Test_using_null_class()
END
v9.CheckSourceSuccess(lines)
# Test for using a null class with string()
# Test for using a null class with type() and typename()
lines =<< trim END
vim9script
assert_equal(12, type(null_class))
@@ -569,30 +569,6 @@ def Test_using_null_class()
v9.CheckSourceSuccess(lines)
enddef
def Test_using_null_object()
# Test for using a null object as a value
var lines =<< trim END
vim9script
assert_equal(1, empty(null_object))
END
v9.CheckSourceSuccess(lines)
# Test for using a null object with string()
lines =<< trim END
vim9script
assert_equal('object of [unknown]', string(null_object))
END
v9.CheckSourceSuccess(lines)
# Test for using a null object with string()
lines =<< trim END
vim9script
assert_equal(13, type(null_object))
assert_equal('object<Unknown>', typename(null_object))
END
v9.CheckSourceSuccess(lines)
enddef
def Test_class_interface_wrong_end()
var lines =<< trim END
vim9script

View File

@@ -5055,6 +5055,34 @@ def Test_eval_lambda_block()
v9.CheckSourceSuccess(lines)
enddef
" Test for using various null values
def Test_null_values()
var lines =<< trim END
var nullValues = [
[null, 1, 'null', 7, 'special'],
[null_blob, 1, '0z', 10, 'blob'],
[null_channel, 1, 'channel fail', 9, 'channel'],
[null_dict, 1, '{}', 4, 'dict<any>'],
[null_function, 1, "function('')", 2, 'func(...): unknown'],
[null_job, 1, 'no process', 8, 'job'],
[null_list, 1, '[]', 3, 'list<any>'],
[null_object, 1, 'object of [unknown]', 13, 'object<Unknown>'],
[null_partial, 1, "function('')", 2, 'func(...): unknown'],
[null_string, 1, "''", 1, 'string']
]
for [Val, emptyExp, stringExp, typeExp, typenameExp] in nullValues
assert_equal(emptyExp, empty(Val))
assert_equal(stringExp, string(Val))
assert_equal(typeExp, type(Val))
assert_equal(typenameExp, typename(Val))
assert_equal(Val, copy(Val))
assert_equal(-1, test_refcount(Val))
endfor
END
v9.CheckSourceDefAndScriptSuccess(lines)
enddef
" Keep this last, it messes up highlighting.
def Test_substitute_cmd()
new

View File

@@ -704,6 +704,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
387,
/**/
386,
/**/

View File

@@ -2093,7 +2093,7 @@ check_typval_is_value(typval_T *tv)
class_T *cl = tv->vval.v_class;
char_u *class_name = (cl == NULL) ? (char_u *)""
: cl->class_name;
if (cl && IS_ENUM(cl))
if (cl != NULL && IS_ENUM(cl))
semsg(_(e_using_enum_as_value_str), class_name);
else
semsg(_(e_using_class_as_value_str), class_name);