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

Function TestFunctionDeclIncludeOverloads

cel/decls_test.go:876–963  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

874}
875
876func TestFunctionDeclIncludeOverloads(t *testing.T) {
877 funcs := []*decls.FunctionDecl{}
878 for _, fn := range stdlib.Functions() {
879 if fn.Name() == operators.Add {
880 fn = fn.Subset(IncludeOverloads(overloads.AddInt64, overloads.AddDouble))
881 }
882 funcs = append(funcs, fn)
883 }
884 env, err := NewCustomEnv(FunctionDecls(funcs...))
885 if err != nil {
886 t.Fatalf("NewCustomEnv() failed: %v", err)
887 }
888
889 successTests := []struct {
890 name string
891 expr string
892 want ref.Val
893 }{
894 {
895 name: "ints",
896 expr: "1 + 1",
897 want: types.Int(2),
898 },
899 {
900 name: "doubles",
901 expr: "1.5 + 1.5",
902 want: types.Double(3.0),
903 },
904 }
905 for _, tst := range successTests {
906 tc := tst
907 t.Run(tc.name, func(t *testing.T) {
908 ast, iss := env.Compile(tc.expr)
909 if iss.Err() != nil {
910 t.Fatalf("env.Compile() failed: %v", iss.Err())
911 }
912 prg, err := env.Program(ast)
913 if err != nil {
914 t.Fatalf("env.Program() failed: %v", err)
915 }
916 out, _, err := prg.Eval(NoVars())
917 if err != nil {
918 t.Fatalf("prg.Eval() errored: %v", err)
919 }
920 if out.Equal(tc.want) != types.True {
921 t.Errorf("Eval() got %v, wanted %v", out, tc.want)
922 }
923 })
924 }
925 failureTests := []struct {
926 name string
927 expr string
928 }{
929 {
930 name: "strings",
931 expr: "'a' + 'b'",
932 },
933 {

Callers

nothing calls this directly

Calls 15

FunctionsFunction · 0.92
IntTypeAlias · 0.92
DoubleTypeAlias · 0.92
NewCustomEnvFunction · 0.85
FunctionDeclsFunction · 0.85
NoVarsFunction · 0.85
SubsetMethod · 0.80
ErrMethod · 0.80
ProgramMethod · 0.80
IncludeOverloadsFunction · 0.70
NameMethod · 0.65
CompileMethod · 0.65

Tested by

no test coverage detected