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

Function TestFunctionMergeSingletonRedefinition

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

Source from the content-addressed store, hash-verified

526}
527
528func TestFunctionMergeSingletonRedefinition(t *testing.T) {
529 sizeFunc, err := NewFunction("size",
530 MemberOverload("list_size",
531 []*types.Type{types.NewListType(types.NewTypeParamType("T"))}, types.IntType),
532 SingletonUnaryBinding(func(ref.Val) ref.Val {
533 return types.IntZero
534 }),
535 )
536 if err != nil {
537 t.Fatalf("NewFunction() failed: %v", err)
538 }
539 sizeVecFunc, err := NewFunction("size",
540 MemberOverload("string_size",
541 []*types.Type{types.StringType}, types.IntType),
542 SingletonUnaryBinding(func(ref.Val) ref.Val {
543 return types.IntZero
544 }),
545 )
546 if err != nil {
547 t.Fatalf("NewFunction() failed: %v", err)
548 }
549 _, err = sizeFunc.Merge(sizeVecFunc)
550 if err == nil || !strings.Contains(err.Error(), "already has a singleton") {
551 t.Fatalf("Merge() expected to fail, got: %v", err)
552 }
553}
554
555func TestFunctionAddDuplicateOverloads(t *testing.T) {
556 _, err := NewFunction("max",

Callers

nothing calls this directly

Calls 8

NewListTypeFunction · 0.92
NewTypeParamTypeFunction · 0.92
MergeMethod · 0.80
NewFunctionFunction · 0.70
MemberOverloadFunction · 0.70
SingletonUnaryBindingFunction · 0.70
ContainsMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected