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