Add more parseMessage() test cases, handle a prefix edge case

This commit is contained in:
Ken-Håvard Lieng 2015-06-10 22:53:29 +02:00
parent da8915328d
commit c78ca7318c
2 changed files with 34 additions and 0 deletions

View File

@ -24,6 +24,8 @@ func parseMessage(line string) *Message {
if i := strings.Index(msg.Prefix, "!"); i > 0 { if i := strings.Index(msg.Prefix, "!"); i > 0 {
msg.Nick = msg.Prefix[:i] msg.Nick = msg.Prefix[:i]
} else if i := strings.Index(msg.Prefix, "@"); i > 0 {
msg.Nick = msg.Prefix[:i]
} else { } else {
msg.Nick = msg.Prefix msg.Nick = msg.Prefix
} }

View File

@ -34,6 +34,38 @@ func TestParseMessage(t *testing.T) {
Command: "CMD", Command: "CMD",
Params: []string{"a", "b"}, Params: []string{"a", "b"},
}, },
}, {
"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{
Command: "CMD",
Params: []string{"tests and stuff"},
Trailing: "tests and stuff",
},
}, {
":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",
},
}, },
} }