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