github.com/tetratelabs/wazero@v1.7.3-0.20240513003603-48f702e154b5/internal/u64/u64_test.go (about)

     1  package u64
     2  
     3  import (
     4  	"encoding/binary"
     5  	"math"
     6  	"testing"
     7  
     8  	"github.com/tetratelabs/wazero/internal/testing/require"
     9  )
    10  
    11  func TestBytes(t *testing.T) {
    12  	tests := []struct {
    13  		name  string
    14  		input uint64
    15  	}{
    16  		{
    17  			name:  "zero",
    18  			input: 0,
    19  		},
    20  		{
    21  			name:  "half",
    22  			input: math.MaxUint32,
    23  		},
    24  		{
    25  			name:  "max",
    26  			input: math.MaxUint64,
    27  		},
    28  	}
    29  
    30  	for _, tt := range tests {
    31  		tc := tt
    32  
    33  		t.Run(tc.name, func(t *testing.T) {
    34  			expected := make([]byte, 8)
    35  			binary.LittleEndian.PutUint64(expected, tc.input)
    36  			require.Equal(t, expected, LeBytes(tc.input))
    37  		})
    38  	}
    39  }