This repository was archived by the owner on Feb 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocessor_test.go
134 lines (120 loc) · 2.84 KB
/
processor_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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package kinitx
import (
"reflect"
"testing"
"github.com/go-kata/kerror"
)
func TestProcessor__FunctionReturningNothing(t *testing.T) {
var c int
proc := MustNewProcessor(func(v *int, i int8) { *v += int(i) })
t.Logf("%+v %+v", proc.Type(), proc.Parameters())
if err := proc.Process(reflect.ValueOf(&c), reflect.ValueOf(int8(1))); err != nil {
t.Logf("%+v", err)
t.Fail()
return
}
if c != 1 {
t.Fail()
return
}
}
func TestProcessor__FunctionReturningError(t *testing.T) {
var c int
proc := MustNewProcessor(func(v *int, i int8) error {
*v += int(i)
return nil
})
t.Logf("%+v %+v", proc.Type(), proc.Parameters())
if err := proc.Process(reflect.ValueOf(&c), reflect.ValueOf(int8(1))); err != nil {
t.Logf("%+v", err)
t.Fail()
return
}
if c != 1 {
t.Fail()
return
}
}
func TestNewProcessor__Nil(t *testing.T) {
_, err := NewProcessor(nil)
t.Logf("%+v", err)
if kerror.ClassOf(err) != kerror.EViolation {
t.Fail()
return
}
}
func TestNewProcessor__NilFunction(t *testing.T) {
_, err := NewProcessor((func())(nil))
t.Logf("%+v", err)
if kerror.ClassOf(err) != kerror.EViolation {
t.Fail()
return
}
}
func TestNewProcessor__WrongType(t *testing.T) {
_, err := NewProcessor(0)
t.Logf("%+v", err)
if kerror.ClassOf(err) != kerror.EViolation {
t.Fail()
return
}
}
func TestNewProcessor__WrongSignature(t *testing.T) {
_, err := NewProcessor(func() {})
t.Logf("%+v", err)
if kerror.ClassOf(err) != kerror.EViolation {
t.Fail()
return
}
}
func TestProcessor_Process__WrongObjectType(t *testing.T) {
proc := MustNewProcessor(func(v *int, i int8) { *v += int(i) })
t.Logf("%+v %+v", proc.Type(), proc.Parameters())
err := proc.Process(reflect.ValueOf(""), reflect.ValueOf(int8(1)))
t.Logf("%+v", err)
if kerror.ClassOf(err) != kerror.EViolation {
t.Fail()
return
}
}
func TestProcessor_Process__WrongNumberOfArguments(t *testing.T) {
var c int
proc := MustNewProcessor(func(v *int, i int8) { *v += int(i) })
t.Logf("%+v %+v", proc.Type(), proc.Parameters())
err := proc.Process(reflect.ValueOf(&c))
t.Logf("%+v", err)
if kerror.ClassOf(err) != kerror.EViolation {
t.Fail()
return
}
}
func TestProcessor_Process__WrongArgumentType(t *testing.T) {
var c int
proc := MustNewProcessor(func(v *int, i int8) { *v += int(i) })
t.Logf("%+v %+v", proc.Type(), proc.Parameters())
err := proc.Process(reflect.ValueOf(&c), reflect.ValueOf(""))
t.Logf("%+v", err)
if kerror.ClassOf(err) != kerror.EViolation {
t.Fail()
return
}
}
func TestNilProcessor_Type(t *testing.T) {
if (*Processor)(nil).Type() != nil {
t.Fail()
return
}
}
func TestNilProcessor_Parameters(t *testing.T) {
if (*Processor)(nil).Parameters() != nil {
t.Fail()
return
}
}
func TestNilProcessor_Process(t *testing.T) {
if err := (*Processor)(nil).Process(reflect.Value{}); err != nil {
t.Logf("%+v", err)
t.Fail()
return
}
}