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

Function TestFunctionDisableDeclarationMergeReenable

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

Source from the content-addressed store, hash-verified

596}
597
598func TestFunctionDisableDeclarationMergeReenable(t *testing.T) {
599 e, err := NewCustomEnv(
600 Function("enabled",
601 DisableDeclaration(true),
602 Overload("enabled_any", []*Type{BoolType}, BoolType),
603 ),
604 // Ensure the previously disabled declaration is enabled
605 Function("enabled",
606 DisableDeclaration(false),
607 Overload("enabled_any", []*Type{BoolType}, BoolType,
608 FunctionBinding(func(args ...ref.Val) ref.Val {
609 return types.True
610 })),
611 ),
612 )
613 if err != nil {
614 t.Fatalf("NewCustomEnv() failed: %v", err)
615 }
616 ast, iss := e.Parse("enabled(true)")
617 if iss.Err() != nil {
618 t.Errorf("Parse(enabled(true)) failed: %v", iss.Err())
619 }
620 prg, err := e.Program(ast)
621 if err != nil {
622 t.Fatalf("Program(ast) failed: %v", err)
623 }
624 out, _, err := prg.Eval(NoVars())
625 if err != nil {
626 t.Errorf("enabled runtime binding missing: %v", err)
627 } else if out != types.True {
628 t.Errorf("enabled runtime binding failed: %v", out)
629 }
630 _, iss = e.Compile("enabled(true)")
631 if iss.Err() != nil {
632 t.Errorf("Compile(enabled(true)) got an unexpected error: %v", iss.Err())
633 }
634}
635
636func TestExprDeclToDeclaration(t *testing.T) {
637 paramT := chkdecls.NewTypeParamType("T")

Callers

nothing calls this directly

Calls 11

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

Tested by

no test coverage detected