-
Notifications
You must be signed in to change notification settings - Fork 56
/
gomodule_test.go
63 lines (49 loc) · 1.15 KB
/
gomodule_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
package py
import (
"fmt"
"testing"
)
// ------------------------------------------------------------------------------------------
type FooModule struct {
}
func (r *FooModule) Py_bar(args *Tuple) (ret *Base, err error) {
var i int
var s []string
err = ParseV(args, &i, &s)
if err != nil {
return
}
fmt.Println("call foo.bar:", i, s)
return IncNone(), nil
}
// ------------------------------------------------------------------------------------------
type gomoduleCase struct {
exp string
name string
}
var g_gomoduleCases = []gomoduleCase{
{
`import foo
foo.bar(1, 'Hello')
`, "test"},
}
func TestGoModule(t *testing.T) {
gomod, err := NewGoModule("foo", "", new(FooModule))
if err != nil {
t.Fatal("NewGoModule failed:", err)
}
defer gomod.Decref()
for _, c := range g_gomoduleCases {
code, err := Compile(c.exp, "", FileInput)
if err != nil {
t.Fatal("Compile failed:", err)
}
defer code.Decref()
mod, err := ExecCodeModule(c.name, code.Obj())
if err != nil {
t.Fatal("ExecCodeModule failed:", err)
}
defer mod.Decref()
}
}
// ------------------------------------------------------------------------------------------