github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/cmd/link/internal/sym/sizeof_test.go (about) 1 // Copyright 2018 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package sym 6 7 import ( 8 "reflect" 9 "testing" 10 "unsafe" 11 ) 12 13 // Assert that the size of important structures do not change unexpectedly. 14 15 func TestSizeof(t *testing.T) { 16 const nbit = unsafe.Sizeof(uintptr(0)) * 8 17 const _64bit = nbit == 64 18 19 var tests = []struct { 20 val interface{} // type as a value 21 _32bit uintptr // size on 32bit platforms 22 _64bit uintptr // size on 64bit platforms 23 }{ 24 {Symbol{}, 108, 176}, 25 } 26 27 for _, tt := range tests { 28 want := tt._32bit 29 if _64bit { 30 want = tt._64bit 31 } 32 got := reflect.TypeOf(tt.val).Size() 33 if want != got { 34 t.Errorf("%d bit unsafe.Sizeof(%T) = %d, want %d", nbit, tt.val, got, want) 35 } 36 } 37 }