forked from bytecodealliance/wasmtime-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
functype_test.go
43 lines (34 loc) · 1.23 KB
/
functype_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package wasmtime
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestFuncType(t *testing.T) {
NewFuncType(make([]*ValType, 0), make([]*ValType, 0))
i32 := NewValType(KindI32)
i64 := NewValType(KindI64)
NewFuncType([]*ValType{i32}, []*ValType{})
NewFuncType([]*ValType{i32}, []*ValType{i32})
NewFuncType([]*ValType{}, []*ValType{i32})
NewFuncType([]*ValType{i32, i64, i64}, []*ValType{i32, i64, i64})
ty := NewFuncType([]*ValType{}, []*ValType{})
require.Len(t, ty.Params(), 0)
require.Len(t, ty.Results(), 0)
ty = NewFuncType([]*ValType{i32, i64, i64}, []*ValType{i32, i64, i64})
params := ty.Params()
require.Len(t, ty.Params(), 3)
require.Equal(t, KindI32, params[0].Kind())
require.Equal(t, KindI64, params[1].Kind())
require.Equal(t, KindI64, params[2].Kind())
results := ty.Results()
require.Len(t, ty.Params(), 3)
require.Equal(t, KindI32, results[0].Kind())
require.Equal(t, KindI64, results[1].Kind())
require.Equal(t, KindI64, results[2].Kind())
ty = NewFuncType([]*ValType{}, []*ValType{})
ty2 := ty.AsExternType().FuncType()
require.NotNil(t, ty2)
require.Nil(t, ty.AsExternType().GlobalType())
require.Nil(t, ty.AsExternType().MemoryType())
require.Nil(t, ty.AsExternType().TableType())
}