github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/cmd/compile/internal/gc/sizeof_test.go (about)

     1  // Copyright 2016 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 gc
     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 _64bit = unsafe.Sizeof(uintptr(0)) == 8
    17  
    18  	var tests = []struct {
    19  		val    interface{} // type as a value
    20  		_32bit uintptr     // size on 32bit platforms
    21  		_64bit uintptr     // size on 64bit platforms
    22  	}{
    23  		{Func{}, 124, 224},
    24  		{Name{}, 32, 56},
    25  		{Param{}, 24, 48},
    26  		{Node{}, 76, 128},
    27  	}
    28  
    29  	for _, tt := range tests {
    30  		want := tt._32bit
    31  		if _64bit {
    32  			want = tt._64bit
    33  		}
    34  		got := reflect.TypeOf(tt.val).Size()
    35  		if want != got {
    36  			t.Errorf("unsafe.Sizeof(%T) = %d, want %d", tt.val, got, want)
    37  		}
    38  	}
    39  }