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

Function TestOptionalMapCost

cel/cel_test.go:4372–4491  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

4370}
4371
4372func 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{

Callers

nothing calls this directly

Calls 12

RangedCostEstimateFunction · 0.92
OptionalTypesFunction · 0.85
OptionalTypesVersionFunction · 0.85
CostTrackingFunction · 0.85
ErrMethod · 0.80
EstimateCostMethod · 0.80
ProgramMethod · 0.80
VariableFunction · 0.70
testEnvFunction · 0.70
CompileMethod · 0.65
EvalMethod · 0.65
ActualCostMethod · 0.45

Tested by

no test coverage detected