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

Function TestLateBoundFunctionVariableNamespace

cel/cel_test.go:6275–6308  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6273}
6274
6275func TestLateBoundFunctionVariableNamespace(t *testing.T) {
6276 // Late bindings are supplied in a namespace which is separate from variables, so the same
6277 // qualified name may refer to both a variable and a late-bound function.
6278 env, err := NewEnv(
6279 Variable("inc", IntType),
6280 Function("inc", Overload("inc_int", []*Type{IntType}, IntType, LateFunctionBinding())),
6281 )
6282 if err != nil {
6283 t.Fatalf("NewEnv() failed: %v", err)
6284 }
6285 ast, iss := env.Compile("inc(inc)")
6286 if iss.Err() != nil {
6287 t.Fatalf("Compile() failed: %v", iss.Err())
6288 }
6289 prg, err := env.Program(ast)
6290 if err != nil {
6291 t.Fatalf("Program() failed: %v", err)
6292 }
6293 act, err := FunctionVars(map[string]any{"inc": 41}, map[string]LateBoundFunction{
6294 "inc": func(overloadID string, args ...ref.Val) ref.Val {
6295 return types.Int(args[0].(types.Int) + 1)
6296 },
6297 })
6298 if err != nil {
6299 t.Fatalf("FunctionVars() failed: %v", err)
6300 }
6301 out, _, err := prg.Eval(act)
6302 if err != nil {
6303 t.Fatalf("Eval() failed: %v", err)
6304 }
6305 if out.Equal(types.Int(42)) != types.True {
6306 t.Errorf("Eval() got %v, wanted 42", out)
6307 }
6308}
6309
6310func TestLateBoundFunctionCost(t *testing.T) {
6311 env, err := NewEnv(

Callers

nothing calls this directly

Calls 12

CompileMethod · 0.95
ProgramMethod · 0.95
IntTypeAlias · 0.92
FunctionVarsFunction · 0.85
ErrMethod · 0.80
NewEnvFunction · 0.70
VariableFunction · 0.70
FunctionFunction · 0.70
OverloadFunction · 0.70
LateFunctionBindingFunction · 0.70
EvalMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected