1
2
3
4
5 package types2
6
7 import (
8 "reflect"
9 "testing"
10 )
11
12
13
14 func TestSizeof(t *testing.T) {
15 const _64bit = ^uint(0)>>32 != 0
16
17 var tests = []struct {
18 val interface{}
19 _32bit uintptr
20 _64bit uintptr
21 }{
22
23 {Basic{}, 16, 32},
24 {Array{}, 16, 24},
25 {Slice{}, 8, 16},
26 {Struct{}, 24, 48},
27 {Pointer{}, 8, 16},
28 {Tuple{}, 12, 24},
29 {Signature{}, 28, 56},
30 {Union{}, 12, 24},
31 {Interface{}, 40, 80},
32 {Map{}, 16, 32},
33 {Chan{}, 12, 24},
34 {Named{}, 60, 112},
35 {TypeParam{}, 28, 48},
36 {term{}, 12, 24},
37
38
39 {PkgName{}, 60, 96},
40 {Const{}, 64, 104},
41 {TypeName{}, 56, 88},
42 {Var{}, 64, 104},
43 {Func{}, 64, 104},
44 {Label{}, 60, 96},
45 {Builtin{}, 60, 96},
46 {Nil{}, 56, 88},
47
48
49 {Scope{}, 60, 104},
50 {Package{}, 44, 88},
51 {_TypeSet{}, 28, 56},
52 }
53
54 for _, test := range tests {
55 got := reflect.TypeOf(test.val).Size()
56 want := test._32bit
57 if _64bit {
58 want = test._64bit
59 }
60 if got != want {
61 t.Errorf("unsafe.Sizeof(%T) = %d, want %d", test.val, got, want)
62 }
63 }
64 }
65
View as plain text