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

Method VisitExpr

tools/celtest/test_runner.go:1119–1213  ·  view source on GitHub ↗

VisitExpr populates the coverageStats for the current expression based on the coverageStats of its direct children.

(e ast.Expr)

Source from the content-addressed store, hash-verified

1117
1118// VisitExpr populates the coverageStats for the current expression based on the coverageStats of its direct children.
1119func (pv parentVisitor) VisitExpr(e ast.Expr) {
1120 switch e.Kind() {
1121 case ast.SelectKind:
1122 if pv.coverageStats[e.ID()] != nil {
1123 return
1124 }
1125 if _, ok := pv.coverageStats[e.AsSelect().Operand().ID()]; ok {
1126 pv.coverageStats[e.ID()] = make(set)
1127 }
1128 case ast.CallKind:
1129 c := e.AsCall()
1130 if c.FunctionName() == "cel.@block" {
1131 pv.coverageStats[e.ID()] = pv.coverageStats[c.Args()[1].ID()]
1132 return
1133 }
1134 if c.FunctionName() == operators.Conditional {
1135 truthyID := c.Args()[1].ID()
1136 if truthyVal, ok := pv.evalState.Value(truthyID); ok {
1137 if pv.coverageStats[e.ID()] == nil {
1138 pv.coverageStats[e.ID()] = make(set)
1139 }
1140 pv.coverageStats[e.ID()][truthyVal] = struct{}{}
1141 }
1142 falsyID := c.Args()[2].ID()
1143 if falsyVal, ok := pv.evalState.Value(falsyID); ok {
1144 if pv.coverageStats[e.ID()] == nil {
1145 pv.coverageStats[e.ID()] = make(set)
1146 }
1147 pv.coverageStats[e.ID()][falsyVal] = struct{}{}
1148 }
1149 return
1150 }
1151 if pv.coverageStats[e.ID()] != nil {
1152 return
1153 }
1154 for _, arg := range c.Args() {
1155 if _, ok := pv.coverageStats[arg.ID()]; ok {
1156 pv.coverageStats[e.ID()] = make(set)
1157 break
1158 }
1159 }
1160 if c.IsMemberFunction() && pv.coverageStats[c.Target().ID()] == nil && pv.coverageStats[e.ID()] != nil {
1161 pv.coverageStats[c.Target().ID()] = make(set)
1162 }
1163 case ast.ListKind:
1164 if pv.coverageStats[e.ID()] != nil {
1165 return
1166 }
1167 l := e.AsList()
1168 for _, element := range l.Elements() {
1169 if _, ok := pv.coverageStats[element.ID()]; ok {
1170 pv.coverageStats[e.ID()] = make(set)
1171 break
1172 }
1173 }
1174 case ast.MapKind:
1175 if pv.coverageStats[e.ID()] != nil {
1176 return

Callers

nothing calls this directly

Calls 15

KindMethod · 0.65
IDMethod · 0.65
OperandMethod · 0.65
AsSelectMethod · 0.65
AsCallMethod · 0.65
FunctionNameMethod · 0.65
ArgsMethod · 0.65
ValueMethod · 0.65
IsMemberFunctionMethod · 0.65
TargetMethod · 0.65
AsListMethod · 0.65
ElementsMethod · 0.65

Tested by

no test coverage detected