handle_command(...) implementation now uses responses, unit tests for
responses are now lincuded.
This commit is contained in:
parent
7a4e1675b2
commit
4a48093905
2 changed files with 24 additions and 3 deletions
|
@ -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 <nick> :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())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<T> IrcServer<T> 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(" ") {
|
||||
|
|
Loading…
Reference in a new issue