2011-08-21 12:38:51 +00:00
|
|
|
package client
|
|
|
|
|
2013-03-17 01:21:09 +00:00
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
2011-08-21 12:38:51 +00:00
|
|
|
|
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 {
|
2013-03-17 01:21:09 +00:00
|
|
|
t.Errorf("test %d: expected %q, got %q", i, test.out, out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIndexFragment(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
in string
|
|
|
|
out int
|
|
|
|
}{
|
|
|
|
{"", -1},
|
|
|
|
{"foobarbaz", -1},
|
|
|
|
{"foo bar baz", 8},
|
|
|
|
{"foo. bar baz", 5},
|
|
|
|
{"foo: bar baz", 5},
|
|
|
|
{"foo; bar baz", 5},
|
|
|
|
{"foo, bar baz", 5},
|
|
|
|
{"foo! bar baz", 5},
|
|
|
|
{"foo? bar baz", 5},
|
|
|
|
{"foo\" bar baz", 5},
|
|
|
|
{"foo' bar baz", 5},
|
|
|
|
{"foo. bar. baz beep", 10},
|
|
|
|
{"foo. bar, baz beep", 10},
|
|
|
|
}
|
|
|
|
for i, test := range tests {
|
|
|
|
out := indexFragment(test.in)
|
|
|
|
if test.out != out {
|
|
|
|
t.Errorf("test %d: expected %d, got %d", i, test.out, out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSplitMessage(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
in string
|
|
|
|
sp int
|
|
|
|
out []string
|
|
|
|
}{
|
|
|
|
{"", 0, []string{""}},
|
|
|
|
{"foo", 0, []string{"foo"}},
|
|
|
|
{"foo bar baz beep", 0, []string{"foo bar ...", "baz beep"}},
|
2015-04-14 10:18:11 +00:00
|
|
|
{"foo bar baz beep", 15, []string{"foo bar baz ...", "beep"}},
|
|
|
|
{"foo. bar baz, beep.", 0, []string{"foo. ...", "bar baz, ...", "beep."}},
|
|
|
|
{"foo bar, baz beep", 15, []string{"foo bar, ...", "baz beep"}},
|
2013-03-17 01:21:09 +00:00
|
|
|
{"0123456789012345", 0, []string{"0123456789...", "012345"}},
|
2015-04-14 10:18:11 +00:00
|
|
|
{"0123456789012345", 15, []string{"012345678901...", "2345"}},
|
|
|
|
{"0123456789012345", 16, []string{"0123456789012345"}},
|
2013-03-17 01:21:09 +00:00
|
|
|
}
|
|
|
|
for i, test := range tests {
|
|
|
|
out := splitMessage(test.in, test.sp)
|
|
|
|
if !reflect.DeepEqual(test.out, out) {
|
|
|
|
t.Errorf("test %d: expected %q, got %q", i, test.out, out)
|
2013-03-10 12:17:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2013-03-17 01:21:09 +00:00
|
|
|
// Avoid having to type ridiculously long lines to test that
|
|
|
|
// messages longer than SplitLen are correctly sent to the server.
|
2015-04-14 10:18:11 +00:00
|
|
|
c.cfg.SplitLen = 23
|
2013-03-17 01:21:09 +00:00
|
|
|
|
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")
|
2014-12-23 18:21:53 +00:00
|
|
|
c.Join("#foo bar")
|
|
|
|
s.nc.Expect("JOIN #foo bar")
|
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
|
|
|
|
2013-03-17 01:21:09 +00:00
|
|
|
// 0123456789012345678901234567890123
|
|
|
|
c.Privmsg("#foo", "foo bar baz blorp. woo woobly woo.")
|
|
|
|
s.nc.Expect("PRIVMSG #foo :foo bar baz blorp. ...")
|
|
|
|
s.nc.Expect("PRIVMSG #foo :woo woobly woo.")
|
|
|
|
|
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
|
|
|
|
2013-03-17 01:21:09 +00:00
|
|
|
// 01234567890123456789012345678901234567
|
|
|
|
c.Notice("somebody", "something much much longer that splits")
|
|
|
|
s.nc.Expect("NOTICE somebody :something much much ...")
|
|
|
|
s.nc.Expect("NOTICE somebody :longer that splits")
|
|
|
|
|
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
|
|
|
|
2013-03-17 01:21:09 +00:00
|
|
|
c.Ctcp("somebody", "ping", "123456789012345678901234567890")
|
|
|
|
s.nc.Expect("PRIVMSG somebody :\001PING 12345678901234567890...\001")
|
|
|
|
s.nc.Expect("PRIVMSG somebody :\001PING 1234567890\001")
|
|
|
|
|
|
|
|
c.CtcpReply("somebody", "pong", "123456789012345678901234567890")
|
|
|
|
s.nc.Expect("NOTICE somebody :\001PONG 12345678901234567890...\001")
|
|
|
|
s.nc.Expect("NOTICE somebody :\001PONG 1234567890\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")
|
2013-03-15 17:40:28 +00:00
|
|
|
|
|
|
|
c.VHost("user", "pass")
|
|
|
|
s.nc.Expect("VHOST user pass")
|
2011-08-21 12:38:51 +00:00
|
|
|
}
|