mirror of https://github.com/fluffle/goirc
Fix comments and my poor code-reading skills. Damn you StalkR :-)
This commit is contained in:
parent
2c5b477233
commit
d6cb0bb026
|
@ -30,16 +30,10 @@ const (
|
||||||
WHOIS = "WHOIS"
|
WHOIS = "WHOIS"
|
||||||
)
|
)
|
||||||
|
|
||||||
// this file contains the various commands you can
|
// cutNewLines() pares down a string to the part before the first "\r" or "\n"
|
||||||
// send to the server using an Conn connection
|
|
||||||
|
|
||||||
// This could be a lot less ugly with the ability to manipulate
|
|
||||||
// the symbol table and add methods/functions on the fly
|
|
||||||
// [ CMD, FMT, FMTARGS ] etc.
|
|
||||||
|
|
||||||
func cutNewLines(s string) string {
|
func cutNewLines(s string) string {
|
||||||
r := strings.SplitN(s, "\\r", 2)
|
r := strings.SplitN(s, "\r", 2)
|
||||||
r = strings.SplitN(r[0], "\\n", 2)
|
r = strings.SplitN(r[0], "\n", 2)
|
||||||
return r[0]
|
return r[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,25 @@ package client
|
||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
|
func TestCutNewLines(t *testing.T) {
|
||||||
|
tests := []struct{ in, out string }{
|
||||||
|
{"", ""},
|
||||||
|
{"foo bar", "foo bar"},
|
||||||
|
{"foo bar\rbaz", "foo bar"},
|
||||||
|
{"foo bar\nbaz", "foo bar"},
|
||||||
|
{"blorp\r\n\r\nbloop", "blorp"},
|
||||||
|
{"\n\rblaap", ""},
|
||||||
|
{"\r\n", ""},
|
||||||
|
{"boo\\r\\n\\n\r", "boo\\r\\n\\n"},
|
||||||
|
}
|
||||||
|
for i, test := range tests {
|
||||||
|
out := cutNewLines(test.in)
|
||||||
|
if test.out != out {
|
||||||
|
t.Errorf("test %d: expected '%s', got '%s'", i, test.out, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestClientCommands(t *testing.T) {
|
func TestClientCommands(t *testing.T) {
|
||||||
c, s := setUp(t)
|
c, s := setUp(t)
|
||||||
defer s.tearDown()
|
defer s.tearDown()
|
||||||
|
|
Loading…
Reference in New Issue