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:
Crypt Keeper
2022-04-06 06:35:31 +08:00
committed by GitHub
parent b1cffcc58e
commit f5598c9a8e
14 changed files with 153 additions and 62 deletions

39
internal/u64/u64_test.go Normal file
View 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))
})
}
}