2015-06-10 03:48:54 +00:00
|
|
|
package irc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2016-03-01 00:51:26 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2015-06-10 03:48:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestParseMessage(t *testing.T) {
|
|
|
|
cases := []struct {
|
|
|
|
input string
|
|
|
|
expected *Message
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
":user CMD #chan :some message\r\n",
|
|
|
|
&Message{
|
2016-12-12 06:19:22 +00:00
|
|
|
Prefix: "user",
|
|
|
|
Nick: "user",
|
|
|
|
Command: "CMD",
|
|
|
|
Params: []string{"#chan", "some message"},
|
2015-06-10 03:48:54 +00:00
|
|
|
},
|
|
|
|
}, {
|
|
|
|
":nick!user@host.com CMD a b\r\n",
|
|
|
|
&Message{
|
|
|
|
Prefix: "nick!user@host.com",
|
|
|
|
Nick: "nick",
|
|
|
|
Command: "CMD",
|
|
|
|
Params: []string{"a", "b"},
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
"CMD a b :\r\n",
|
|
|
|
&Message{
|
|
|
|
Command: "CMD",
|
2016-12-12 06:19:22 +00:00
|
|
|
Params: []string{"a", "b", ""},
|
2015-06-10 03:48:54 +00:00
|
|
|
},
|
2015-06-10 20:53:29 +00:00
|
|
|
}, {
|
|
|
|
"CMD a b\r\n",
|
|
|
|
&Message{
|
|
|
|
Command: "CMD",
|
|
|
|
Params: []string{"a", "b"},
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
"CMD\r\n",
|
|
|
|
&Message{
|
|
|
|
Command: "CMD",
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
"CMD :tests and stuff\r\n",
|
|
|
|
&Message{
|
2016-12-12 06:19:22 +00:00
|
|
|
Command: "CMD",
|
|
|
|
Params: []string{"tests and stuff"},
|
2015-06-10 20:53:29 +00:00
|
|
|
},
|
|
|
|
}, {
|
|
|
|
":nick@host.com CMD\r\n",
|
|
|
|
&Message{
|
|
|
|
Prefix: "nick@host.com",
|
|
|
|
Nick: "nick",
|
|
|
|
Command: "CMD",
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
":ni@ck!user!name@host!.com CMD\r\n",
|
|
|
|
&Message{
|
|
|
|
Prefix: "ni@ck!user!name@host!.com",
|
|
|
|
Nick: "ni@ck",
|
|
|
|
Command: "CMD",
|
|
|
|
},
|
2015-06-10 03:48:54 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
|
|
|
assert.Equal(t, tc.expected, parseMessage(tc.input))
|
|
|
|
}
|
|
|
|
}
|
2016-12-16 22:49:37 +00:00
|
|
|
|
2016-12-16 23:11:44 +00:00
|
|
|
func TestLastParam(t *testing.T) {
|
|
|
|
assert.Equal(t, "some message", parseMessage(":user CMD #chan :some message\r\n").LastParam())
|
|
|
|
}
|
|
|
|
|
2016-12-16 22:49:37 +00:00
|
|
|
func TestBadMessagePanic(t *testing.T) {
|
|
|
|
parseMessage(":user\r\n")
|
|
|
|
parseMessage(":\r\n")
|
|
|
|
parseMessage(":")
|
|
|
|
parseMessage("")
|
|
|
|
}
|