(t *testing.T)
| 476 | } |
| 477 | |
| 478 | func TestFunctionBinding(t *testing.T) { |
| 479 | e, err := NewCustomEnv( |
| 480 | Variable("unk", DynType), |
| 481 | Variable("err", DynType), |
| 482 | Function("dyn", |
| 483 | Overload("dyn", []*Type{DynType}, DynType), |
| 484 | SingletonUnaryBinding(func(arg ref.Val) ref.Val { |
| 485 | return arg |
| 486 | })), |
| 487 | Function("max", |
| 488 | Overload("max_int", []*Type{IntType}, IntType, |
| 489 | UnaryBinding(func(arg ref.Val) ref.Val { return arg })), |
| 490 | Overload("max_int_int", []*Type{IntType, IntType}, IntType, |
| 491 | BinaryBinding(func(lhs, rhs ref.Val) ref.Val { |
| 492 | if lhs.(types.Int).Compare(rhs) == types.IntNegOne { |
| 493 | return rhs |
| 494 | } |
| 495 | return lhs |
| 496 | })), |
| 497 | Overload("max_int_int_int", []*Type{IntType, IntType, IntType}, IntType, |
| 498 | FunctionBinding(func(args ...ref.Val) ref.Val { |
| 499 | max := types.Int(math.MinInt64) |
| 500 | for _, arg := range args { |
| 501 | i := arg.(types.Int) |
| 502 | if i > max { |
| 503 | max = i |
| 504 | } |
| 505 | } |
| 506 | return max |
| 507 | })), |
| 508 | ), |
| 509 | ) |
| 510 | if err != nil { |
| 511 | t.Fatalf("NewCustomEnv() failed: %v", err) |
| 512 | } |
| 513 | |
| 514 | for _, tc := range dispatchTests { |
| 515 | tc := tc |
| 516 | t.Run(fmt.Sprintf("Parse(%s)", tc.expr), func(t *testing.T) { |
| 517 | testParse(t, e, tc.expr, tc.out) |
| 518 | }) |
| 519 | } |
| 520 | for _, tc := range dispatchTests { |
| 521 | tc := tc |
| 522 | t.Run(fmt.Sprintf("Compile(%s)", tc.expr), func(t *testing.T) { |
| 523 | testCompile(t, e, tc.expr, tc.out) |
| 524 | }) |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | func TestFunctionDisableDeclaration(t *testing.T) { |
| 529 | e, err := NewCustomEnv( |
nothing calls this directly
no test coverage detected