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

Function TestFunctionMergeSingletonRedefinition

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

Source from the content-addressed store, hash-verified

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