Return empty string from LastParam() if theres no params

This commit is contained in:
Ken-Håvard Lieng 2017-06-21 07:20:31 +02:00
parent a4ebd8d4c4
commit 4a74463ae8
2 changed files with 5 additions and 1 deletions

View File

@ -12,8 +12,11 @@ type Message struct {
} }
func (m *Message) LastParam() string { func (m *Message) LastParam() string {
if len(m.Params) > 0 {
return m.Params[len(m.Params)-1] return m.Params[len(m.Params)-1]
} }
return ""
}
func parseMessage(line string) *Message { func parseMessage(line string) *Message {
line = strings.Trim(line, "\r\n") line = strings.Trim(line, "\r\n")

View File

@ -74,6 +74,7 @@ func TestParseMessage(t *testing.T) {
func TestLastParam(t *testing.T) { func TestLastParam(t *testing.T) {
assert.Equal(t, "some message", parseMessage(":user CMD #chan :some message\r\n").LastParam()) assert.Equal(t, "some message", parseMessage(":user CMD #chan :some message\r\n").LastParam())
assert.Equal(t, "", parseMessage("NO_PARAMS").LastParam())
} }
func TestBadMessagePanic(t *testing.T) { func TestBadMessagePanic(t *testing.T) {