Fixes global numeric types to have max of signed encoding (#442)
This adjusts towards the exiting code which used int32/64 instead of uint32/64. The reason is that the spec indicates intepretation as signed numbers, which affects the maximum value. See https://www.w3.org/TR/wasm-core-1/#value-types%E2%91%A2 Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
39
internal/u64/u64_test.go
Normal file
39
internal/u64/u64_test.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package u64
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"math"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestBytes(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input uint64
|
||||
}{
|
||||
{
|
||||
name: "zero",
|
||||
input: 0,
|
||||
},
|
||||
{
|
||||
name: "half",
|
||||
input: math.MaxUint32,
|
||||
},
|
||||
{
|
||||
name: "max",
|
||||
input: math.MaxUint64,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
tc := tt
|
||||
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
expected := make([]byte, 8)
|
||||
binary.LittleEndian.PutUint64(expected, tc.input)
|
||||
require.Equal(t, expected, LeBytes(tc.input))
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user