From 1256a6f0d2a00d5dc0e24b43fe5ea6c6ffd78f5d Mon Sep 17 00:00:00 2001 From: Kermit Alexander II Date: Sun, 5 Mar 2023 20:59:35 +0000 Subject: [PATCH] Add non-proto field test. --- checker/cost.go | 7 +++++-- interpreter/runtimecost_test.go | 13 +++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/checker/cost.go b/checker/cost.go index 16e5ecf8..c10b957a 100644 --- a/checker/cost.go +++ b/checker/cost.go @@ -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())) diff --git a/interpreter/runtimecost_test.go b/interpreter/runtimecost_test.go index 26a19368..ec128410 100644 --- a/interpreter/runtimecost_test.go +++ b/interpreter/runtimecost_test.go @@ -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()`,