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

Function TestFunctionDisableDeclarationMerge

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

Source from the content-addressed store, hash-verified

559}
560
561func TestFunctionDisableDeclarationMerge(t *testing.T) {
562 e, err := NewCustomEnv(
563 Function("disabled",
564 Overload("disabled_any", []*Type{BoolType}, BoolType),
565 ),
566 // Ensure the previously enabled declaration is disabled
567 Function("disabled",
568 DisableDeclaration(true),
569 Overload("disabled_any", []*Type{BoolType}, BoolType,
570 FunctionBinding(func(args ...ref.Val) ref.Val {
571 return types.True
572 })),
573 ),
574 )
575 if err != nil {
576 t.Fatalf("NewCustomEnv() failed: %v", err)
577 }
578 ast, iss := e.Parse("disabled(true)")
579 if iss.Err() != nil {
580 t.Errorf("Parse(disabled(true)) failed: %v", iss.Err())
581 }
582 prg, err := e.Program(ast)
583 if err != nil {
584 t.Fatalf("Program(ast) failed: %v", err)
585 }
586 out, _, err := prg.Eval(NoVars())
587 if err != nil {
588 t.Errorf("disabled runtime binding missing: %v", err)
589 } else if out != types.True {
590 t.Errorf("disabled runtime binding failed: %v", out)
591 }
592 _, iss = e.Compile("disabled(true)")
593 if iss.Err() == nil || !strings.Contains(iss.Err().Error(), "undeclared reference to 'disabled'") {
594 t.Errorf("Compile(disabled(true)) got an unexpected error: %v", iss.Err())
595 }
596}
597
598func TestFunctionDisableDeclarationMergeReenable(t *testing.T) {
599 e, err := NewCustomEnv(

Callers

nothing calls this directly

Calls 13

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

Tested by

no test coverage detected