forked from bytecodealliance/wasmtime-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
table_test.go
53 lines (43 loc) · 1.26 KB
/
table_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
44
45
46
47
48
49
50
51
52
53
package wasmtime
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestTable(t *testing.T) {
store := NewStore(NewEngine())
ty := NewTableType(NewValType(KindFuncref), 1, true, 3)
table, err := NewTable(store, ty, ValFuncref(nil))
require.NoError(t, err)
require.Equal(t, uint32(1), table.Size(store))
f, err := table.Get(store, 0)
require.NoError(t, err)
require.Nil(t, f.Funcref())
_, err = table.Get(store, 1)
require.Error(t, err)
err = table.Set(store, 0, ValFuncref(nil))
require.NoError(t, err)
err = table.Set(store, 1, ValFuncref(nil))
require.Error(t, err)
err = table.Set(store, 0, ValFuncref(WrapFunc(store, func() {})))
require.NoError(t, err)
f, err = table.Get(store, 0)
require.NoError(t, err)
require.NotNil(t, f.Funcref())
prevSize, err := table.Grow(store, 1, ValFuncref(nil))
require.NoError(t, err)
require.Equal(t, uint32(1), prevSize)
f, err = table.Get(store, 1)
require.NoError(t, err)
require.Nil(t, f.Funcref())
called := false
_, err = table.Grow(store, 1, ValFuncref(WrapFunc(store, func() {
called = true
})))
require.NoError(t, err)
f, err = table.Get(store, 2)
require.NoError(t, err)
require.False(t, called)
_, err = f.Funcref().Call(store)
require.NoError(t, err)
require.True(t, called)
}