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

Function TestFunctionDisableDeclaration

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

Source from the content-addressed store, hash-verified

526}
527
528func TestFunctionDisableDeclaration(t *testing.T) {
529 e, err := NewCustomEnv(
530 Function("disabled",
531 DisableDeclaration(true),
532 Overload("disabled_any", []*Type{BoolType}, BoolType),
533 SingletonFunctionImpl(func(args ...ref.Val) ref.Val {
534 return types.True
535 }),
536 ),
537 )
538 if err != nil {
539 t.Fatalf("NewCustomEnv() failed: %v", err)
540 }
541 ast, iss := e.Parse("disabled(true)")
542 if iss.Err() != nil {
543 t.Errorf("Parse(disabled(true)) failed: %v", iss.Err())
544 }
545 prg, err := e.Program(ast)
546 if err != nil {
547 t.Fatalf("Program(ast) failed: %v", err)
548 }
549 out, _, err := prg.Eval(NoVars())
550 if err != nil {
551 t.Errorf("disabled runtime binding missing: %v", err)
552 } else if out != types.True {
553 t.Errorf("disabled runtime binding failed: %v", out)
554 }
555 _, iss = e.Compile("disabled(true)")
556 if iss.Err() == nil || !strings.Contains(iss.Err().Error(), "undeclared reference to 'disabled'") {
557 t.Errorf("Compile(disabled(true)) got an unexpected error: %v", iss.Err())
558 }
559}
560
561func TestFunctionDisableDeclarationMerge(t *testing.T) {
562 e, err := NewCustomEnv(

Callers

nothing calls this directly

Calls 13

NewCustomEnvFunction · 0.85
SingletonFunctionImplFunction · 0.85
NoVarsFunction · 0.85
ErrMethod · 0.80
ProgramMethod · 0.80
FunctionFunction · 0.70
DisableDeclarationFunction · 0.70
OverloadFunction · 0.70
ParseMethod · 0.65
EvalMethod · 0.65
CompileMethod · 0.65
ContainsMethod · 0.65

Tested by

no test coverage detected