forked from bytecodealliance/wasmtime-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable_test.go
85 lines (79 loc) · 1.47 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package wasmtime
import "testing"
func TestTable(t *testing.T) {
store := NewStore(NewEngine())
ty := NewTableType(NewValType(KindFuncref), 1, true, 3)
table, err := NewTable(store, ty, ValFuncref(nil))
if err != nil {
panic(err)
}
if table.Size(store) != 1 {
panic("wrong size")
}
f, err := table.Get(store, 0)
if err != nil {
panic(err)
}
if f.Funcref() != nil {
panic("expected nil")
}
f, err = table.Get(store, 1)
if err == nil {
panic("expected error")
}
err = table.Set(store, 0, ValFuncref(nil))
if err != nil {
panic(err)
}
err = table.Set(store, 1, ValFuncref(nil))
if err == nil {
panic("expected error")
}
err = table.Set(store, 0, ValFuncref(WrapFunc(store, func() {})))
if err != nil {
panic(nil)
}
f, err = table.Get(store, 0)
if err != nil {
panic(err)
}
if f.Funcref() == nil {
panic("expected not nil")
}
prevSize, err := table.Grow(store, 1, ValFuncref(nil))
if err != nil {
panic(err)
}
if prevSize != 1 {
print(prevSize)
panic("bad prev")
}
f, err = table.Get(store, 1)
if err != nil {
panic(err)
}
if f.Funcref() != nil {
panic("expected nil")
}
called := false
_, err = table.Grow(store, 1, ValFuncref(WrapFunc(store, func() {
called = true
})))
if err != nil {
panic(err)
}
f, err = table.Get(store, 2)
if err != nil {
panic(err)
}
if called {
panic("called already?")
}
_, err = f.Funcref().Call(store)
if err != nil {
panic(err)
}
if !called {
panic("should have called")
}
}