From 6fcf3e2fc6cc3e8028504e1536ab864851685f1e Mon Sep 17 00:00:00 2001 From: Aaron Weiss Date: Wed, 8 Oct 2014 22:17:39 -0400 Subject: [PATCH] Implemented unit tests for the remainder of the send_* methods. --- src/bot.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/bot.rs b/src/bot.rs index 550eb52..6bfa384 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -186,4 +186,49 @@ mod test { b.send_user("test", "Test").unwrap(); assert_eq!(b.conn.writer().deref_mut().get_ref(), "USER test 0 * :Test\r\n".as_bytes()); } + + #[test] + fn send_join() { + let w = MemWriter::new(); + let c = Connection::new(w, NullReader).unwrap(); + let b = IrcBot::from_connection(c, |_, _, _, _| { Ok(()) }).unwrap(); + b.send_join("#test").unwrap(); + assert_eq!(b.conn.writer().deref_mut().get_ref(), "JOIN :#test\r\n".as_bytes()); + } + + #[test] + fn send_mode() { + let w = MemWriter::new(); + let c = Connection::new(w, NullReader).unwrap(); + let b = IrcBot::from_connection(c, |_, _, _, _| { Ok(()) }).unwrap(); + b.send_mode("#test", "+i").unwrap(); + assert_eq!(b.conn.writer().deref_mut().get_ref(), "MODE #test :+i\r\n".as_bytes()); + } + + #[test] + fn send_topic() { + let w = MemWriter::new(); + let c = Connection::new(w, NullReader).unwrap(); + let b = IrcBot::from_connection(c, |_, _, _, _| { Ok(()) }).unwrap(); + b.send_topic("#test", "This is a test topic.").unwrap(); + assert_eq!(b.conn.writer().deref_mut().get_ref(), "TOPIC #test :This is a test topic.\r\n".as_bytes()); + } + + #[test] + fn send_invite() { + let w = MemWriter::new(); + let c = Connection::new(w, NullReader).unwrap(); + let b = IrcBot::from_connection(c, |_, _, _, _| { Ok(()) }).unwrap(); + b.send_invite("test2", "#test").unwrap(); + assert_eq!(b.conn.writer().deref_mut().get_ref(), "INVITE test2 :#test\r\n".as_bytes()); + } + + #[test] + fn send_privmsg() { + let w = MemWriter::new(); + let c = Connection::new(w, NullReader).unwrap(); + let b = IrcBot::from_connection(c, |_, _, _, _| { Ok(()) }).unwrap(); + b.send_privmsg("#test", "This is a test message.").unwrap(); + assert_eq!(b.conn.writer().deref_mut().get_ref(), "PRIVMSG #test :This is a test message.\r\n".as_bytes()); + } }