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

Function TestFunctionMergeDeclarationAndDefinition

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

Source from the content-addressed store, hash-verified

185}
186
187func TestFunctionMergeDeclarationAndDefinition(t *testing.T) {
188 idFuncDecl := Function("id", Overload("id", []*Type{TypeParamType("T")}, TypeParamType("T"), OverloadIsNonStrict()))
189 idFuncDef := Function("id",
190 Overload("id", []*Type{TypeParamType("T")}, TypeParamType("T"), OverloadIsNonStrict(),
191 UnaryBinding(func(arg ref.Val) ref.Val {
192 return arg
193 }),
194 ),
195 )
196 env, err := NewCustomEnv(Variable("x", AnyType), idFuncDecl, idFuncDef)
197 if err != nil {
198 t.Fatalf("NewCustomEnv() failed: %v", err)
199 }
200 ast, iss := env.Compile("id(x)")
201 if iss.Err() != nil {
202 t.Fatalf("env.Compile(id(x)) failed: %v", iss.Err())
203 }
204 prg, err := env.Program(ast)
205 if err != nil {
206 t.Fatalf("env.Program() failed: %v", err)
207 }
208 out, _, err := prg.Eval(map[string]any{"x": true})
209 if err != nil {
210 t.Fatalf("prg.Eval(x: true) errored: %v", err)
211 }
212 if out != types.True {
213 t.Errorf("prg.Eval() yielded %v, wanted true", out)
214 }
215}
216
217func TestFunctionMergeCollision(t *testing.T) {
218 maxFunc := Function("max",

Callers

nothing calls this directly

Calls 10

NewCustomEnvFunction · 0.85
ErrMethod · 0.80
ProgramMethod · 0.80
FunctionFunction · 0.70
OverloadFunction · 0.70
OverloadIsNonStrictFunction · 0.70
UnaryBindingFunction · 0.70
VariableFunction · 0.70
CompileMethod · 0.65
EvalMethod · 0.65

Tested by

no test coverage detected