From c78ca7318cf9aa9ae4758e4d0ad1929a71ee7855 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ken-H=C3=A5vard=20Lieng?= Date: Wed, 10 Jun 2015 22:53:29 +0200 Subject: [PATCH] Add more parseMessage() test cases, handle a prefix edge case --- irc/message.go | 2 ++ irc/message_test.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/irc/message.go b/irc/message.go index 8ff822d4..7d4bbea1 100644 --- a/irc/message.go +++ b/irc/message.go @@ -24,6 +24,8 @@ func parseMessage(line string) *Message { if i := strings.Index(msg.Prefix, "!"); i > 0 { msg.Nick = msg.Prefix[:i] + } else if i := strings.Index(msg.Prefix, "@"); i > 0 { + msg.Nick = msg.Prefix[:i] } else { msg.Nick = msg.Prefix } diff --git a/irc/message_test.go b/irc/message_test.go index f76755bc..41a06d79 100644 --- a/irc/message_test.go +++ b/irc/message_test.go @@ -34,6 +34,38 @@ func TestParseMessage(t *testing.T) { Command: "CMD", 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", + }, }, }