This repository has been archived by the owner on Jan 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
parser_test.go
72 lines (58 loc) · 1.88 KB
/
parser_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
package bot
import (
"fmt"
. "github.com/smartystreets/goconvey/convey"
"testing"
)
var (
DefaultChannel = "#go-bot"
DefaultNick = "user123"
DefaultCommand = "command"
DefaultFullArg = "arg1 arg2"
DefaultArgs = []string{
"arg1",
"arg2",
}
)
func TestPaser(t *testing.T) {
Convey("When given a message", t, func() {
Convey("When the message is empty", func() {
cmd := parse("", DefaultChannel, DefaultNick)
So(cmd, ShouldBeNil)
})
Convey("When the message doesn't have the prefix", func() {
Message := "regular message"
cmd := parse(Message, DefaultChannel, DefaultNick)
So(cmd, ShouldBeNil)
})
Convey("When the message is only the prefix", func() {
cmd := parse(CmdPrefix, DefaultChannel, DefaultNick)
So(cmd, ShouldBeNil)
})
Convey("When the message is valid command", func() {
msg := fmt.Sprintf("%v%v", CmdPrefix, DefaultCommand)
cmd := parse(msg, DefaultChannel, DefaultNick)
So(cmd, ShouldNotBeNil)
So(cmd.Command, ShouldEqual, DefaultCommand)
So(cmd.Channel, ShouldEqual, DefaultChannel)
})
Convey("When the message is a command with args", func() {
msg := fmt.Sprintf("%v%v %v", CmdPrefix, DefaultCommand, DefaultFullArg)
cmd := parse(msg, DefaultChannel, DefaultNick)
So(cmd, ShouldNotBeNil)
So(cmd.Command, ShouldEqual, DefaultCommand)
So(cmd.Channel, ShouldEqual, DefaultChannel)
So(cmd.Args, ShouldResemble, DefaultArgs)
So(cmd.FullArg, ShouldEqual, DefaultFullArg)
})
Convey("When the message has extra spaces", func() {
msg := fmt.Sprintf(" %v %v %v %v ", CmdPrefix, DefaultCommand, DefaultArgs[0], DefaultArgs[1])
cmd := parse(msg, DefaultChannel, DefaultNick)
So(cmd, ShouldNotBeNil)
So(cmd.Command, ShouldEqual, DefaultCommand)
So(cmd.Channel, ShouldEqual, DefaultChannel)
So(cmd.Args, ShouldResemble, DefaultArgs)
So(cmd.FullArg, ShouldEqual, DefaultFullArg)
})
})
}