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

Function optionalDecls

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

Source from the content-addressed store, hash-verified

593}
594
595func optionalDecls(t *testing.T) []*decls.FunctionDecl {
596 paramType := types.NewTypeParamType("T")
597 optionalType := types.NewOptionalType(paramType)
598 return []*decls.FunctionDecl{
599 funcDecl(t, "optional.none",
600 decls.Overload("optional_none", []*types.Type{}, optionalType,
601 decls.FunctionBinding(func(args ...ref.Val) ref.Val {
602 return types.OptionalNone
603 }),
604 ),
605 ),
606 funcDecl(t, "optional.of",
607 decls.Overload("optional_of_value", []*types.Type{paramType}, optionalType,
608 decls.UnaryBinding(func(val ref.Val) ref.Val {
609 return types.OptionalOf(val)
610 }),
611 ),
612 ),
613 funcDecl(t, "_[?_]",
614 decls.Overload("map_optindex_optional_value", []*types.Type{
615 types.NewMapType(types.NewTypeParamType("K"), paramType),
616 types.NewTypeParamType("K"),
617 }, optionalType),
618 ),
619 funcDecl(t, "last", decls.Overload("list_last", []*types.Type{paramType}, optionalType,
620 decls.UnaryBinding(func(v ref.Val) ref.Val {
621 list := v.(traits.Lister)
622 sz := list.Size().Value().(int64)
623
624 if sz == 0 {
625 return types.OptionalNone
626 }
627
628 return types.OptionalOf(list.Get(types.Int(sz - 1)))
629 }),
630 ),
631 ),
632 }
633}

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