forked from wdvxdr1123/ZeroBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathall_test.go
64 lines (54 loc) · 1.04 KB
/
all_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
package zero
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestType(t *testing.T) {
t1 := Type("notice/aaa/bbb")
t2 := Type("notice/aaa")
t3 := Type("aaa/aaa/bbb")
e1 := &Event{
PostType: "notice",
DetailType: "aaa",
SubType: "bbb",
}
testCtx.Event = e1
assert.Equal(t, true, t1(testCtx))
assert.Equal(t, true, t2(testCtx))
assert.Equal(t, false, t3(testCtx))
}
type pt struct {
x int
y int
}
var testState = State{
"hello": "world",
"pkg": int32(123),
"help": pt{
x: 1,
y: 2,
},
"love": 520.1314,
}
var testCtx = &Ctx{State: testState}
type testModel struct {
Hello string `zero:"hello"`
Pkg int32 `zero:"pkg"`
Help pt `zero:"help"`
Love float64 `zero:"love"`
}
func BenchmarkState_Parse(b *testing.B) {
a := &testModel{}
for i := 0; i < b.N; i++ {
_ = testCtx.Parse(a)
}
}
func TestState_Parse2(t *testing.T) {
a := &testModel{}
_ = testCtx.Parse(a)
assert.Equal(t, 520.1314, a.Love)
}
func TestMatcher_Delete(t *testing.T) {
OnCommand("").Delete()
assert.Empty(t, matcherList)
}