MCPcopy Create free account
hub / github.com/cel-expr/cel-go / evalCostAndState

Function evalCostAndState

cel/cel_test.go:1726–1742  ·  view source on GitHub ↗

evalCostAndState evaluates the ast and reports the tracked cost along with whether evaluation state was recorded.

(t *testing.T, env *Env, ast *Ast, opts ...ProgramOption)

Source from the content-addressed store, hash-verified

1724// evalCostAndState evaluates the ast and reports the tracked cost along with whether evaluation
1725// state was recorded.
1726func evalCostAndState(t *testing.T, env *Env, ast *Ast, opts ...ProgramOption) (uint64, bool) {
1727 t.Helper()
1728 prg, err := env.Program(ast, opts...)
1729 if err != nil {
1730 t.Fatalf("env.Program() failed: %v", err)
1731 }
1732 _, det, err := prg.Eval(map[string]any{"a": "xyz-abcdefghij"})
1733 if err != nil {
1734 t.Fatalf("prg.Eval() failed: %v", err)
1735 }
1736 cost := det.ActualCost()
1737 if cost == nil {
1738 t.Fatalf("det.ActualCost() returned nil")
1739 }
1740 state := det.State()
1741 return *cost, state != nil && len(state.IDs()) != 0
1742}
1743
1744func TestParseError(t *testing.T) {
1745 env := testEnv(t)

Callers 1

Calls 5

ProgramMethod · 0.80
StateMethod · 0.80
EvalMethod · 0.65
IDsMethod · 0.65
ActualCostMethod · 0.45

Tested by

no test coverage detected