Skip to content

Commit

Permalink
Add non-proto field test.
Browse files Browse the repository at this point in the history
  • Loading branch information
DangerOnTheRanger committed Mar 5, 2023
1 parent e2d28ac commit 1256a6f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
7 changes: 5 additions & 2 deletions checker/cost.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,11 @@ func (c *coster) costSelect(e *exprpb.Expr) CostEstimate {
sel := e.GetSelectExpr()
var sum CostEstimate
if sel.GetTestOnly() {
sum.Min = 1
sum.Max = 1
// recurse, but do not add any cost
// this is equivalent to how evalTestOnly increments the runtime cost counter
// but does not add any additional cost for the qualifier, except here we do
// the reverse (ident adds cost)
sum = sum.Add(c.cost(sel.GetOperand()))
return sum
}
sum = sum.Add(c.cost(sel.GetOperand()))
Expand Down
13 changes: 13 additions & 0 deletions interpreter/runtimecost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,19 @@ func TestRuntimeCost(t *testing.T) {
},
},
},
{
name: "select: non-proto field test",
expr: `has(input.testAttr.nestedAttr)`,
decls: []*exprpb.Decl{decls.NewVar("input", nestedMap)},
want: 2,
in: map[string]any{
"input": map[string]any{
"testAttr": map[string]any{
"nestedAttr": "0",
},
},
},
},
{
name: "estimated function call",
expr: `input.getFullYear()`,
Expand Down

0 comments on commit 1256a6f

Please sign in to comment.