Files
wazero/internal/wasm/binary/limits_test.go
Crypt Keeper ce1052a097 Isolates testify to one file, so that it is easier to remove (#460)
This starts the process of removing all dependencies from wazero, by
isolating all assertions we use into a single file. This allows us to
port those assertions as we have time, and when twitchy is gone, the
project literally has no dependencies except go!

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-04-14 10:05:38 +08:00

65 lines
1.3 KiB
Go

package binary
import (
"bytes"
"fmt"
"math"
"testing"
"github.com/tetratelabs/wazero/internal/testing/require"
)
func TestLimitsType(t *testing.T) {
zero := uint32(0)
largest := uint32(math.MaxUint32)
tests := []struct {
name string
min uint32
max *uint32
expected []byte
}{
{
name: "min 0",
expected: []byte{0x0, 0},
},
{
name: "min 0, max 0",
max: &zero,
expected: []byte{0x1, 0, 0},
},
{
name: "min largest",
min: largest,
expected: []byte{0x0, 0xff, 0xff, 0xff, 0xff, 0xf},
},
{
name: "min 0, max largest",
max: &largest,
expected: []byte{0x1, 0, 0xff, 0xff, 0xff, 0xff, 0xf},
},
{
name: "min largest max largest",
min: largest,
max: &largest,
expected: []byte{0x1, 0xff, 0xff, 0xff, 0xff, 0xf, 0xff, 0xff, 0xff, 0xff, 0xf},
},
}
for _, tt := range tests {
tc := tt
b := encodeLimitsType(tc.min, tc.max)
t.Run(fmt.Sprintf("encode - %s", tc.name), func(t *testing.T) {
require.Equal(t, tc.expected, b)
})
t.Run(fmt.Sprintf("decode - %s", tc.name), func(t *testing.T) {
min, max, err := decodeLimitsType(bytes.NewReader(b))
require.NoError(t, err)
require.Equal(t, min, tc.min)
require.Equal(t, max, tc.max)
})
}
}