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

Function TestParseWithMacroTracking

cel/cel_test.go:1694–1721  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1692}
1693
1694func TestParseWithMacroTracking(t *testing.T) {
1695 env := testEnv(t, EnableMacroCallTracking())
1696 ast, iss := env.Parse("has(a.b) && a.b.exists(c, c < 10)")
1697 if iss.Err() != nil {
1698 t.Fatalf("e.Parse() failed: %v", iss.Err())
1699 }
1700 pe, err := AstToParsedExpr(ast)
1701 if err != nil {
1702 t.Fatalf("AstToParsedExpr(%v) failed: %v", ast, err)
1703 }
1704 macroCalls := pe.GetSourceInfo().GetMacroCalls()
1705 if len(macroCalls) != 2 {
1706 t.Errorf("got %d macro calls, wanted 2", len(macroCalls))
1707 }
1708 callsFound := map[string]bool{"has": false, "exists": false}
1709 for _, expr := range macroCalls {
1710 f := expr.GetCallExpr().GetFunction()
1711 _, found := callsFound[f]
1712 if !found {
1713 t.Errorf("Unexpected macro call: %v", expr)
1714 }
1715 callsFound[f] = true
1716 }
1717 callsWanted := map[string]bool{"has": true, "exists": true}
1718 if !reflect.DeepEqual(callsFound, callsWanted) {
1719 t.Errorf("Tracked calls %v, but wanted %v", callsFound, callsWanted)
1720 }
1721}
1722
1723func TestParseAndCheckConcurrently(t *testing.T) {
1724 env := testEnv(t,

Callers

nothing calls this directly

Calls 5

EnableMacroCallTrackingFunction · 0.85
AstToParsedExprFunction · 0.85
ErrMethod · 0.80
testEnvFunction · 0.70
ParseMethod · 0.65

Tested by

no test coverage detected