/
func_test.go
51 lines (45 loc) · 1.53 KB
/
func_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2019, The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package function
import (
"bytes"
"reflect"
"testing"
)
type myType struct{ bytes.Buffer }
func (myType) valueMethod() {}
func (myType) ValueMethod() {}
func (*myType) pointerMethod() {}
func (*myType) PointerMethod() {}
func TestNameOf(t *testing.T) {
tests := []struct {
fnc interface{}
want string
}{
{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"},
}
for _, tt := range tests {
t.Run("", func(t *testing.T) {
got := NameOf(reflect.ValueOf(tt.fnc))
if got != tt.want {
t.Errorf("NameOf() = %v, want %v", got, tt.want)
}
})
}
}