forked from yurigorokhov/mtflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_test.go
63 lines (58 loc) · 1.69 KB
/
parse_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
package main
import (
"testing"
)
func TestParse_empty_command(t *testing.T) {
_, err := ParseCommand(" ")
if err == nil {
t.Error("Empty command should have error")
}
}
func TestParse_unrecognized_command(t *testing.T) {
comm, err := ParseCommand(" lsdjhfl rwiuhgirehg erhgiuerhg oehrgioerhg,!#$% ")
if err != nil {
t.Error("No error expected")
}
if comm.Target != CommandTargetNone {
t.Error("command target none expexted")
}
if comm.Type != CommandNone {
t.Error("command type none expexted")
}
}
func TestParse_command_type(t *testing.T) {
comm, err := ParseCommand(" @nataren, please give me the status of pr ")
if err != nil {
t.Error("Unexpected error: ", err.Error())
}
if comm.Type != CommandStatus {
t.Error("Expected type status but was: ", comm.Type)
}
if comm.Mentions[0] != "@nataren" {
t.Error("Expected prefix @nataren but was: ", comm.Mentions)
}
if comm.Target != CommandTargetPR {
t.Error("Expected type pr but was: ", comm.Target)
}
}
func TestParse_command_with_user_parsing(t *testing.T) {
comm, err := ParseCommand(" @nataren, @yurig please !@manuel! give me the status of pr ")
if err != nil {
t.Error("Unexpected error: ", err.Error())
}
if comm.Type != CommandStatus {
t.Error("Expected type status but was: ", comm.Type)
}
if comm.Mentions[0] != "@nataren" {
t.Error("Expected prefix @nataren but was: ", comm.Mentions[0])
}
if comm.Mentions[1] != "@yurig" {
t.Error("Expected prefix @nataren but was: ", comm.Mentions[0])
}
if comm.Mentions[2] != "@manuel" {
t.Error("Expected prefix @nataren but was: ", comm.Mentions[0])
}
if comm.Target != CommandTargetPR {
t.Error("Expected type pr but was: ", comm.Target)
}
}