Mercurial > vim
comparison src/testdir/test_vim9_assign.vim @ 33874:902b7bdf2afb v9.0.2147
patch 9.0.2147: Type check tests fail without the channel feature
Commit: https://github.com/vim/vim/commit/3ee25965e4fbf9f44f5fc31d6a827638e409c6f8
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Mon Dec 4 20:31:14 2023 +0100
patch 9.0.2147: Type check tests fail without the channel feature
Problem: Type check tests fail without the channel feature
Solution: only run tests, when Vim was build with +channel
fixes: #13617
closes: #13619
Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 10 Dec 2023 15:16:12 +0100 |
parents | 1a0886e98382 |
children | cd7acb9bc4fd |
comparison
equal
deleted
inserted
replaced
33873:1e3f2847297a | 33874:902b7bdf2afb |
---|---|
3068 var S: string = 'abc' | 3068 var S: string = 'abc' |
3069 var d: dict<number> = {} | 3069 var d: dict<number> = {} |
3070 var l: list<number> = [] | 3070 var l: list<number> = [] |
3071 var b: blob = 0z10 | 3071 var b: blob = 0z10 |
3072 var Fn: func = function('min') | 3072 var Fn: func = function('min') |
3073 var j: job = test_null_job() | |
3074 var ch: channel = test_null_channel() | |
3075 var o: A = A.new() | 3073 var o: A = A.new() |
3076 | 3074 |
3077 # Assign a number | 3075 # Assign a number |
3078 assert_fails('d = N', 'E1012: Type mismatch; expected dict<number> but got number') | 3076 assert_fails('d = N', 'E1012: Type mismatch; expected dict<number> but got number') |
3079 assert_fails('l = N', 'E1012: Type mismatch; expected list<number> but got number') | 3077 assert_fails('l = N', 'E1012: Type mismatch; expected list<number> but got number') |
3080 assert_fails('b = N', 'E1012: Type mismatch; expected blob but got number') | 3078 assert_fails('b = N', 'E1012: Type mismatch; expected blob but got number') |
3081 assert_fails('Fn = N', 'E1012: Type mismatch; expected func(...): unknown but got number') | 3079 assert_fails('Fn = N', 'E1012: Type mismatch; expected func(...): unknown but got number') |
3082 assert_fails('j = N', 'E1012: Type mismatch; expected job but got number') | |
3083 assert_fails('ch = N', 'E1012: Type mismatch; expected channel but got number') | |
3084 assert_fails('A = N', 'E1012: Type mismatch; expected class<A> but got number') | 3080 assert_fails('A = N', 'E1012: Type mismatch; expected class<A> but got number') |
3085 assert_fails('o = N', 'E1012: Type mismatch; expected object<A> but got number') | 3081 assert_fails('o = N', 'E1012: Type mismatch; expected object<A> but got number') |
3086 | 3082 |
3087 # Use a compound operator with different LHS types | 3083 # Use a compound operator with different LHS types |
3088 assert_fails('d += N', 'E734: Wrong variable type for +=') | 3084 assert_fails('d += N', 'E734: Wrong variable type for +=') |
3089 assert_fails('l += N', 'E734: Wrong variable type for +=') | 3085 assert_fails('l += N', 'E734: Wrong variable type for +=') |
3090 assert_fails('b += N', 'E734: Wrong variable type for +=') | 3086 assert_fails('b += N', 'E734: Wrong variable type for +=') |
3091 assert_fails('Fn += N', 'E734: Wrong variable type for +=') | 3087 assert_fails('Fn += N', 'E734: Wrong variable type for +=') |
3092 assert_fails('j += N', 'E734: Wrong variable type for +=') | |
3093 assert_fails('ch += N', 'E734: Wrong variable type for +=') | |
3094 assert_fails('A += N', 'E734: Wrong variable type for +=') | 3088 assert_fails('A += N', 'E734: Wrong variable type for +=') |
3095 assert_fails('o += N', 'E734: Wrong variable type for +=') | 3089 assert_fails('o += N', 'E734: Wrong variable type for +=') |
3096 | 3090 |
3097 # Assign to a number variable | 3091 # Assign to a number variable |
3098 assert_fails('N = d', 'E1012: Type mismatch; expected number but got dict<number>') | 3092 assert_fails('N = d', 'E1012: Type mismatch; expected number but got dict<number>') |
3099 assert_fails('N = l', 'E1012: Type mismatch; expected number but got list<number>') | 3093 assert_fails('N = l', 'E1012: Type mismatch; expected number but got list<number>') |
3100 assert_fails('N = b', 'E1012: Type mismatch; expected number but got blob') | 3094 assert_fails('N = b', 'E1012: Type mismatch; expected number but got blob') |
3101 assert_fails('N = Fn', 'E1012: Type mismatch; expected number but got func([unknown]): number') | 3095 assert_fails('N = Fn', 'E1012: Type mismatch; expected number but got func([unknown]): number') |
3102 assert_fails('N = j', 'E1012: Type mismatch; expected number but got job') | |
3103 assert_fails('N = ch', 'E1012: Type mismatch; expected number but got channel') | |
3104 assert_fails('N = A', 'E1012: Type mismatch; expected number but got class<A>') | 3096 assert_fails('N = A', 'E1012: Type mismatch; expected number but got class<A>') |
3105 assert_fails('N = o', 'E1012: Type mismatch; expected number but got object<A>') | 3097 assert_fails('N = o', 'E1012: Type mismatch; expected number but got object<A>') |
3106 | 3098 |
3107 # Use a compound operator with different RHS types | 3099 # Use a compound operator with different RHS types |
3108 assert_fails('N += d', 'E734: Wrong variable type for +=') | 3100 assert_fails('N += d', 'E734: Wrong variable type for +=') |
3109 assert_fails('N += l', 'E734: Wrong variable type for +=') | 3101 assert_fails('N += l', 'E734: Wrong variable type for +=') |
3110 assert_fails('N += b', 'E974: Using a Blob as a Number') | 3102 assert_fails('N += b', 'E974: Using a Blob as a Number') |
3111 assert_fails('N += Fn', 'E734: Wrong variable type for +=') | 3103 assert_fails('N += Fn', 'E734: Wrong variable type for +=') |
3112 assert_fails('N += j', 'E910: Using a Job as a Number') | |
3113 assert_fails('N += ch', 'E913: Using a Channel as a Number') | |
3114 assert_fails('N += A', 'E1319: Using a Class as a Number') | 3104 assert_fails('N += A', 'E1319: Using a Class as a Number') |
3115 assert_fails('N += o', 'E1320: Using an Object as a Number') | 3105 assert_fails('N += o', 'E1320: Using an Object as a Number') |
3116 | 3106 |
3117 # Initialize multiple variables using [] | 3107 # Initialize multiple variables using [] |
3118 assert_fails('var [X1: number, Y: number] = [1, d]', 'E1012: Type mismatch; expected number but got dict<number>') | 3108 assert_fails('var [X1: number, Y: number] = [1, d]', 'E1012: Type mismatch; expected number but got dict<number>') |
3119 assert_fails('var [X2: number, Y: number] = [1, l]', 'E1012: Type mismatch; expected number but got list<number>') | 3109 assert_fails('var [X2: number, Y: number] = [1, l]', 'E1012: Type mismatch; expected number but got list<number>') |
3120 assert_fails('var [X3: number, Y: number] = [1, b]', 'E1012: Type mismatch; expected number but got blob') | 3110 assert_fails('var [X3: number, Y: number] = [1, b]', 'E1012: Type mismatch; expected number but got blob') |
3121 assert_fails('var [X4: number, Y: number] = [1, Fn]', 'E1012: Type mismatch; expected number but got func([unknown]): number') | 3111 assert_fails('var [X4: number, Y: number] = [1, Fn]', 'E1012: Type mismatch; expected number but got func([unknown]): number') |
3122 assert_fails('var [X5: number, Y: number] = [1, j]', 'E1012: Type mismatch; expected number but got job') | |
3123 assert_fails('var [X6: number, Y: number] = [1, ch]', 'E1012: Type mismatch; expected number but got channel') | |
3124 assert_fails('var [X7: number, Y: number] = [1, A]', 'E1012: Type mismatch; expected number but got class<A>') | 3112 assert_fails('var [X7: number, Y: number] = [1, A]', 'E1012: Type mismatch; expected number but got class<A>') |
3125 assert_fails('var [X8: number, Y: number] = [1, o]', 'E1012: Type mismatch; expected number but got object<A>') | 3113 assert_fails('var [X8: number, Y: number] = [1, o]', 'E1012: Type mismatch; expected number but got object<A>') |
3126 | 3114 |
3127 # String concatenation with various LHS types | 3115 # String concatenation with various LHS types |
3128 assert_fails('S ..= d', 'E734: Wrong variable type for .=') | 3116 assert_fails('S ..= d', 'E734: Wrong variable type for .=') |
3129 assert_fails('S ..= l', 'E734: Wrong variable type for .=') | 3117 assert_fails('S ..= l', 'E734: Wrong variable type for .=') |
3130 assert_fails('S ..= b', 'E976: Using a Blob as a String') | 3118 assert_fails('S ..= b', 'E976: Using a Blob as a String') |
3131 assert_fails('S ..= Fn', 'E734: Wrong variable type for .=') | 3119 assert_fails('S ..= Fn', 'E734: Wrong variable type for .=') |
3132 assert_fails('S ..= j', 'E908: Using an invalid value as a String: job') | |
3133 assert_fails('S ..= ch', 'E908: Using an invalid value as a String: channel') | |
3134 assert_fails('S ..= A', 'E1323: Using a Class as a String') | 3120 assert_fails('S ..= A', 'E1323: Using a Class as a String') |
3135 assert_fails('S ..= o', 'E1324: Using an Object as a String') | 3121 assert_fails('S ..= o', 'E1324: Using an Object as a String') |
3136 | 3122 |
3137 # String concatenation with various RHS types | 3123 # String concatenation with various RHS types |
3138 assert_fails('d ..= S', 'E734: Wrong variable type for .=') | 3124 assert_fails('d ..= S', 'E734: Wrong variable type for .=') |
3139 assert_fails('l ..= S', 'E734: Wrong variable type for .=') | 3125 assert_fails('l ..= S', 'E734: Wrong variable type for .=') |
3140 assert_fails('b ..= S', 'E734: Wrong variable type for .=') | 3126 assert_fails('b ..= S', 'E734: Wrong variable type for .=') |
3141 assert_fails('Fn ..= S', 'E734: Wrong variable type for .=') | 3127 assert_fails('Fn ..= S', 'E734: Wrong variable type for .=') |
3142 assert_fails('j ..= S', 'E734: Wrong variable type for .=') | |
3143 assert_fails('ch ..= S', 'E734: Wrong variable type for .=') | |
3144 assert_fails('A ..= S', 'E734: Wrong variable type for .=') | 3128 assert_fails('A ..= S', 'E734: Wrong variable type for .=') |
3145 assert_fails('o ..= S', 'E734: Wrong variable type for .=') | 3129 assert_fails('o ..= S', 'E734: Wrong variable type for .=') |
3146 END | 3130 END |
3147 v9.CheckSourceSuccess(lines) | 3131 v9.CheckSourceSuccess(lines) |
3132 | |
3133 if has('channel') | |
3134 lines =<< trim END | |
3135 vim9script | |
3136 var N: number = 1 | |
3137 var S: string = 'abc' | |
3138 var j: job = test_null_job() | |
3139 var ch: channel = test_null_channel() | |
3140 assert_fails('j = N', 'E1012: Type mismatch; expected job but got number') | |
3141 assert_fails('ch = N', 'E1012: Type mismatch; expected channel but got number') | |
3142 assert_fails('j += N', 'E734: Wrong variable type for +=') | |
3143 assert_fails('ch += N', 'E734: Wrong variable type for +=') | |
3144 assert_fails('N = j', 'E1012: Type mismatch; expected number but got job') | |
3145 assert_fails('N = ch', 'E1012: Type mismatch; expected number but got channel') | |
3146 assert_fails('N += j', 'E910: Using a Job as a Number') | |
3147 assert_fails('N += ch', 'E913: Using a Channel as a Number') | |
3148 assert_fails('var [X5: number, Y: number] = [1, j]', 'E1012: Type mismatch; expected number but got job') | |
3149 assert_fails('var [X6: number, Y: number] = [1, ch]', 'E1012: Type mismatch; expected number but got channel') | |
3150 assert_fails('S ..= j', 'E908: Using an invalid value as a String: job') | |
3151 assert_fails('S ..= ch', 'E908: Using an invalid value as a String: channel') | |
3152 assert_fails('j ..= S', 'E734: Wrong variable type for .=') | |
3153 assert_fails('ch ..= S', 'E734: Wrong variable type for .=') | |
3154 END | |
3155 v9.CheckSourceSuccess(lines) | |
3156 endif | |
3148 enddef | 3157 enddef |
3149 | 3158 |
3150 " Test for checking the argument type of a def function | 3159 " Test for checking the argument type of a def function |
3151 def Test_func_argtype_check() | 3160 def Test_func_argtype_check() |
3152 var lines =<< trim END | 3161 var lines =<< trim END |
3162 var S: string = 'abc' | 3171 var S: string = 'abc' |
3163 var d: dict<number> = {} | 3172 var d: dict<number> = {} |
3164 var l: list<number> = [] | 3173 var l: list<number> = [] |
3165 var b: blob = 0z10 | 3174 var b: blob = 0z10 |
3166 var Fn: func = function('min') | 3175 var Fn: func = function('min') |
3167 var j: job = test_null_job() | |
3168 var ch: channel = test_null_channel() | |
3169 var o: A = A.new() | 3176 var o: A = A.new() |
3170 | 3177 |
3171 assert_fails('IntArg(d)', 'E1013: Argument 1: type mismatch, expected number but got dict<number>') | 3178 assert_fails('IntArg(d)', 'E1013: Argument 1: type mismatch, expected number but got dict<number>') |
3172 assert_fails('IntArg(l)', 'E1013: Argument 1: type mismatch, expected number but got list<number>') | 3179 assert_fails('IntArg(l)', 'E1013: Argument 1: type mismatch, expected number but got list<number>') |
3173 assert_fails('IntArg(b)', 'E1013: Argument 1: type mismatch, expected number but got blob') | 3180 assert_fails('IntArg(b)', 'E1013: Argument 1: type mismatch, expected number but got blob') |
3174 assert_fails('IntArg(Fn)', 'E1013: Argument 1: type mismatch, expected number but got func([unknown]): number') | 3181 assert_fails('IntArg(Fn)', 'E1013: Argument 1: type mismatch, expected number but got func([unknown]): number') |
3175 assert_fails('IntArg(j)', 'E1013: Argument 1: type mismatch, expected number but got job') | 3182 if has('channel') |
3176 assert_fails('IntArg(ch)', 'E1013: Argument 1: type mismatch, expected number but got channel') | 3183 var j: job = test_null_job() |
3184 var ch: channel = test_null_channel() | |
3185 assert_fails('IntArg(j)', 'E1013: Argument 1: type mismatch, expected number but got job') | |
3186 assert_fails('IntArg(ch)', 'E1013: Argument 1: type mismatch, expected number but got channel') | |
3187 endif | |
3177 assert_fails('IntArg(A)', 'E1013: Argument 1: type mismatch, expected number but got class<A>') | 3188 assert_fails('IntArg(A)', 'E1013: Argument 1: type mismatch, expected number but got class<A>') |
3178 assert_fails('IntArg(o)', 'E1013: Argument 1: type mismatch, expected number but got object<A>') | 3189 assert_fails('IntArg(o)', 'E1013: Argument 1: type mismatch, expected number but got object<A>') |
3179 | 3190 |
3180 # Passing a number to functions accepting different argument types | 3191 # Passing a number to functions accepting different argument types |
3181 def DictArg(_: dict<number>) | 3192 def DictArg(_: dict<number>) |
3192 | 3203 |
3193 def FuncArg(Fn_arg: func) | 3204 def FuncArg(Fn_arg: func) |
3194 enddef | 3205 enddef |
3195 assert_fails('FuncArg(N)', 'E1013: Argument 1: type mismatch, expected func(...): unknown but got number') | 3206 assert_fails('FuncArg(N)', 'E1013: Argument 1: type mismatch, expected func(...): unknown but got number') |
3196 | 3207 |
3197 def JobArg(_: job) | 3208 if has('channel') |
3198 enddef | 3209 def JobArg(_: job) |
3199 assert_fails('JobArg(N)', 'E1013: Argument 1: type mismatch, expected job but got number') | 3210 enddef |
3200 | 3211 assert_fails('JobArg(N)', 'E1013: Argument 1: type mismatch, expected job but got number') |
3201 def ChannelArg(_: channel) | 3212 |
3202 enddef | 3213 def ChannelArg(_: channel) |
3203 assert_fails('ChannelArg(N)', 'E1013: Argument 1: type mismatch, expected channel but got number') | 3214 enddef |
3215 assert_fails('ChannelArg(N)', 'E1013: Argument 1: type mismatch, expected channel but got number') | |
3216 endif | |
3204 | 3217 |
3205 def ObjectArg(_: A) | 3218 def ObjectArg(_: A) |
3206 enddef | 3219 enddef |
3207 assert_fails('ObjectArg(N)', 'E1013: Argument 1: type mismatch, expected object<A> but got number') | 3220 assert_fails('ObjectArg(N)', 'E1013: Argument 1: type mismatch, expected object<A> but got number') |
3208 END | 3221 END |
3228 v9.CheckSourceFailure(lines, 'E1013: Argument 1: type mismatch, expected number but got list<number>', 2) | 3241 v9.CheckSourceFailure(lines, 'E1013: Argument 1: type mismatch, expected number but got list<number>', 2) |
3229 lines = pre_lines + ['var b: blob = 0z12', 'IntArg(b)'] + post_lines | 3242 lines = pre_lines + ['var b: blob = 0z12', 'IntArg(b)'] + post_lines |
3230 v9.CheckSourceFailure(lines, 'E1013: Argument 1: type mismatch, expected number but got blob', 2) | 3243 v9.CheckSourceFailure(lines, 'E1013: Argument 1: type mismatch, expected number but got blob', 2) |
3231 lines = pre_lines + ['var Fn: func = function("min")', 'IntArg(Fn)'] + post_lines | 3244 lines = pre_lines + ['var Fn: func = function("min")', 'IntArg(Fn)'] + post_lines |
3232 v9.CheckSourceFailure(lines, 'E1013: Argument 1: type mismatch, expected number but got func(...): unknown', 2) | 3245 v9.CheckSourceFailure(lines, 'E1013: Argument 1: type mismatch, expected number but got func(...): unknown', 2) |
3233 lines = pre_lines + ['var j: job = test_null_job()', 'IntArg(j)'] + post_lines | 3246 if has('channel') |
3234 v9.CheckSourceFailure(lines, 'E1013: Argument 1: type mismatch, expected number but got job', 2) | 3247 lines = pre_lines + ['var j: job = test_null_job()', 'IntArg(j)'] + post_lines |
3235 lines = pre_lines + ['var ch: channel = test_null_channel()', 'IntArg(ch)'] + post_lines | 3248 v9.CheckSourceFailure(lines, 'E1013: Argument 1: type mismatch, expected number but got job', 2) |
3236 v9.CheckSourceFailure(lines, 'E1013: Argument 1: type mismatch, expected number but got channel', 2) | 3249 lines = pre_lines + ['var ch: channel = test_null_channel()', 'IntArg(ch)'] + post_lines |
3250 v9.CheckSourceFailure(lines, 'E1013: Argument 1: type mismatch, expected number but got channel', 2) | |
3251 endif | |
3237 lines = pre_lines + ['IntArg(A)'] + post_lines | 3252 lines = pre_lines + ['IntArg(A)'] + post_lines |
3238 v9.CheckSourceFailure(lines, 'E1013: Argument 1: type mismatch, expected number but got class<A>', 1) | 3253 v9.CheckSourceFailure(lines, 'E1013: Argument 1: type mismatch, expected number but got class<A>', 1) |
3239 lines = pre_lines + ['var o: A = A.new()', 'IntArg(o)'] + post_lines | 3254 lines = pre_lines + ['var o: A = A.new()', 'IntArg(o)'] + post_lines |
3240 v9.CheckSourceFailure(lines, 'E1013: Argument 1: type mismatch, expected number but got object<A>', 2) | 3255 v9.CheckSourceFailure(lines, 'E1013: Argument 1: type mismatch, expected number but got object<A>', 2) |
3241 enddef | 3256 enddef |