verifySourceInfoTransfer checks that each offset range in the compiledRule has a corresponding node in composed
(t *testing.T, compiledRule *CompiledRule, composed *cel.Ast)
| 97 | |
| 98 | // verifySourceInfoTransfer checks that each offset range in the compiledRule has a corresponding node in composed |
| 99 | func verifySourceInfoTransfer(t *testing.T, compiledRule *CompiledRule, composed *cel.Ast) { |
| 100 | t.Helper() |
| 101 | dstRanges := make(map[ast.OffsetRange]ast.Expr) |
| 102 | check := func(a *cel.Ast) { |
| 103 | ast.PostOrderVisit(a.NativeRep().Expr(), &transferChecker{ |
| 104 | t: t, |
| 105 | srcInfo: a.NativeRep().SourceInfo(), |
| 106 | dstInfo: composed.NativeRep().SourceInfo(), |
| 107 | ranges: &dstRanges}) |
| 108 | } |
| 109 | ast.PostOrderVisit(composed.NativeRep().Expr(), &collectRanges{sourceInfo: composed.NativeRep().SourceInfo(), ranges: &dstRanges}) |
| 110 | for _, match := range compiledRule.matches { |
| 111 | check(match.cond) |
| 112 | check(match.output.expr) |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | type collectRanges struct { |
| 117 | sourceInfo *ast.SourceInfo |
no test coverage detected