-
Notifications
You must be signed in to change notification settings - Fork 1
/
runtime_test.go
80 lines (73 loc) · 1.98 KB
/
runtime_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
package kinit
import (
"reflect"
"testing"
"github.com/go-kata/kdone"
"github.com/go-kata/kerror"
)
func TestRuntime(t *testing.T) {
var c int
ctr := NewContainer()
ctr.MustProvide(newTestConstructor(func() (int32, kdone.Destructor, error) {
c++
return int32(c), kdone.Noop, nil
}))
ctr.MustProvide(newTestConstructor(func() (int64, kdone.Destructor, error) {
c++
return int64(c), kdone.Noop, nil
}))
arena := NewArena()
defer arena.MustFinalize()
runtime := MustNewRuntime(ctr, arena)
runtime.MustPut(reflect.TypeOf(t), reflect.ValueOf(t), kdone.Noop)
runtime.MustRun(newTestFunctor(func(innerRuntime1 *Runtime, i32 int32) ([]Functor, error) {
if i32 != 1 {
return nil, kerror.Newf(kerror.EInvalid, "int32: %d expected, %d given", 1, i32)
}
innerRuntime1.MustPut(reflect.TypeOf(t), reflect.ValueOf(t), kdone.Noop)
innerRuntime1.MustRun(newTestFunctor(func(innerRuntime2 *Runtime, i32 int32, i64 int64) ([]Functor, error) {
if i32 != 1 {
return nil, kerror.Newf(kerror.EInvalid, "int32: %d expected, %d given", 1, i32)
}
if i64 != 2 {
return nil, kerror.Newf(kerror.EInvalid, "int64: %d expected, %d given", 2, i64)
}
innerRuntime2.MustPut(reflect.TypeOf(t), reflect.ValueOf(t), kdone.Noop)
return nil, nil
}))
return nil, nil
}))
}
func TestNewRuntime__NilContainer(t *testing.T) {
_, err := NewRuntime(nil, NewArena())
t.Logf("%+v", err)
if kerror.ClassOf(err) != kerror.EInvalid {
t.Fail()
return
}
}
func TestNewRuntime__NilArena(t *testing.T) {
_, err := NewRuntime(NewContainer(), nil)
t.Logf("%+v", err)
if kerror.ClassOf(err) != kerror.EInvalid {
t.Fail()
return
}
}
func TestNilRuntime_Put(t *testing.T) {
x := 1
err := (*Runtime)(nil).Put(reflect.TypeOf(x), reflect.ValueOf(x), kdone.Noop)
t.Logf("%+v", err)
if kerror.ClassOf(err) != kerror.ENil {
t.Fail()
return
}
}
func TestNilRuntime_Run(t *testing.T) {
err := (*Runtime)(nil).Run()
t.Logf("%+v", err)
if kerror.ClassOf(err) != kerror.ENil {
t.Fail()
return
}
}