Throw more test cases at the message parser, fix edge case
This commit is contained in:
parent
b4bdcd4939
commit
f72253966b
@ -49,11 +49,11 @@ func parseMessage(line string) *Message {
|
|||||||
trailing = line[i+2:]
|
trailing = line[i+2:]
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := strings.Split(line[cmdStart:cmdEnd], " ")
|
cmd := strings.Fields(line[cmdStart:cmdEnd])
|
||||||
msg.Command = cmd[0]
|
if len(cmd) == 0 {
|
||||||
if msg.Command == "" {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
msg.Command = cmd[0]
|
||||||
|
|
||||||
if len(cmd) > 1 {
|
if len(cmd) > 1 {
|
||||||
msg.Params = cmd[1:]
|
msg.Params = cmd[1:]
|
||||||
|
@ -76,6 +76,30 @@ func TestParseMessage(t *testing.T) {
|
|||||||
Command: "CMD",
|
Command: "CMD",
|
||||||
Params: []string{"#cake", "pie"},
|
Params: []string{"#cake", "pie"},
|
||||||
},
|
},
|
||||||
|
}, {
|
||||||
|
"CMD #cake ::pie\r\n",
|
||||||
|
&Message{
|
||||||
|
Command: "CMD",
|
||||||
|
Params: []string{"#cake", ":pie"},
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
"CMD #cake : pie\r\n",
|
||||||
|
&Message{
|
||||||
|
Command: "CMD",
|
||||||
|
Params: []string{"#cake", " pie"},
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
"CMD #cake :pie :P <3\r\n",
|
||||||
|
&Message{
|
||||||
|
Command: "CMD",
|
||||||
|
Params: []string{"#cake", "pie :P <3"},
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
"CMD #cake :pie!\r\n",
|
||||||
|
&Message{
|
||||||
|
Command: "CMD",
|
||||||
|
Params: []string{"#cake", "pie!"},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user