(t *testing.T)
| 2266 | } |
| 2267 | |
| 2268 | func TestIterVarComputedRangeModelVersion0(t *testing.T) { |
| 2269 | allTypes := types.NewObjectType("google.expr.proto3.test.TestAllTypes") |
| 2270 | env, err := testCelEnv.Extend(cel.VariableDecls( |
| 2271 | decls.NewVariable("self", allTypes), |
| 2272 | )) |
| 2273 | if err != nil { |
| 2274 | t.Fatalf("env.Extend() failed: %v", err) |
| 2275 | } |
| 2276 | |
| 2277 | hints := map[string]uint64{ |
| 2278 | "self.repeated_int64": 10, |
| 2279 | "@items": 0, |
| 2280 | "@indices": 0, |
| 2281 | "@keys": 0, |
| 2282 | "@values": 0, |
| 2283 | } |
| 2284 | est := testCostEstimator{hints: hints} |
| 2285 | |
| 2286 | tests := []struct { |
| 2287 | name string |
| 2288 | expr string |
| 2289 | wantV0 cost.CostEstimate |
| 2290 | wantV1 cost.CostEstimate |
| 2291 | }{ |
| 2292 | { |
| 2293 | name: "single_iter_var_over_computed_list", |
| 2294 | expr: `self.repeated_int64.map(e, e * 20).exists(e, e == 60)`, |
| 2295 | wantV0: cost.RangedCostEstimate(14, 204), |
| 2296 | wantV1: cost.RangedCostEstimate(14, 214), |
| 2297 | }, |
| 2298 | { |
| 2299 | name: "nested_comprehension_over_computed_list", |
| 2300 | expr: `self.repeated_int64.map(e, [e, e]).exists(l, l.exists(e, e == 60))`, |
| 2301 | wantV0: cost.RangedCostEstimate(14, 314), |
| 2302 | wantV1: cost.RangedCostEstimate(14, 434), |
| 2303 | }, |
| 2304 | { |
| 2305 | name: "two_var_comprehension_over_computed_list", |
| 2306 | expr: `self.repeated_int64.map(e, e * 20).exists(i, v, i == 0 && v == 60)`, |
| 2307 | wantV0: cost.RangedCostEstimate(14, 214), |
| 2308 | wantV1: cost.RangedCostEstimate(14, 234), |
| 2309 | }, |
| 2310 | { |
| 2311 | name: "two_var_comprehension_over_computed_map", |
| 2312 | expr: `{'a': 'x', 'b': 'y'}.transformMap(k, v, v + 'z').exists(k, v, k == 'a' && v == 'xz')`, |
| 2313 | wantV0: cost.RangedCostEstimate(80, 84), |
| 2314 | wantV1: cost.RangedCostEstimate(80, 88), |
| 2315 | }, |
| 2316 | { |
| 2317 | name: "string_iter_var_over_computed_list", |
| 2318 | expr: `self.repeated_int64.map(e, 'abc').exists(s, s == 'abc')`, |
| 2319 | wantV0: cost.RangedCostEstimate(14, 184), |
| 2320 | wantV1: cost.RangedCostEstimate(14, 194), |
| 2321 | }, |
| 2322 | } |
| 2323 | |
| 2324 | for _, tc := range tests { |
| 2325 | t.Run(tc.name, func(t *testing.T) { |
nothing calls this directly
no test coverage detected