-
Notifications
You must be signed in to change notification settings - Fork 7
/
type_test.go
78 lines (74 loc) · 1.66 KB
/
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
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package memsize
import (
"reflect"
"testing"
)
var typCacheTests = []struct {
val interface{}
want typInfo
}{
{
val: int(0),
want: typInfo{isPointer: false, needScan: false},
},
{
val: make(chan struct{}, 1),
want: typInfo{isPointer: true, needScan: true},
},
{
val: struct{ A int }{},
want: typInfo{isPointer: false, needScan: false},
},
{
val: struct{ S string }{},
want: typInfo{isPointer: false, needScan: true},
},
{
val: structloop{},
want: typInfo{isPointer: false, needScan: true},
},
{
val: [3]int{},
want: typInfo{isPointer: false, needScan: false},
},
{
val: [3]struct{ A int }{},
want: typInfo{isPointer: false, needScan: false},
},
{
val: [3]struct{ S string }{},
want: typInfo{isPointer: false, needScan: true},
},
{
val: [3]structloop{},
want: typInfo{isPointer: false, needScan: true},
},
{
val: struct {
a [32]uint8
s [2][]uint8
}{},
want: typInfo{isPointer: false, needScan: true},
},
}
func TestTypeInfo(t *testing.T) {
// This cache is shared among all test cases. It is used
// to verify that putting many different types into the cache
// doesn't change the resulting info.
sharedtc := make(typCache)
for i := range typCacheTests {
test := typCacheTests[i]
typ := reflect.TypeOf(test.val)
t.Run(typ.String(), func(t *testing.T) {
tc := make(typCache)
info := tc.info(typ)
if !reflect.DeepEqual(info, test.want) {
t.Fatalf("wrong info from local cache:\ngot %+v, want %+v", info, test.want)
}
info = sharedtc.info(typ)
if !reflect.DeepEqual(info, test.want) {
t.Fatalf("wrong info from shared cache:\ngot %+v, want %+v", info, test.want)
}
})
}
}