(t *testing.T)
| 276 | } |
| 277 | |
| 278 | func TestValidateHomogeneousAggregateLiterals(t *testing.T) { |
| 279 | env, err := NewCustomEnv( |
| 280 | Variable("name", StringType), |
| 281 | Function(operators.In, |
| 282 | Overload(overloads.InList, []*Type{StringType, ListType(StringType)}, BoolType, |
| 283 | BinaryBinding(func(lhs, rhs ref.Val) ref.Val { |
| 284 | return rhs.(traits.Container).Contains(lhs) |
| 285 | }), |
| 286 | ), |
| 287 | Overload(overloads.InMap, []*Type{StringType, MapType(StringType, BoolType)}, BoolType, |
| 288 | BinaryBinding(func(lhs, rhs ref.Val) ref.Val { |
| 289 | return rhs.(traits.Container).Contains(lhs) |
| 290 | }), |
| 291 | ), |
| 292 | ), |
| 293 | OptionalTypes(), |
| 294 | HomogeneousAggregateLiterals(), |
| 295 | ASTValidators(ValidateHomogeneousAggregateLiterals()), |
| 296 | ) |
| 297 | if err != nil { |
| 298 | t.Fatalf("NewCustomEnv() failed: %v", err) |
| 299 | } |
| 300 | |
| 301 | tests := []struct { |
| 302 | expr string |
| 303 | iss string |
| 304 | }{ |
| 305 | { |
| 306 | expr: `name in ['hello', 0]`, |
| 307 | iss: ` |
| 308 | ERROR: <input>:1:19: expected type 'string' but found 'int' |
| 309 | | name in ['hello', 0] |
| 310 | | ..................^`, |
| 311 | }, |
| 312 | { |
| 313 | expr: `{'hello':'world', 1:'!'}`, |
| 314 | iss: ` |
| 315 | ERROR: <input>:1:19: expected type 'string' but found 'int' |
| 316 | | {'hello':'world', 1:'!'} |
| 317 | | ..................^`, |
| 318 | }, |
| 319 | { |
| 320 | expr: `name in {'hello':'world', 'goodbye':true}`, |
| 321 | iss: ` |
| 322 | ERROR: <input>:1:37: expected type 'string' but found 'bool' |
| 323 | | name in {'hello':'world', 'goodbye':true} |
| 324 | | ....................................^`, |
| 325 | }, |
| 326 | { |
| 327 | expr: `name in ['hello', 'world']`, |
| 328 | }, |
| 329 | { |
| 330 | expr: `name in ['hello', ?optional.ofNonZeroValue('')]`, |
| 331 | }, |
| 332 | { |
| 333 | expr: `name in [?optional.ofNonZeroValue(''), 'hello', ?optional.of('')]`, |
| 334 | }, |
| 335 | { |
nothing calls this directly
no test coverage detected