(t *testing.T)
| 205 | } |
| 206 | |
| 207 | func TestValidateHomogeneousAggregateLiterals(t *testing.T) { |
| 208 | env, err := NewCustomEnv( |
| 209 | Variable("name", StringType), |
| 210 | Function(operators.In, |
| 211 | Overload(overloads.InList, []*Type{StringType, ListType(StringType)}, BoolType, |
| 212 | BinaryBinding(func(lhs, rhs ref.Val) ref.Val { |
| 213 | return rhs.(traits.Container).Contains(lhs) |
| 214 | }), |
| 215 | ), |
| 216 | Overload(overloads.InMap, []*Type{StringType, MapType(StringType, BoolType)}, BoolType, |
| 217 | BinaryBinding(func(lhs, rhs ref.Val) ref.Val { |
| 218 | return rhs.(traits.Container).Contains(lhs) |
| 219 | }), |
| 220 | ), |
| 221 | ), |
| 222 | OptionalTypes(), |
| 223 | HomogeneousAggregateLiterals(), |
| 224 | ASTValidators(ValidateHomogeneousAggregateLiterals()), |
| 225 | ) |
| 226 | if err != nil { |
| 227 | t.Fatalf("NewCustomEnv() failed: %v", err) |
| 228 | } |
| 229 | |
| 230 | tests := []struct { |
| 231 | expr string |
| 232 | iss string |
| 233 | }{ |
| 234 | { |
| 235 | expr: `name in ['hello', 0]`, |
| 236 | iss: ` |
| 237 | ERROR: <input>:1:19: expected type 'string' but found 'int' |
| 238 | | name in ['hello', 0] |
| 239 | | ..................^`, |
| 240 | }, |
| 241 | { |
| 242 | expr: `{'hello':'world', 1:'!'}`, |
| 243 | iss: ` |
| 244 | ERROR: <input>:1:19: expected type 'string' but found 'int' |
| 245 | | {'hello':'world', 1:'!'} |
| 246 | | ..................^`, |
| 247 | }, |
| 248 | { |
| 249 | expr: `name in {'hello':'world', 'goodbye':true}`, |
| 250 | iss: ` |
| 251 | ERROR: <input>:1:37: expected type 'string' but found 'bool' |
| 252 | | name in {'hello':'world', 'goodbye':true} |
| 253 | | ....................................^`, |
| 254 | }, |
| 255 | { |
| 256 | expr: `name in ['hello', 'world']`, |
| 257 | }, |
| 258 | { |
| 259 | expr: `name in ['hello', ?optional.ofNonZeroValue('')]`, |
| 260 | }, |
| 261 | { |
| 262 | expr: `name in [?optional.ofNonZeroValue(''), 'hello', ?optional.of('')]`, |
| 263 | }, |
| 264 | { |
nothing calls this directly
no test coverage detected