Added unit tests for Connections and caught an inconsistency from the spec.
This commit is contained in:
parent
8049d52e93
commit
31e633763b
1 changed files with 31 additions and 1 deletions
32
src/conn.rs
32
src/conn.rs
|
@ -30,7 +30,6 @@ impl<T, U> Connection<T, U> where T: IrcWriter, U: IrcReader {
|
|||
|
||||
pub fn send(&self, msg: Message) -> IoResult<()> {
|
||||
let mut send = msg.command.to_string();
|
||||
send.push_str(" ");
|
||||
send.push_str(msg.args.init().connect(" ").as_slice());
|
||||
send.push_str(" :");
|
||||
send.push_str(*msg.args.last().unwrap());
|
||||
|
@ -42,3 +41,34 @@ impl<T, U> Connection<T, U> where T: IrcWriter, U: IrcReader {
|
|||
self.reader.borrow_mut()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::io::MemWriter;
|
||||
use std::io::util::NullReader;
|
||||
use data::Message;
|
||||
use super::Connection;
|
||||
|
||||
#[test]
|
||||
fn new_connection() {
|
||||
let w = MemWriter::new();
|
||||
assert!(Connection::new(w, NullReader).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_internal() {
|
||||
let w = MemWriter::new();
|
||||
let c = Connection::new(w, NullReader).unwrap();
|
||||
c.send_internal("string of text").unwrap();
|
||||
assert_eq!(c.writer.borrow_mut().deref_mut().get_ref(), "string of text".as_bytes());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send() {
|
||||
let w = MemWriter::new();
|
||||
let c = Connection::new(w, NullReader).unwrap();
|
||||
let args = ["flare.to.ca.fyrechat.net"];
|
||||
c.send(Message::new(None, "PING", args)).unwrap();
|
||||
assert_eq!(c.writer.borrow_mut().deref_mut().get_ref(), "PING :flare.to.ca.fyrechat.net\r\n".as_bytes());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue