-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstate_test.go
119 lines (104 loc) · 2.72 KB
/
state_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
// This file is part of Botgoram
// Botgoram is free software: see LICENSE.txt for more details.
package botgoram
import (
"testing"
"github.com/Patrolavia/telegram"
)
func TestTypeTransitors(t *testing.T) {
st := newState("")
m := func() *telegram.Message {
return &telegram.Message{
From: &telegram.Victim{},
Chat: &telegram.Victim{},
}
}
factory := func(result string) Transitor {
f := func(msg *telegram.Message, state State) (next string, err error) {
return result, nil
}
return f
}
types := []string{
TextMsg,
FileMsg,
AudioMsg,
PhotoMsg,
StickerMsg,
VideoMsg,
VoiceMsg,
ContactMsg,
LocationMsg,
VenueMsg,
}
for _, t := range types {
st.Register(t, factory(t))
}
st.RegisterCommand("Command", factory("Command"))
// contact
msg := m()
msg.Contact = &telegram.Contact{}
if next, _ := st.test(msg); next != ContactMsg {
t.Errorf("While testing contact transitor: get next state %s", next)
}
// location
msg = m()
msg.Location = &telegram.Location{}
if next, _ := st.test(msg); next != LocationMsg {
t.Errorf("While testing location transitor: get next state %s", next)
}
// sticker
msg = m()
msg.Sticker = &telegram.Sticker{}
if next, _ := st.test(msg); next != StickerMsg {
t.Errorf("While testing sticker transitor: get next state %s", next)
}
// photo
msg = m()
msg.Photo = []telegram.PhotoSize{telegram.PhotoSize{}}
if next, _ := st.test(msg); next != PhotoMsg {
t.Errorf("While testing photo transitor: get next state %s", next)
}
// video
msg = m()
msg.Video = &telegram.Video{}
if next, _ := st.test(msg); next != VideoMsg {
t.Errorf("While testing video transitor: get next state %s", next)
}
// voice
msg = m()
msg.Voice = &telegram.Voice{}
if next, _ := st.test(msg); next != VoiceMsg {
t.Errorf("While testing voice transitor: get next state %s", next)
}
// audio
msg = m()
msg.Audio = &telegram.Audio{}
if next, _ := st.test(msg); next != AudioMsg {
t.Errorf("While testing audio transitor: get next state %s", next)
}
// document
msg = m()
msg.Document = &telegram.Document{}
if next, _ := st.test(msg); next != FileMsg {
t.Errorf("While testing document transitor: get next state %s", next)
}
// text
msg = m()
msg.Text = "asd"
if next, _ := st.test(msg); next != TextMsg {
t.Errorf("While testing text transitor: get next state %s", next)
}
// command
msg = m()
msg.Text = "Command"
if next, _ := st.test(msg); next != "Command" {
t.Errorf("While testing command transitor: get next state %s", next)
}
// command mismatch, fallback to text transitor
msg = m()
msg.Text = "Command2"
if next, _ := st.test(msg); next != TextMsg {
t.Errorf("While testing command transitor: not fallback to text, get next state %s", next)
}
}