Add Message.LastParam()
This commit is contained in:
parent
83056c5396
commit
cc3b1e3a82
4 changed files with 22 additions and 14 deletions
|
@ -179,7 +179,7 @@ func (c *Client) recv() {
|
|||
|
||||
switch msg.Command {
|
||||
case Ping:
|
||||
go c.write("PONG :" + msg.Params[len(msg.Params)-1])
|
||||
go c.write("PONG :" + msg.LastParam())
|
||||
|
||||
case Join:
|
||||
if msg.Nick == c.GetNick() {
|
||||
|
|
|
@ -11,6 +11,10 @@ type Message struct {
|
|||
Params []string
|
||||
}
|
||||
|
||||
func (m *Message) LastParam() string {
|
||||
return m.Params[len(m.Params)-1]
|
||||
}
|
||||
|
||||
func parseMessage(line string) *Message {
|
||||
line = strings.Trim(line, "\r\n")
|
||||
msg := Message{}
|
||||
|
|
|
@ -72,6 +72,10 @@ func TestParseMessage(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestLastParam(t *testing.T) {
|
||||
assert.Equal(t, "some message", parseMessage(":user CMD #chan :some message\r\n").LastParam())
|
||||
}
|
||||
|
||||
func TestBadMessagePanic(t *testing.T) {
|
||||
parseMessage(":user\r\n")
|
||||
parseMessage(":\r\n")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue