verifySourceInfoTransfer checks that each offset range in the compiledRule has a corresponding node in composed
(t *testing.T, compiledRule *CompiledRule, composed *cel.Ast)
| 210 | |
| 211 | // verifySourceInfoTransfer checks that each offset range in the compiledRule has a corresponding node in composed |
| 212 | func verifySourceInfoTransfer(t *testing.T, compiledRule *CompiledRule, composed *cel.Ast) { |
| 213 | t.Helper() |
| 214 | dstRanges := make(map[ast.OffsetRange]ast.Expr) |
| 215 | check := func(a *cel.Ast) { |
| 216 | ast.PostOrderVisit(a.NativeRep().Expr(), &transferChecker{ |
| 217 | t: t, |
| 218 | srcInfo: a.NativeRep().SourceInfo(), |
| 219 | dstInfo: composed.NativeRep().SourceInfo(), |
| 220 | ranges: &dstRanges}) |
| 221 | } |
| 222 | ast.PostOrderVisit(composed.NativeRep().Expr(), &collectRanges{sourceInfo: composed.NativeRep().SourceInfo(), ranges: &dstRanges}) |
| 223 | for _, v := range compiledRule.variables { |
| 224 | check(v.expr) |
| 225 | } |
| 226 | for _, match := range compiledRule.matches { |
| 227 | check(match.cond) |
| 228 | if match.output != nil { |
| 229 | check(match.output.expr) |
| 230 | } else if match.nestedRule != nil { |
| 231 | verifySourceInfoTransfer(t, match.nestedRule, composed) |
| 232 | } |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | type collectRanges struct { |
| 237 | sourceInfo *ast.SourceInfo |
no test coverage detected