forked from andeya/goutil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
type_test.go
36 lines (26 loc) · 910 Bytes
/
type_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
package goutil
import (
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
type A struct {
B
}
func (A) X0() {}
func (*A) X1() {}
type B struct {
}
func (B) Y0() {}
func (*B) Y1() {}
func TestIsCompositionMethod(t *testing.T) {
assert.False(t, IsCompositionMethod(reflect.TypeOf(A{}).Method(0)))
assert.True(t, IsCompositionMethod(reflect.TypeOf(A{}).Method(1)))
assert.False(t, IsCompositionMethod(reflect.TypeOf(&A{}).Method(0)), reflect.TypeOf(&A{}).Method(0))
assert.False(t, IsCompositionMethod(reflect.TypeOf(&A{}).Method(1)))
assert.True(t, IsCompositionMethod(reflect.TypeOf(&A{}).Method(2)))
assert.True(t, IsCompositionMethod(reflect.TypeOf(&A{}).Method(3)))
assert.False(t, IsCompositionMethod(reflect.TypeOf(B{}).Method(0)))
assert.False(t, IsCompositionMethod(reflect.TypeOf(&B{}).Method(0)))
assert.False(t, IsCompositionMethod(reflect.TypeOf(&B{}).Method(1)))
}