2011-08-21 12:38:51 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
2013-03-10 12:17:16 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-21 12:38:51 +00:00
|
|
|
func TestClientCommands(t *testing.T) {
|
2011-11-06 04:56:46 +00:00
|
|
|
c, s := setUp(t)
|
|
|
|
defer s.tearDown()
|
2011-08-21 12:38:51 +00:00
|
|
|
|
|
|
|
c.Pass("password")
|
2011-11-06 04:56:46 +00:00
|
|
|
s.nc.Expect("PASS password")
|
2011-08-21 12:38:51 +00:00
|
|
|
|
|
|
|
c.Nick("test")
|
2011-11-06 04:56:46 +00:00
|
|
|
s.nc.Expect("NICK test")
|
2011-08-21 12:38:51 +00:00
|
|
|
|
|
|
|
c.User("test", "Testing IRC")
|
2011-11-06 04:56:46 +00:00
|
|
|
s.nc.Expect("USER test 12 * :Testing IRC")
|
2011-08-21 12:38:51 +00:00
|
|
|
|
|
|
|
c.Raw("JUST a raw :line")
|
2011-11-06 04:56:46 +00:00
|
|
|
s.nc.Expect("JUST a raw :line")
|
2011-08-21 12:38:51 +00:00
|
|
|
|
|
|
|
c.Join("#foo")
|
2011-11-06 04:56:46 +00:00
|
|
|
s.nc.Expect("JOIN #foo")
|
2011-08-21 12:38:51 +00:00
|
|
|
|
|
|
|
c.Part("#foo")
|
2011-11-06 04:56:46 +00:00
|
|
|
s.nc.Expect("PART #foo")
|
2011-08-21 12:38:51 +00:00
|
|
|
c.Part("#foo", "Screw you guys...")
|
2011-11-06 04:56:46 +00:00
|
|
|
s.nc.Expect("PART #foo :Screw you guys...")
|
2011-08-21 12:38:51 +00:00
|
|
|
|
|
|
|
c.Quit()
|
2011-11-06 04:56:46 +00:00
|
|
|
s.nc.Expect("QUIT :GoBye!")
|
2011-08-21 12:38:51 +00:00
|
|
|
c.Quit("I'm going home.")
|
2011-11-06 04:56:46 +00:00
|
|
|
s.nc.Expect("QUIT :I'm going home.")
|
2011-08-21 12:38:51 +00:00
|
|
|
|
|
|
|
c.Whois("somebody")
|
2011-11-06 04:56:46 +00:00
|
|
|
s.nc.Expect("WHOIS somebody")
|
2011-08-21 12:38:51 +00:00
|
|
|
|
|
|
|
c.Who("*@some.host.com")
|
2011-11-06 04:56:46 +00:00
|
|
|
s.nc.Expect("WHO *@some.host.com")
|
2011-08-21 12:38:51 +00:00
|
|
|
|
|
|
|
c.Privmsg("#foo", "bar")
|
2011-11-06 04:56:46 +00:00
|
|
|
s.nc.Expect("PRIVMSG #foo :bar")
|
2011-08-21 12:38:51 +00:00
|
|
|
|
|
|
|
c.Notice("somebody", "something")
|
2011-11-06 04:56:46 +00:00
|
|
|
s.nc.Expect("NOTICE somebody :something")
|
2011-08-21 12:38:51 +00:00
|
|
|
|
|
|
|
c.Ctcp("somebody", "ping", "123456789")
|
2011-11-06 04:56:46 +00:00
|
|
|
s.nc.Expect("PRIVMSG somebody :\001PING 123456789\001")
|
2011-08-21 12:38:51 +00:00
|
|
|
|
|
|
|
c.CtcpReply("somebody", "pong", "123456789")
|
2011-11-06 04:56:46 +00:00
|
|
|
s.nc.Expect("NOTICE somebody :\001PONG 123456789\001")
|
2011-08-21 12:38:51 +00:00
|
|
|
|
|
|
|
c.Version("somebody")
|
2011-11-06 04:56:46 +00:00
|
|
|
s.nc.Expect("PRIVMSG somebody :\001VERSION\001")
|
2011-08-21 12:38:51 +00:00
|
|
|
|
|
|
|
c.Action("#foo", "pokes somebody")
|
2011-11-06 04:56:46 +00:00
|
|
|
s.nc.Expect("PRIVMSG #foo :\001ACTION pokes somebody\001")
|
2011-08-21 12:38:51 +00:00
|
|
|
|
|
|
|
c.Topic("#foo")
|
2011-11-06 04:56:46 +00:00
|
|
|
s.nc.Expect("TOPIC #foo")
|
2011-08-21 12:38:51 +00:00
|
|
|
c.Topic("#foo", "la la la")
|
2011-11-06 04:56:46 +00:00
|
|
|
s.nc.Expect("TOPIC #foo :la la la")
|
2011-08-21 12:38:51 +00:00
|
|
|
|
|
|
|
c.Mode("#foo")
|
2011-11-06 04:56:46 +00:00
|
|
|
s.nc.Expect("MODE #foo")
|
2011-08-21 12:38:51 +00:00
|
|
|
c.Mode("#foo", "+o somebody")
|
2011-11-06 04:56:46 +00:00
|
|
|
s.nc.Expect("MODE #foo +o somebody")
|
2011-08-21 12:38:51 +00:00
|
|
|
|
|
|
|
c.Away()
|
2011-11-06 04:56:46 +00:00
|
|
|
s.nc.Expect("AWAY")
|
2011-08-21 12:38:51 +00:00
|
|
|
c.Away("Dave's not here, man.")
|
2011-11-06 04:56:46 +00:00
|
|
|
s.nc.Expect("AWAY :Dave's not here, man.")
|
2011-08-21 12:38:51 +00:00
|
|
|
|
|
|
|
c.Invite("somebody", "#foo")
|
2011-11-06 04:56:46 +00:00
|
|
|
s.nc.Expect("INVITE somebody #foo")
|
2011-08-21 12:38:51 +00:00
|
|
|
|
|
|
|
c.Oper("user", "pass")
|
2011-11-06 04:56:46 +00:00
|
|
|
s.nc.Expect("OPER user pass")
|
2011-08-21 12:38:51 +00:00
|
|
|
}
|