Use correct pattern for table tests everywhere (#582)

Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
This commit is contained in:
Anuraag Agrawal
2022-05-20 16:55:01 +09:00
committed by GitHub
parent 7794530d01
commit ec3ada35a0
28 changed files with 636 additions and 332 deletions

View File

@@ -11,7 +11,7 @@ import (
)
func TestFuncName(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
name, moduleName, funcName string
funcIdx uint32
expected string
@@ -25,8 +25,10 @@ func TestFuncName(t *testing.T) {
{name: "dots in function", moduleName: "x", funcName: "y.z", expected: "x.y.z"},
{name: "spaces in module", moduleName: "w x", funcName: "y", expected: "w x.y"},
{name: "spaces in function", moduleName: "x", funcName: "y z", expected: "x.y z"},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
funcName := FuncName(tc.moduleName, tc.funcName, tc.funcIdx)
require.Equal(t, tc.expected, funcName)
@@ -36,7 +38,7 @@ func TestFuncName(t *testing.T) {
func TestAddSignature(t *testing.T) {
i32, i64, f32, f64 := api.ValueTypeI32, api.ValueTypeI64, api.ValueTypeF32, api.ValueTypeF64
for _, tc := range []struct {
tests := []struct {
name string
paramTypes, resultTypes []api.ValueType
expected string
@@ -51,8 +53,10 @@ func TestAddSignature(t *testing.T) {
{name: "i32_i64", paramTypes: []api.ValueType{i32}, resultTypes: []api.ValueType{i64}, expected: "x.y(i32) i64"},
{name: "i64f32_i64f32", paramTypes: []api.ValueType{i64, f32}, resultTypes: []api.ValueType{i64, f32}, expected: "x.y(i64,f32) (i64,f32)"},
{name: "i64f32f64_f32i32f64", paramTypes: []api.ValueType{i64, f32, f64}, resultTypes: []api.ValueType{f32, i32, f64}, expected: "x.y(i64,f32,f64) (f32,i32,f64)"},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
withSignature := signature("x.y", tc.paramTypes, tc.resultTypes)
require.Equal(t, tc.expected, withSignature)
@@ -66,7 +70,7 @@ func TestErrorBuilder(t *testing.T) {
i32 := api.ValueTypeI32
i32i32i32i32 := []api.ValueType{i32, i32, i32, i32}
for _, tc := range []struct {
tests := []struct {
name string
build func(ErrorBuilder) error
expectedErr string
@@ -122,8 +126,10 @@ wasm stack trace:
x.y()`,
expectUnwrap: wasmruntime.ErrRuntimeCallStackOverflow,
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
withStackTrace := tc.build(NewErrorBuilder())
require.Equal(t, tc.expectUnwrap, errors.Unwrap(withStackTrace))