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