From b9357ee67145aebd321d4fdb68e76d9a8b8ca8dd Mon Sep 17 00:00:00 2001 From: Aaron Weiss Date: Tue, 23 Dec 2014 13:31:10 -0500 Subject: [PATCH] Fixed CTCP tests. --- src/data/message.rs | 2 +- src/server/mod.rs | 16 ++++++++++------ src/server/utils.rs | 3 ++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/data/message.rs b/src/data/message.rs index f62191e..74de5d8 100644 --- a/src/data/message.rs +++ b/src/data/message.rs @@ -26,7 +26,7 @@ impl Message { Message { prefix: prefix.map(|s| s.to_owned()), command: command.to_owned(), - args: args.map_or(Vec::new(), |v| v.iter().map(|s| s.to_string()).collect()), + args: args.map_or(Vec::new(), |v| v.iter().map(|&s| s.to_owned()).collect()), suffix: suffix.map(|s| s.to_owned()), } } diff --git a/src/server/mod.rs b/src/server/mod.rs index 4645130..c014b66 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -186,6 +186,7 @@ impl IrcServer { None => "", }; if let ("PRIVMSG", [ref target]) = (msg.command[], msg.args[]) { + println!("it's a privmsg"); let resp = if target.starts_with("#") { target[] } else { source }; match msg.suffix { Some(ref msg) if msg.starts_with("\u{001}") => { @@ -197,14 +198,17 @@ impl IrcServer { }; msg[1..end].split_str(" ").collect() }; + println!("we made it this far."); match tokens[0] { "FINGER" => self.send_ctcp(resp, format!("FINGER :{} ({})", self.config.real_name(), self.config.username())[]), "VERSION" => self.send_ctcp(resp, "VERSION irc:git:Rust"), "SOURCE" => { + println!("sending shit!"); self.send_ctcp(resp, "SOURCE https://github.com/aatxe/irc"); self.send_ctcp(resp, "SOURCE"); + println!("sent"); }, "PING" => self.send_ctcp(resp, format!("PING {}", tokens[1])[]), "TIME" => self.send_ctcp(resp, format!("TIME :{}", now().rfc822z())[]), @@ -453,7 +457,7 @@ mod test { #[test] #[cfg(feature = "ctcp")] fn finger_response() { - let value = "test!test@test PRIVMSG test :\u{001}FINGER\u{001}\r\n"; + let value = ":test!test@test PRIVMSG test :\u{001}FINGER\u{001}\r\n"; let server = IrcServer::from_connection(test_config(), Connection::new( MemReader::new(value.as_bytes().to_vec()), MemWriter::new() )); @@ -467,7 +471,7 @@ mod test { #[test] #[cfg(feature = "ctcp")] fn version_response() { - let value = "test!test@test PRIVMSG test :\u{001}VERSION\u{001}\r\n"; + let value = ":test!test@test PRIVMSG test :\u{001}VERSION\u{001}\r\n"; let server = IrcServer::from_connection(test_config(), Connection::new( MemReader::new(value.as_bytes().to_vec()), MemWriter::new() )); @@ -481,7 +485,7 @@ mod test { #[test] #[cfg(feature = "ctcp")] fn source_response() { - let value = "test!test@test PRIVMSG test :\u{001}SOURCE\u{001}\r\n"; + let value = ":test!test@test PRIVMSG test :\u{001}SOURCE\u{001}\r\n"; let server = IrcServer::from_connection(test_config(), Connection::new( MemReader::new(value.as_bytes().to_vec()), MemWriter::new() )); @@ -496,7 +500,7 @@ mod test { #[test] #[cfg(feature = "ctcp")] fn ctcp_ping_response() { - let value = "test!test@test PRIVMSG test :\u{001}PING test\u{001}\r\n"; + let value = ":test!test@test PRIVMSG test :\u{001}PING test\u{001}\r\n"; let server = IrcServer::from_connection(test_config(), Connection::new( MemReader::new(value.as_bytes().to_vec()), MemWriter::new() )); @@ -509,7 +513,7 @@ mod test { #[test] #[cfg(feature = "ctcp")] fn time_response() { - let value = "test!test@test PRIVMSG test :\u{001}TIME\u{001}\r\n"; + let value = ":test!test@test PRIVMSG test :\u{001}TIME\u{001}\r\n"; let server = IrcServer::from_connection(test_config(), Connection::new( MemReader::new(value.as_bytes().to_vec()), MemWriter::new() )); @@ -524,7 +528,7 @@ mod test { #[test] #[cfg(feature = "ctcp")] fn user_info_response() { - let value = "test!test@test PRIVMSG test :\u{001}USERINFO\u{001}\r\n"; + let value = ":test!test@test PRIVMSG test :\u{001}USERINFO\u{001}\r\n"; let server = IrcServer::from_connection(test_config(), Connection::new( MemReader::new(value.as_bytes().to_vec()), MemWriter::new() )); diff --git a/src/server/utils.rs b/src/server/utils.rs index 59b7cf8..e40975b 100644 --- a/src/server/utils.rs +++ b/src/server/utils.rs @@ -543,9 +543,10 @@ mod test { Connection::new(NullReader, MemWriter::new())); { let wrapper = Wrapper::new(&server); - wrapper.send_ctcp_ping("PING").unwrap(); + wrapper.send_ctcp_ping("test").unwrap(); } let val = get_server_value(server); + println!("{}", val); assert!(val.starts_with("PRIVMSG test :\u{001}PING ")); assert!(val.ends_with("\u{001}\r\n")); }