(t *testing.T)
| 517 | } |
| 518 | |
| 519 | func TestMathNonMatch(t *testing.T) { |
| 520 | var mathTests = []struct { |
| 521 | expr string |
| 522 | }{ |
| 523 | // Even though 'least' is the macro, the call is left unexpanded since the operand is not 'math'. |
| 524 | { |
| 525 | expr: `100.least(42) == 42`, |
| 526 | }, |
| 527 | // Even though 'greatest' is the macro, the call is left unexpanded since the operand is not 'math'. |
| 528 | { |
| 529 | expr: `100.greatest(42) == 100`, |
| 530 | }, |
| 531 | } |
| 532 | env := testMathEnv(t, |
| 533 | cel.Function("greatest", |
| 534 | cel.MemberOverload("int_greatest_int", []*cel.Type{cel.IntType, cel.IntType}, cel.IntType, |
| 535 | cel.BinaryBinding(maxPair))), |
| 536 | cel.Function("least", |
| 537 | cel.MemberOverload("int_least_int", []*cel.Type{cel.IntType, cel.IntType}, cel.IntType, |
| 538 | cel.BinaryBinding(minPair))), |
| 539 | ) |
| 540 | for i, tst := range mathTests { |
| 541 | tc := tst |
| 542 | t.Run(fmt.Sprintf("[%d]", i), func(t *testing.T) { |
| 543 | var asts []*cel.Ast |
| 544 | pAst, iss := env.Parse(tc.expr) |
| 545 | if iss.Err() != nil { |
| 546 | t.Fatalf("env.Parse(%v) failed: %v", tc.expr, iss.Err()) |
| 547 | } |
| 548 | asts = append(asts, pAst) |
| 549 | cAst, iss := env.Check(pAst) |
| 550 | if iss.Err() != nil { |
| 551 | t.Fatalf("env.Check(%v) failed: %v", tc.expr, iss.Err()) |
| 552 | } |
| 553 | asts = append(asts, cAst) |
| 554 | |
| 555 | for _, ast := range asts { |
| 556 | prg, err := env.Program(ast) |
| 557 | if err != nil { |
| 558 | t.Fatalf("env.Program() failed: %v", err) |
| 559 | } |
| 560 | out, _, err := prg.Eval(cel.NoVars()) |
| 561 | if err != nil { |
| 562 | t.Fatalf("prg.Eval() failed: %v", err) |
| 563 | } |
| 564 | if out.Value() != true { |
| 565 | t.Errorf("prg.Eval() got %v, wanted true for expr: %s", out.Value(), tc.expr) |
| 566 | } |
| 567 | } |
| 568 | }) |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | func TestMathWithExtension(t *testing.T) { |
| 573 | env := testMathEnv(t) |
nothing calls this directly
no test coverage detected