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

Function TestFunctionAsCELFunction

common/env/env_test.go:901–1068  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

899}
900
901func TestFunctionAsCELFunction(t *testing.T) {
902 tests := []struct {
903 name string
904 f *Function
905 want any
906 }{
907 {
908 name: "nil function",
909 f: nil,
910 want: errors.New("invalid function: nil"),
911 },
912 {
913 name: "unnamed function",
914 f: &Function{},
915 want: errors.New("invalid function"),
916 },
917 {
918 name: "no overloads",
919 f: NewFunction("no_overloads"),
920 want: errors.New("missing overloads"),
921 },
922 {
923 name: "nil overload",
924 f: NewFunction("no_overloads", nil),
925 want: errors.New("invalid overload: nil"),
926 },
927 {
928 name: "missing overload id",
929 f: NewFunction("size", &Overload{}),
930 want: errors.New("missing overload id"),
931 },
932 {
933 name: "no return type",
934 f: NewFunction("size",
935 NewOverload("size_string", []*TypeDesc{NewTypeDesc("string")}, nil),
936 ),
937 want: errors.New("return: invalid type"),
938 },
939 {
940 name: "bad return type",
941 f: NewFunction("size",
942 NewOverload("size_string", []*TypeDesc{NewTypeDesc("string")}, NewTypeDesc("")),
943 ),
944 want: errors.New("invalid type"),
945 },
946 {
947 name: "bad arg type",
948 f: NewFunction("size",
949 NewOverload("size_string", []*TypeDesc{NewTypeDesc("")}, NewTypeDesc("")),
950 ),
951 want: errors.New("invalid type"),
952 },
953 {
954 name: "undefined arg type",
955 f: NewFunction("size",
956 NewOverload("size_undefined", []*TypeDesc{NewTypeDesc("undefined")}, NewTypeDesc("int")),
957 ),
958 want: errors.New("undefined type"),

Callers

nothing calls this directly

Calls 15

RegisterTypeMethod · 0.95
OverloadFunction · 0.92
MemberOverloadFunction · 0.92
FunctionDocsFunction · 0.92
OverloadExamplesFunction · 0.92
NewTypeTypeWithParamFunction · 0.92
NewTypeParamTypeFunction · 0.92
NewRegistryFunction · 0.92
NewOpaqueTypeFunction · 0.92
NewTypeDescFunction · 0.85
NewMemberOverloadFunction · 0.85
mustNewFunctionFunction · 0.85

Tested by

no test coverage detected