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

Function TestFunctionEnableDeclaration

common/decls/decls_test.go:966–1008  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

964}
965
966func TestFunctionEnableDeclaration(t *testing.T) {
967 fn, err := NewFunction("in",
968 DisableDeclaration(false),
969 Overload("in_list",
970 []*types.Type{types.NewListType(types.NewTypeParamType("K")), types.NewTypeParamType("K")},
971 types.BoolType),
972 )
973 if err != nil {
974 t.Fatalf("NewFunction() failed: %v", err)
975 }
976 if fn.IsDeclarationDisabled() {
977 t.Error("got declaration disabled, wanted enabled")
978 }
979 fn2, err := NewFunction("in",
980 DisableDeclaration(true),
981 Overload("in_list",
982 []*types.Type{types.NewListType(types.NewTypeParamType("K")), types.NewTypeParamType("K")},
983 types.BoolType),
984 )
985 if err != nil {
986 t.Fatalf("NewFunction() failed: %v", err)
987 }
988 if !fn2.IsDeclarationDisabled() {
989 t.Error("got declaration enabled, wanted disabled")
990 }
991
992 // enabled -> disabled
993 merged, err := fn.Merge(fn2)
994 if err != nil {
995 t.Fatalf("fn.Merge(fn2) failed: %v", err)
996 }
997 if !merged.IsDeclarationDisabled() {
998 t.Error("got declaration enabled, wanted disabled")
999 }
1000 // disabled -> enabled
1001 merged2, err := fn2.Merge(fn)
1002 if err != nil {
1003 t.Fatalf("fn.Merge(fn2) failed: %v", err)
1004 }
1005 if merged2.IsDeclarationDisabled() {
1006 t.Error("got declaration disabled, wanted enabled")
1007 }
1008}
1009
1010func TestFunctionDeclToExprDecl(t *testing.T) {
1011 tests := []struct {

Callers

nothing calls this directly

Calls 8

NewListTypeFunction · 0.92
NewTypeParamTypeFunction · 0.92
IsDeclarationDisabledMethod · 0.80
MergeMethod · 0.80
NewFunctionFunction · 0.70
DisableDeclarationFunction · 0.70
OverloadFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected