(t *testing.T)
| 4370 | } |
| 4371 | |
| 4372 | func TestOptionalMapCost(t *testing.T) { |
| 4373 | commonOpts := []EnvOption{ |
| 4374 | Variable("self", MapType(StringType, ListType(StringType))), |
| 4375 | } |
| 4376 | envs := []struct { |
| 4377 | name string |
| 4378 | env *Env |
| 4379 | }{ |
| 4380 | {name: "v3", env: testEnv(t, append(commonOpts, OptionalTypes(OptionalTypesVersion(3)))...)}, |
| 4381 | {name: "v4", env: testEnv(t, append(commonOpts, OptionalTypes(OptionalTypesVersion(4)))...)}, |
| 4382 | {name: "latest", env: testEnv(t, append(commonOpts, OptionalTypes())...)}, |
| 4383 | } |
| 4384 | |
| 4385 | tests := []struct { |
| 4386 | name string |
| 4387 | expr string |
| 4388 | in map[string]any |
| 4389 | v3Est cost.CostEstimate |
| 4390 | v3Actual uint64 |
| 4391 | v4Est cost.CostEstimate |
| 4392 | v4Actual uint64 |
| 4393 | latestEst cost.CostEstimate |
| 4394 | latestCost uint64 |
| 4395 | }{ |
| 4396 | { |
| 4397 | name: "string equality optMap", |
| 4398 | expr: `optional.of('a').optMap(v, v == 'value').hasValue()`, |
| 4399 | v3Est: cost.RangedCostEstimate(4, 18), |
| 4400 | v3Actual: 18, |
| 4401 | v4Est: cost.RangedCostEstimate(15, 29), |
| 4402 | v4Actual: 29, |
| 4403 | latestEst: cost.RangedCostEstimate(15, 29), |
| 4404 | latestCost: 29, |
| 4405 | }, |
| 4406 | { |
| 4407 | name: "string size optMap", |
| 4408 | expr: `optional.of('abcdefgabcdefg').optMap(v, v.size()).hasValue()`, |
| 4409 | v3Est: cost.RangedCostEstimate(4, 18), |
| 4410 | v3Actual: 18, |
| 4411 | v4Est: cost.RangedCostEstimate(15, 29), |
| 4412 | v4Actual: 29, |
| 4413 | latestEst: cost.RangedCostEstimate(15, 29), |
| 4414 | latestCost: 29, |
| 4415 | }, |
| 4416 | { |
| 4417 | name: "list size optMap", |
| 4418 | expr: `optional.of([1, 2, 3, 4, 5]).optMap(v, v.size()).hasValue()`, |
| 4419 | v3Est: cost.RangedCostEstimate(14, 38), |
| 4420 | v3Actual: 38, |
| 4421 | v4Est: cost.RangedCostEstimate(25, 39), |
| 4422 | v4Actual: 39, |
| 4423 | latestEst: cost.RangedCostEstimate(25, 39), |
| 4424 | latestCost: 39, |
| 4425 | }, |
| 4426 | { |
| 4427 | name: "map index optMap", |
| 4428 | expr: `self.l[?0].optMap(v, v == 'a').hasValue()`, |
| 4429 | in: map[string]any{ |
nothing calls this directly
no test coverage detected