diff --git a/cmp/internal/function/func_test.go b/cmp/internal/function/func_test.go index eb87e9e..a8d8e85 100644 --- a/cmp/internal/function/func_test.go +++ b/cmp/internal/function/func_test.go @@ -21,29 +21,35 @@ func (*myType) PointerMethod() {} func TestNameOf(t *testing.T) { tests := []struct { fnc any - want string + want []string // any matching entry is ok }{ - {TestNameOf, "function.TestNameOf"}, - {func() {}, "function.TestNameOf.func1"}, - {(myType).valueMethod, "function.myType.valueMethod"}, - {(myType).ValueMethod, "function.myType.ValueMethod"}, - {(myType{}).valueMethod, "function.myType.valueMethod"}, - {(myType{}).ValueMethod, "function.myType.ValueMethod"}, - {(*myType).valueMethod, "function.myType.valueMethod"}, - {(*myType).ValueMethod, "function.myType.ValueMethod"}, - {(&myType{}).valueMethod, "function.myType.valueMethod"}, - {(&myType{}).ValueMethod, "function.myType.ValueMethod"}, - {(*myType).pointerMethod, "function.myType.pointerMethod"}, - {(*myType).PointerMethod, "function.myType.PointerMethod"}, - {(&myType{}).pointerMethod, "function.myType.pointerMethod"}, - {(&myType{}).PointerMethod, "function.myType.PointerMethod"}, - {(*myType).Write, "function.myType.Write"}, - {(&myType{}).Write, "bytes.Buffer.Write"}, + {TestNameOf, []string{"function.TestNameOf"}}, + {func() {}, []string{"function.TestNameOf.func1"}}, + {(myType).valueMethod, []string{"function.myType.valueMethod"}}, + {(myType).ValueMethod, []string{"function.myType.ValueMethod"}}, + {(myType{}).valueMethod, []string{"function.myType.valueMethod"}}, + {(myType{}).ValueMethod, []string{"function.myType.ValueMethod"}}, + {(*myType).valueMethod, []string{"function.myType.valueMethod"}}, + {(*myType).ValueMethod, []string{"function.myType.ValueMethod"}}, + {(&myType{}).valueMethod, []string{"function.myType.valueMethod"}}, + {(&myType{}).ValueMethod, []string{"function.myType.ValueMethod"}}, + {(*myType).pointerMethod, []string{"function.myType.pointerMethod"}}, + {(*myType).PointerMethod, []string{"function.myType.PointerMethod"}}, + {(&myType{}).pointerMethod, []string{"function.myType.pointerMethod"}}, + {(&myType{}).PointerMethod, []string{"function.myType.PointerMethod"}}, + {(*myType).Write, []string{"function.myType.Write", "bytes.Buffer.Write"}}, + {(&myType{}).Write, []string{"bytes.Buffer.Write"}}, } for _, tt := range tests { t.Run("", func(t *testing.T) { got := NameOf(reflect.ValueOf(tt.fnc)) - if got != tt.want { + match := false + for _, w := range tt.want { + if got == w { + match = true + } + } + if !match { t.Errorf("NameOf() = %v, want %v", got, tt.want) } })