Added some basic data tests.

This commit is contained in:
Aaron Weiss 2014-10-08 18:08:29 -04:00
parent afa1fccff7
commit 7efe3f3fdf
3 changed files with 34 additions and 3 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
/target
/Cargo.lock
*.json

View file

@ -7,6 +7,8 @@ impl<T> IrcWriter for T where T: Writer + Sized + 'static {}
pub trait IrcReader: Reader + Sized + Clone + 'static {}
impl<T> 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"));
}
}

View file

@ -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"])
}