diff --git a/.gitignore b/.gitignore index 4fffb2f..d6c23ea 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target /Cargo.lock +*.json diff --git a/src/data.rs b/src/data.rs index 78d415a..6cc12f6 100644 --- a/src/data.rs +++ b/src/data.rs @@ -7,6 +7,8 @@ impl IrcWriter for T where T: Writer + Sized + 'static {} pub trait IrcReader: Reader + Sized + Clone + 'static {} impl IrcReader for T where T: Reader + Sized + Clone + 'static {} + +#[deriving(Show, PartialEq)] pub struct Message<'a> { pub source: Option<&'a str>, pub command: &'a str, @@ -50,3 +52,31 @@ impl Config { self.owners.as_slice().contains(&String::from_str(nickname)) } } + +#[cfg(test)] +mod test { + use super::{Config, Message}; + + #[test] + fn new_message() { + let args = ["flare.to.ca.fyrechat.net"]; + let m = Message::new(None, "PING", args); + assert_eq!(m, Message { + source: None, + command: "PING", + args: args, + }); + } + + #[test] + fn load_config() { + assert!(Config::load().is_ok()); + } + + #[test] + fn is_owner() { + let cfg = Config::load().unwrap(); + assert!(cfg.is_owner("test")); + assert!(!cfg.is_owner("test2")); + } +} diff --git a/src/lib.rs b/src/lib.rs index 1832086..60c045f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -52,9 +52,9 @@ fn parse_args(line: &str) -> Vec<&str> { #[cfg(test)] mod test { use super::{process, parse_args}; - + #[test] - fn process_line_test() { + fn process_line() { let res = process(":flare.to.ca.fyrechat.net 353 pickles = #pickles :pickles awe\r\n").unwrap(); let (source, command, args) = res; assert_eq!(source, "flare.to.ca.fyrechat.net"); @@ -69,7 +69,7 @@ mod test { } #[test] - fn process_args_test() { + fn process_args() { let res = parse_args("PRIVMSG #vana :hi"); assert_eq!(res, vec!["#vana", "hi"]) }