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

Function TestOptionalMapVersion

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

Source from the content-addressed store, hash-verified

4273}
4274
4275func TestOptionalMapVersion(t *testing.T) {
4276 commonOpts := []EnvOption{
4277 Variable("x", OptionalType(IntType)),
4278 Variable("m", MapType(StringType, MapType(StringType, StringType))),
4279 }
4280 envs := []struct {
4281 name string
4282 env *Env
4283 }{
4284 {name: "v3", env: testEnv(t, append(commonOpts, OptionalTypes(OptionalTypesVersion(3)))...)},
4285 {name: "v4", env: testEnv(t, append(commonOpts, OptionalTypes(OptionalTypesVersion(4)))...)},
4286 {name: "latest", env: testEnv(t, append(commonOpts, OptionalTypes())...)},
4287 }
4288
4289 tests := []struct {
4290 name string
4291 expr string
4292 in map[string]any
4293 wantOut ref.Val
4294 wantKinds map[string]celast.ExprKind
4295 }{
4296 {
4297 name: "{0: 10}[?0].optMap(v, v + 1)",
4298 expr: "{0: 10}[?0].optMap(v, v + 1)",
4299 wantKinds: map[string]celast.ExprKind{
4300 "v3": celast.CallKind,
4301 "v4": celast.ComprehensionKind,
4302 "latest": celast.ComprehensionKind,
4303 },
4304 wantOut: types.OptionalOf(types.Int(11)),
4305 },
4306 {
4307 name: "x.optMap(v, v + 1)",
4308 expr: "x.optMap(v, v + 1)",
4309 in: map[string]any{
4310 "x": types.OptionalOf(types.Int(10)),
4311 },
4312 wantKinds: map[string]celast.ExprKind{
4313 "v3": celast.CallKind,
4314 "v4": celast.CallKind,
4315 "latest": celast.CallKind,
4316 },
4317 wantOut: types.OptionalOf(types.Int(11)),
4318 },
4319 {
4320 name: "m.?key.optFlatMap(k, k.?subkey)",
4321 expr: "m.?key.optFlatMap(k, k.?subkey)",
4322 in: map[string]any{
4323 "m": map[string]any{
4324 "key": map[string]any{
4325 "subkey": "hello",
4326 },
4327 },
4328 },
4329 wantKinds: map[string]celast.ExprKind{
4330 "v3": celast.CallKind,
4331 "v4": celast.ComprehensionKind,
4332 "latest": celast.ComprehensionKind,

Callers

nothing calls this directly

Calls 15

OptionalOfFunction · 0.92
IntTypeAlias · 0.92
StringTypeAlias · 0.92
OptionalTypesFunction · 0.85
OptionalTypesVersionFunction · 0.85
ErrMethod · 0.80
NativeRepMethod · 0.80
ProgramMethod · 0.80
VariableFunction · 0.70
testEnvFunction · 0.70
CompileMethod · 0.65
KindMethod · 0.65

Tested by

no test coverage detected