-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathreflect_test.go
64 lines (49 loc) · 1.13 KB
/
reflect_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
52
53
54
55
56
57
58
59
60
61
62
63
64
package changeset
import (
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
func TestReflectInternalType(t *testing.T) {
type User struct{}
assert.Equal(t,
reflect.TypeOf(User{}),
reflectInternalType(User{}),
)
assert.Equal(t,
reflect.TypeOf(User{}),
reflectInternalType(&User{}),
)
assert.Equal(t,
reflect.TypeOf(User{}),
reflectInternalType([]User{}),
)
assert.Equal(t,
reflect.TypeOf(User{}),
reflectInternalType(&[]User{}),
)
assert.Equal(t,
reflect.TypeOf(User{}),
reflectInternalType([0]User{}),
)
assert.Equal(t,
reflect.TypeOf(User{}),
reflectInternalType(&[0]User{}),
)
}
func TestReflectTypePtr(t *testing.T) {
type User struct{}
assert.Equal(t, reflect.TypeOf(User{}), reflectTypePtr(User{}))
assert.Equal(t, reflect.TypeOf(User{}), reflectTypePtr(&User{}))
assert.Panics(t, func() {
reflectTypePtr("not struct")
})
}
func TestReflectValuePtr(t *testing.T) {
type User struct{}
assert.Equal(t, User{}, reflectValuePtr(User{}).Interface())
assert.Equal(t, User{}, reflectValuePtr(&User{}).Interface())
assert.Panics(t, func() {
reflectValuePtr("not struct")
})
}