(b *testing.B)
| 530 | } |
| 531 | |
| 532 | func BenchmarkBlockEval(b *testing.B) { |
| 533 | fac := ast.NewExprFactory() |
| 534 | expr := fac.NewCall( |
| 535 | 1, "cel.@block", |
| 536 | fac.NewList(2, []ast.Expr{ |
| 537 | fac.NewIdent(3, "x"), |
| 538 | fac.NewIdent(4, "@index0"), |
| 539 | fac.NewIdent(5, "@index1"), |
| 540 | }, []int32{}), |
| 541 | fac.NewCall(9, operators.Add, |
| 542 | fac.NewCall(6, operators.Add, |
| 543 | fac.NewIdent(7, "@index2"), |
| 544 | fac.NewIdent(8, "@index1")), |
| 545 | fac.NewIdent(10, "@index0"), |
| 546 | ), |
| 547 | ) |
| 548 | blockAST := ast.NewAST(expr, nil) |
| 549 | env, err := cel.NewEnv( |
| 550 | Bindings(), |
| 551 | cel.Variable("x", cel.StringType), |
| 552 | ) |
| 553 | if err != nil { |
| 554 | b.Fatalf("cel.NewEnv(Bindings()) failed: %v", err) |
| 555 | } |
| 556 | prg, err := env.PlanProgram(blockAST, cel.EvalOptions(cel.OptOptimize)) |
| 557 | if err != nil { |
| 558 | b.Fatalf("PlanProgram() failed: %v", err) |
| 559 | } |
| 560 | input := map[string]any{"x": "hello"} |
| 561 | b.ResetTimer() |
| 562 | b.ReportAllocs() |
| 563 | for i := 0; i < b.N; i++ { |
| 564 | prg.Eval(input) |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | func TestValidateBindNestingLimit(t *testing.T) { |
| 569 | env, err := cel.NewEnv( |
nothing calls this directly
no test coverage detected