github.com/neonyo/sys@v0.0.0-20230720094341-b1ee14be3ce8/cpu/endian_test.go (about)

     1  // Copyright 2023 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 cpu_test
     6  
     7  import (
     8  	"testing"
     9  	"unsafe"
    10  
    11  	"golang.org/x/sys/cpu"
    12  )
    13  
    14  func TestIsBigEndian(t *testing.T) {
    15  	b := uint16(0xff00)
    16  	want := *(*byte)(unsafe.Pointer(&b)) == 0xff
    17  	if cpu.IsBigEndian != want {
    18  		t.Errorf("IsBigEndian = %t, want %t",
    19  			cpu.IsBigEndian, want)
    20  	}
    21  }