Added iterator unit test and fixed a bug where parsing messages without suffixes caused them to incorrectly include a new line in their last argument.
This commit is contained in:
parent
a8c6ba6a82
commit
14f8f09374
2 changed files with 32 additions and 0 deletions
|
@ -78,6 +78,7 @@ impl FromStr for Message {
|
|||
}
|
||||
_ => return None
|
||||
};
|
||||
if suffix.is_none() { state = state[..state.len() - 2] }
|
||||
let args: Vec<_> = state.splitn(14, ' ').filter(|s| s.len() != 0).collect();
|
||||
Some(Message::new(prefix, command, if args.len() > 0 { Some(args) } else { None }, suffix))
|
||||
}
|
||||
|
|
|
@ -118,3 +118,34 @@ impl<'a, T, U> Iterator<Message> for ServerIterator<'a, T, U> where T: IrcWriter
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::{IrcServer, Server};
|
||||
use std::collections::HashMap;
|
||||
use std::io::MemReader;
|
||||
use std::io::util::NullWriter;
|
||||
use conn::Connection;
|
||||
use data::Config;
|
||||
|
||||
#[test]
|
||||
fn iterator() {
|
||||
let exp = "PRIVMSG test :Hi!\r\nPRIVMSG test :This is a test!\r\n:test!test@test JOIN #test\r\n";
|
||||
let server = IrcServer::from_connection(Config {
|
||||
owners: vec![format!("test")],
|
||||
nickname: format!("test"),
|
||||
username: format!("test"),
|
||||
realname: format!("test"),
|
||||
password: String::new(),
|
||||
server: format!("irc.test.net"),
|
||||
port: 6667,
|
||||
channels: vec![format!("#test"), format!("#test2")],
|
||||
options: HashMap::new(),
|
||||
}, Connection::new(NullWriter, MemReader::new(exp.as_bytes().to_vec()))).unwrap();
|
||||
let mut messages = String::new();
|
||||
for message in server.iter() {
|
||||
messages.push_str(message.into_string()[]);
|
||||
}
|
||||
assert_eq!(messages[], exp);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue