Fix comments and my poor code-reading skills. Damn you StalkR :-)

This commit is contained in:
Alex Bramley 2013-03-10 12:17:16 +00:00
parent 2c5b477233
commit d6cb0bb026
2 changed files with 22 additions and 9 deletions

View File

@ -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]
} }

View File

@ -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()