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

Function TestParseWithMacroTracking

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

Source from the content-addressed store, hash-verified

1778}
1779
1780func TestParseWithMacroTracking(t *testing.T) {
1781 env := testEnv(t, EnableMacroCallTracking())
1782 ast, iss := env.Parse("has(a.b) && a.b.exists(c, c < 10)")
1783 if iss.Err() != nil {
1784 t.Fatalf("e.Parse() failed: %v", iss.Err())
1785 }
1786 pe, err := AstToParsedExpr(ast)
1787 if err != nil {
1788 t.Fatalf("AstToParsedExpr(%v) failed: %v", ast, err)
1789 }
1790 macroCalls := pe.GetSourceInfo().GetMacroCalls()
1791 if len(macroCalls) != 2 {
1792 t.Errorf("got %d macro calls, wanted 2", len(macroCalls))
1793 }
1794 callsFound := map[string]bool{"has": false, "exists": false}
1795 for _, expr := range macroCalls {
1796 f := expr.GetCallExpr().GetFunction()
1797 _, found := callsFound[f]
1798 if !found {
1799 t.Errorf("Unexpected macro call: %v", expr)
1800 }
1801 callsFound[f] = true
1802 }
1803 callsWanted := map[string]bool{"has": true, "exists": true}
1804 if !reflect.DeepEqual(callsFound, callsWanted) {
1805 t.Errorf("Tracked calls %v, but wanted %v", callsFound, callsWanted)
1806 }
1807}
1808
1809func TestParseAndCheckConcurrently(t *testing.T) {
1810 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