-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctor_test.go
50 lines (41 loc) · 978 Bytes
/
functor_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
package kinit
import "reflect"
// func(...) ([]Functor, error)
type testFunctor struct {
f reflect.Value
in []reflect.Type
}
func newTestFunctor(x interface{}) *testFunctor {
ft := reflect.TypeOf(x)
f := &testFunctor{
f: reflect.ValueOf(x),
}
numIn := ft.NumIn()
f.in = make([]reflect.Type, numIn)
for i := 0; i < numIn; i++ {
f.in[i] = ft.In(i)
}
return f
}
func (f *testFunctor) Parameters() []reflect.Type {
return f.in
}
func (f *testFunctor) Call(a ...reflect.Value) ([]Functor, error) {
out := f.f.Call(a)
var further []Functor
if v := out[0].Interface(); v != nil {
further = v.([]Functor)
}
var err error
if v := out[1].Interface(); v != nil {
err = v.(error)
}
return further, err
}
type testFunctorWithBrokenParameters struct{}
func (testFunctorWithBrokenParameters) Parameters() []reflect.Type {
return []reflect.Type{nil}
}
func (testFunctorWithBrokenParameters) Call(a ...reflect.Value) ([]Functor, error) {
return nil, nil
}