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

Method VisitExpr

policy/composer_test.go:137–168  ·  view source on GitHub ↗
(srcExpr ast.Expr)

Source from the content-addressed store, hash-verified

135}
136
137func (c *transferChecker) VisitExpr(srcExpr ast.Expr) {
138 if srcRange, haveSrc := c.srcInfo.GetOffsetRange(srcExpr.ID()); haveSrc {
139 if srcRange.Start == 0 {
140 // Ignore synthetic "true" default condition which has an incorrect source location
141 return
142 }
143 dstExpr, haveDst := (*c.ranges)[srcRange]
144 if !haveDst {
145 c.t.Errorf("composed node not found for rule node: %s", debug.ToDebugString(srcExpr))
146 return
147 }
148
149 // Check that the two nodes have the same textual representation
150 if dstExpr.Kind() == ast.IdentKind && strings.HasPrefix(dstExpr.AsIdent(), "@index") {
151 // Skip the check for unnested vars
152 return
153 }
154 dstStr, err := cel.ExprToString(dstExpr, c.dstInfo)
155 if err != nil {
156 c.t.Errorf("failed to convert dstExpr")
157 return
158 }
159 srcStr, err := cel.ExprToString(srcExpr, c.srcInfo)
160 if err != nil {
161 c.t.Errorf("failed to convert srcExpr")
162 return
163 }
164 if srcStr != dstStr {
165 c.t.Errorf("mismatched nodes, rule: %s composed: %s", srcStr, dstStr)
166 }
167 }
168}
169
170func (c *transferChecker) VisitEntryExpr(ast.EntryExpr) {
171}

Callers

nothing calls this directly

Calls 6

ToDebugStringFunction · 0.92
ExprToStringFunction · 0.92
GetOffsetRangeMethod · 0.80
IDMethod · 0.65
KindMethod · 0.65
AsIdentMethod · 0.65

Tested by

no test coverage detected