Added send_kill(...) and associated unit test.

This commit is contained in:
Aaron Weiss 2014-10-29 00:52:52 -04:00
parent aad1d52b59
commit 56ca5379e1
2 changed files with 13 additions and 0 deletions

View file

@ -62,6 +62,10 @@ impl<'a, T, U> Bot for IrcBot<'a, T, U> where T: IrcWriter, U: IrcReader {
self.conn.send(Message::new(None, "KICK", [chan, user, msg]))
}
fn send_kill(&self, nick: &str, msg: &str) -> IoResult<()> {
self.conn.send(Message::new(None, "KILL", [nick, msg]))
}
fn send_privmsg(&self, chan: &str, msg: &str) -> IoResult<()> {
for line in msg.split_str("\r\n") {
try!(self.conn.send(Message::new(None, "PRIVMSG", [chan, line])));
@ -251,6 +255,14 @@ mod test {
assert_eq!(data(b.conn), format!("KICK #test test2 :Goodbye.\r\n"));
}
#[test]
fn send_kill() {
let c = Connection::new(MemWriter::new(), NullReader).unwrap();
let b = IrcBot::from_connection(c, |_, _, _, _| { Ok(()) }).unwrap();
b.send_kill("test", "Goodbye.").unwrap();
assert_eq!(data(b.conn), format!("KILL test :Goodbye.\r\n"));
}
#[test]
fn send_privmsg() {
let c = Connection::new(MemWriter::new(), NullReader).unwrap();

View file

@ -23,6 +23,7 @@ pub trait Bot {
fn send_invite(&self, person: &str, chan: &str) -> IoResult<()>;
fn send_privmsg(&self, chan: &str, msg: &str) -> IoResult<()>;
fn send_kick(&self, chan: &str, user: &str, msg: &str) -> IoResult<()>;
fn send_kill(&self, nick: &str, msg: &str) -> IoResult<()>;
fn identify(&self) -> IoResult<()>;
fn output(&mut self) -> IoResult<()>;
fn config(&self) -> &Config;