1
2
3
4
5
6
7 package types
8
9 import (
10 "reflect"
11 "testing"
12 "unsafe"
13 )
14
15
16
17 func TestSizeof(t *testing.T) {
18 const _64bit = unsafe.Sizeof(uintptr(0)) == 8
19
20 var tests = []struct {
21 val interface{}
22 _32bit uintptr
23 _64bit uintptr
24 }{
25 {Sym{}, 52, 88},
26 {Type{}, 52, 88},
27 {Map{}, 20, 40},
28 {Forward{}, 20, 32},
29 {Func{}, 32, 56},
30 {Struct{}, 16, 32},
31 {Interface{}, 8, 16},
32 {Chan{}, 8, 16},
33 {Array{}, 12, 16},
34 {DDDField{}, 4, 8},
35 {FuncArgs{}, 4, 8},
36 {ChanArgs{}, 4, 8},
37 {Ptr{}, 4, 8},
38 {Slice{}, 4, 8},
39 }
40
41 for _, tt := range tests {
42 want := tt._32bit
43 if _64bit {
44 want = tt._64bit
45 }
46 got := reflect.TypeOf(tt.val).Size()
47 if want != got {
48 t.Errorf("unsafe.Sizeof(%T) = %d, want %d", tt.val, got, want)
49 }
50 }
51 }
52
View as plain text