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

Function TestFunctionEnableDeclaration

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

Source from the content-addressed store, hash-verified

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