aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main.rs20
-rw-r--r--src/tests.rs21
2 files changed, 32 insertions, 9 deletions
diff --git a/src/main.rs b/src/main.rs
index aebabef..4c0cf26 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -97,6 +97,26 @@ impl From<io::Error> for AliasSearchError {
}
}
+#[cfg(test)]
+impl PartialEq<AliasSearchError> for AliasSearchError {
+ fn eq(&self, other: &AliasSearchError) -> bool {
+ match *self {
+ AliasSearchError::NotFound => match *other {
+ AliasSearchError::NotFound => true,
+ _ => false,
+ },
+ AliasSearchError::EmailExists => match *other {
+ AliasSearchError::EmailExists => true,
+ _ => false,
+ },
+ AliasSearchError::Io(_) => match *other {
+ AliasSearchError::Io(_) => true,
+ _ => false,
+ },
+ }
+ }
+}
+
fn find_alias_in_file(alias: &Alias, file: &str) -> Result<Vec<String>, AliasSearchError> {
let mut matches = Vec::new();
let f = try!(File::open(file));
diff --git a/src/tests.rs b/src/tests.rs
index ccacd29..a6f2777 100644
--- a/src/tests.rs
+++ b/src/tests.rs
@@ -1,4 +1,4 @@
-use super::{Alias, find_alias_in_file};
+use super::{Alias, AliasSearchError, find_alias_in_file};
#[test]
fn new_alias_with_only_email() {
@@ -42,13 +42,16 @@ fn new_alias_with_special_characters() {
#[test]
-fn find_alias_in_file_finds_a_match() {
- find_alias_in_file(
- &Alias {
- alias: "farnsworth-hubert".to_owned(),
- name: "Hubert Farnsworth".to_owned(),
- email: "<professor@planetexpress.com>".to_owned()
- },
- "./testdata/aliases"
+fn find_alias_in_file_email_already_exists() {
+ assert_eq!(
+ Err(AliasSearchError::EmailExists),
+ find_alias_in_file(
+ &Alias {
+ alias: "farnsworth-hubert".to_owned(),
+ name: "Hubert Farnsworth".to_owned(),
+ email: "<professor@planetexpress.com>".to_owned()
+ },
+ "./testdata/aliases"
+ )
);
}