...
1
2
3
4
5 package function
6
7 import (
8 "bytes"
9 "reflect"
10 "testing"
11 )
12
13 type myType struct{ bytes.Buffer }
14
15 func (myType) valueMethod() {}
16 func (myType) ValueMethod() {}
17
18 func (*myType) pointerMethod() {}
19 func (*myType) PointerMethod() {}
20
21 func TestNameOf(t *testing.T) {
22 tests := []struct {
23 fnc interface{}
24 want string
25 }{
26 {TestNameOf, "function.TestNameOf"},
27 {func() {}, "function.TestNameOf.func1"},
28 {(myType).valueMethod, "function.myType.valueMethod"},
29 {(myType).ValueMethod, "function.myType.ValueMethod"},
30 {(myType{}).valueMethod, "function.myType.valueMethod"},
31 {(myType{}).ValueMethod, "function.myType.ValueMethod"},
32 {(*myType).valueMethod, "function.myType.valueMethod"},
33 {(*myType).ValueMethod, "function.myType.ValueMethod"},
34 {(&myType{}).valueMethod, "function.myType.valueMethod"},
35 {(&myType{}).ValueMethod, "function.myType.ValueMethod"},
36 {(*myType).pointerMethod, "function.myType.pointerMethod"},
37 {(*myType).PointerMethod, "function.myType.PointerMethod"},
38 {(&myType{}).pointerMethod, "function.myType.pointerMethod"},
39 {(&myType{}).PointerMethod, "function.myType.PointerMethod"},
40 {(*myType).Write, "function.myType.Write"},
41 {(&myType{}).Write, "bytes.Buffer.Write"},
42 }
43 for _, tt := range tests {
44 t.Run("", func(t *testing.T) {
45 got := NameOf(reflect.ValueOf(tt.fnc))
46 if got != tt.want {
47 t.Errorf("NameOf() = %v, want %v", got, tt.want)
48 }
49 })
50 }
51 }
52
View as plain text