(b *testing.B)
| 926 | } |
| 927 | |
| 928 | func BenchmarkBlockEval(b *testing.B) { |
| 929 | fac := ast.NewExprFactory() |
| 930 | expr := fac.NewCall( |
| 931 | 1, "cel.@block", |
| 932 | fac.NewList(2, []ast.Expr{ |
| 933 | fac.NewIdent(3, "x"), |
| 934 | fac.NewIdent(4, "@index0"), |
| 935 | fac.NewIdent(5, "@index1"), |
| 936 | }, []int32{}), |
| 937 | fac.NewCall(9, operators.Add, |
| 938 | fac.NewCall(6, operators.Add, |
| 939 | fac.NewIdent(7, "@index2"), |
| 940 | fac.NewIdent(8, "@index1")), |
| 941 | fac.NewIdent(10, "@index0"), |
| 942 | ), |
| 943 | ) |
| 944 | blockAST := ast.NewAST(expr, nil) |
| 945 | env, err := cel.NewEnv( |
| 946 | Bindings(), |
| 947 | cel.Variable("x", cel.StringType), |
| 948 | ) |
| 949 | if err != nil { |
| 950 | b.Fatalf("cel.NewEnv(Bindings()) failed: %v", err) |
| 951 | } |
| 952 | prg, err := env.PlanProgram(blockAST, cel.EvalOptions(cel.OptOptimize)) |
| 953 | if err != nil { |
| 954 | b.Fatalf("PlanProgram() failed: %v", err) |
| 955 | } |
| 956 | input := map[string]any{"x": "hello"} |
| 957 | b.ResetTimer() |
| 958 | b.ReportAllocs() |
| 959 | for i := 0; i < b.N; i++ { |
| 960 | prg.Eval(input) |
| 961 | } |
| 962 | } |
| 963 | |
| 964 | func TestValidateBindNestingLimit(t *testing.T) { |
| 965 | env, err := cel.NewEnv( |
nothing calls this directly
no test coverage detected