diff --git a/src/data/response.rs b/src/data/response.rs index dbafe64..1f1d0e9 100644 --- a/src/data/response.rs +++ b/src/data/response.rs @@ -315,3 +315,24 @@ impl FromStr for Response { } } } + +#[cfg(test)] +mod test { + use super::Response; + + #[test] + fn from_message() { + assert_eq!(Response::from_message( + &from_str(":irc.test.net 353 test = #test :test\r\n").unwrap() + ).unwrap(), Response::RPL_NAMREPLY); + assert_eq!(Response::from_message( + &from_str(":irc.test.net 433 :Nickname is already in use\r\n").unwrap() + ).unwrap(), Response::ERR_NICKNAMEINUSE); + } + + #[test] + fn is_error() { + assert!(!Response::RPL_NAMREPLY.is_error()) + assert!(Response::ERR_NICKNAMEINUSE.is_error()) + } +} diff --git a/src/server/mod.rs b/src/server/mod.rs index 5d83375..9e1d3cb 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -4,8 +4,8 @@ use std::collections::HashMap; use std::io::{BufferedStream, IoResult}; use std::sync::Mutex; use conn::{Connection, NetStream}; -use data::command::Command::{JOIN, PONG}; -use data::{Command, Config, Message, User}; +use data::{Command, Config, Message, Response, User}; +use data::Command::{JOIN, PONG}; use data::kinds::IrcStream; pub mod utils; @@ -124,7 +124,7 @@ impl IrcServer where T: IrcStream { self.send(JOIN(chan[], None)).unwrap(); } } - else if msg.command[] == "353" { // /NAMES + else if let Some(Response::RPL_NAMREPLY) = Response::from_message(msg) { if let Some(users) = msg.suffix.clone() { if let [_, _, ref chan] = msg.args[] { for user in users.split_str(" ") {