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

Function evalCostAndState

cel/cel_test.go:1754–1770  ·  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

1752// evalCostAndState evaluates the ast and reports the tracked cost along with whether evaluation
1753// state was recorded.
1754func evalCostAndState(t *testing.T, env *Env, ast *Ast, opts ...ProgramOption) (uint64, bool) {
1755 t.Helper()
1756 prg, err := env.Program(ast, opts...)
1757 if err != nil {
1758 t.Fatalf("env.Program() failed: %v", err)
1759 }
1760 _, det, err := prg.Eval(map[string]any{"a": "xyz-abcdefghij"})
1761 if err != nil {
1762 t.Fatalf("prg.Eval() failed: %v", err)
1763 }
1764 cost := det.ActualCost()
1765 if cost == nil {
1766 t.Fatalf("det.ActualCost() returned nil")
1767 }
1768 state := det.State()
1769 return *cost, state != nil && len(state.IDs()) != 0
1770}
1771
1772func TestParseError(t *testing.T) {
1773 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