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

Function optionalDecls

interpreter/prune_test.go:571–609  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

569}
570
571func optionalDecls(t *testing.T) []*decls.FunctionDecl {
572 paramType := types.NewTypeParamType("T")
573 optionalType := types.NewOptionalType(paramType)
574 return []*decls.FunctionDecl{
575 funcDecl(t, "optional.none",
576 decls.Overload("optional_none", []*types.Type{}, optionalType,
577 decls.FunctionBinding(func(args ...ref.Val) ref.Val {
578 return types.OptionalNone
579 }),
580 ),
581 ),
582 funcDecl(t, "optional.of",
583 decls.Overload("optional_of_value", []*types.Type{paramType}, optionalType,
584 decls.UnaryBinding(func(val ref.Val) ref.Val {
585 return types.OptionalOf(val)
586 }),
587 ),
588 ),
589 funcDecl(t, "_[?_]",
590 decls.Overload("map_optindex_optional_value", []*types.Type{
591 types.NewMapType(types.NewTypeParamType("K"), paramType),
592 types.NewTypeParamType("K"),
593 }, optionalType),
594 ),
595 funcDecl(t, "last", decls.Overload("list_last", []*types.Type{paramType}, optionalType,
596 decls.UnaryBinding(func(v ref.Val) ref.Val {
597 list := v.(traits.Lister)
598 sz := list.Size().Value().(int64)
599
600 if sz == 0 {
601 return types.OptionalNone
602 }
603
604 return types.OptionalOf(list.Get(types.Int(sz - 1)))
605 }),
606 ),
607 ),
608 }
609}

Callers 2

TestPruneFunction · 0.85

Calls 12

NewTypeParamTypeFunction · 0.92
NewOptionalTypeFunction · 0.92
OverloadFunction · 0.92
FunctionBindingFunction · 0.92
UnaryBindingFunction · 0.92
OptionalOfFunction · 0.92
NewMapTypeFunction · 0.92
IntTypeAlias · 0.92
funcDeclFunction · 0.85
ValueMethod · 0.65
SizeMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected