diff --git a/src/main.rs b/src/main.rs
index 84f4fe4..3982d73 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -13,7 +13,7 @@ use rules::*;
use utils::status_icon::*;
const VIDEO_EXTENSIONS: [&str; 14] = ["mkv", "mp4", "avi", "webm", "mov", "wmv", "flv", "ogg", "ogv", "yuv", "amv", "mpg", "mpeg", "m4v"];
-const SERIES_REGEX: &str = r"^(?P
.+)(?P-\s)?(?P[Ss]|\s|\.)(?P\d{1,3})(?P[Ee]|[Xx])(?P\d{1,3})([Ee](?P\d{2,3}))?((?P\s-\s)?(?P.+))?\.(?P...)$";
+pub(crate) const SERIES_REGEX: &str = r"^(?P.+)(?P-\s)?(?P[Ss]|\s|\.)(?P\d{1,3})(?P[Ee]|[Xx])(?P\d{1,3})([Ee](?P\d{2,3}))?((?P\s-\s)?(?P.+))?\.(?P...)$";
// const FILE_EXT_REGEX: &str = r"^(?P.+)\.(?P...)$";
// const MOVIE_REGEX: &str = r"^(?P.+)\s(?P\(\d{4}\))\s(?P\[.+\])\.(?P...)$";
diff --git a/src/rules/episode_marker.rs b/src/rules/episode_marker.rs
index 05665a8..3a1c121 100644
--- a/src/rules/episode_marker.rs
+++ b/src/rules/episode_marker.rs
@@ -50,3 +50,23 @@ impl Rule for EpisodeMarker {
return Ok(FixStatus::NotImplemented)
}
}
+
+#[cfg(test)]
+mod tests {
+ use crate::rules::{NonCompliantReason, Rule};
+ use crate::SERIES_REGEX;
+
+ #[test]
+ fn has_dash() {
+ let title = "Test S00E00 - FooBar.mkv";
+ let captures = regex::Regex::new(SERIES_REGEX).unwrap().captures(title).unwrap();
+ assert_eq!(super::EpisodeMarker::check(title, &captures), None);
+ }
+
+ #[test]
+ fn no_dash() {
+ let title = "Test S00x00.mkv";
+ let captures = regex::Regex::new(SERIES_REGEX).unwrap().captures(title).unwrap();
+ assert_eq!(super::EpisodeMarker::check(title, &captures), Some(NonCompliantReason::InvalidEpisodeMarker("Episode Prefix must be 'E'".to_string())));
+ }
+}
\ No newline at end of file
diff --git a/src/rules/has_dash_in_title.rs b/src/rules/has_dash_in_title.rs
index e17a88c..2db0fa8 100644
--- a/src/rules/has_dash_in_title.rs
+++ b/src/rules/has_dash_in_title.rs
@@ -35,4 +35,24 @@ impl Rule for DashInTitle {
return Ok(FixStatus::Fixed(name))
}
+}
+
+#[cfg(test)]
+mod tests {
+ use crate::rules::{NonCompliantReason, Rule};
+ use crate::SERIES_REGEX;
+
+ #[test]
+ fn has_dash() {
+ let title = "Test S00E00 - FooBar.mkv";
+ let captures = regex::Regex::new(SERIES_REGEX).unwrap().captures(title).unwrap();
+ assert_eq!(super::DashInTitle::check(title, &captures), None);
+ }
+
+ #[test]
+ fn no_dash() {
+ let title = "Test - S00E00.mkv";
+ let captures = regex::Regex::new(SERIES_REGEX).unwrap().captures(title).unwrap();
+ assert_eq!(super::DashInTitle::check(title, &captures), Some(NonCompliantReason::DashInTitle));
+ }
}
\ No newline at end of file
diff --git a/src/rules/has_episode_name.rs b/src/rules/has_episode_name.rs
index 6558c31..fd48314 100644
--- a/src/rules/has_episode_name.rs
+++ b/src/rules/has_episode_name.rs
@@ -16,3 +16,23 @@ impl Rule for HasEpisodeName {
return Ok(FixStatus::NotImplemented)
}
}
+
+#[cfg(test)]
+mod tests {
+ use crate::rules::{NonCompliantReason, Rule};
+ use crate::SERIES_REGEX;
+
+ #[test]
+ fn has_name() {
+ let title = "Test S00E00 - FooBar.mkv";
+ let captures = regex::Regex::new(SERIES_REGEX).unwrap().captures(title).unwrap();
+ assert_eq!(super::HasEpisodeName::check(title, &captures), None);
+ }
+
+ #[test]
+ fn no_name() {
+ let title = "Test S00E00.mkv";
+ let captures = regex::Regex::new(SERIES_REGEX).unwrap().captures(title).unwrap();
+ assert_eq!(super::HasEpisodeName::check(title, &captures), Some(NonCompliantReason::MissingName));
+ }
+}
\ No newline at end of file
diff --git a/src/rules/has_fluff.rs b/src/rules/has_fluff.rs
index ed759b8..85f1a0d 100644
--- a/src/rules/has_fluff.rs
+++ b/src/rules/has_fluff.rs
@@ -22,3 +22,20 @@ impl Rule for HasFluff {
}
}
+#[cfg(test)]
+mod tests {
+ use crate::rules::{NonCompliantReason, Rule};
+
+ #[test]
+ fn no_fluff() {
+ let captures = regex::Regex::new("").unwrap().captures("").unwrap();
+ assert_eq!(super::HasFluff::check("Test S00E00 - FooBar.mkv", &captures), None);
+ }
+
+ #[test]
+ fn encoding_info() {
+ let captures = regex::Regex::new("").unwrap().captures("").unwrap();
+ let title = "blah (1920x1080 h264 BD FLAC).mkv";
+ assert_eq!(super::HasFluff::check(title, &captures), Some(NonCompliantReason::HasFluff));
+ }
+}
\ No newline at end of file
diff --git a/src/rules/missing_name_separator.rs b/src/rules/missing_name_separator.rs
index 1b8ae3b..ee38002 100644
--- a/src/rules/missing_name_separator.rs
+++ b/src/rules/missing_name_separator.rs
@@ -16,3 +16,23 @@ impl Rule for MissingNameSeparator {
return Ok(FixStatus::NotImplemented)
}
}
+
+#[cfg(test)]
+mod tests {
+ use crate::rules::{NonCompliantReason, Rule};
+ use crate::SERIES_REGEX;
+
+ #[test]
+ fn has_separator() {
+ let title = "Test S00E00 - FooBar.mkv";
+ let captures = regex::Regex::new(SERIES_REGEX).unwrap().captures(title).unwrap();
+ assert_eq!(super::MissingNameSeparator::check(title, &captures), None);
+ }
+
+ #[test]
+ fn no_separator() {
+ let title = "Test S00E00 FooBar.mkv";
+ let captures = regex::Regex::new(SERIES_REGEX).unwrap().captures(title).unwrap();
+ assert_eq!(super::MissingNameSeparator::check(title, &captures), Some(NonCompliantReason::MissingNameSeparator));
+ }
+}
\ No newline at end of file
diff --git a/src/rules/mod.rs b/src/rules/mod.rs
index 26ea094..f4ebdce 100644
--- a/src/rules/mod.rs
+++ b/src/rules/mod.rs
@@ -14,6 +14,7 @@ pub use has_episode_name::HasEpisodeName;
pub use has_dash_in_title::DashInTitle;
pub use missing_name_separator::MissingNameSeparator;
+#[derive(Debug, PartialEq)]
pub enum NonCompliantReason {
DashInTitle,
MissingName,
diff --git a/src/utils/constructors.rs b/src/utils/constructors.rs
index d149942..02eb4ca 100644
--- a/src/utils/constructors.rs
+++ b/src/utils/constructors.rs
@@ -4,3 +4,32 @@ pub fn episode_name(title: String, season: String, episode: String, name: Option
None => format!("{} S{}E{}.{}", title, season, episode, format),
}
}
+
+#[cfg(test)]
+mod tests {
+ #[test]
+ fn formats_with_name() {
+ let expected_name = "Test S00E00 - FooBar.mkv".to_string();
+ let result = super::episode_name(
+ "Test".to_string(),
+ "00".to_string(),
+ "00".to_string(),
+ Some("FooBar".to_string()),
+ "mkv".to_string()
+ );
+ assert_eq!(expected_name, result);
+ }
+
+ #[test]
+ fn formats_without_name() {
+ let expected_name = "Test S00E00.mkv".to_string();
+ let result = super::episode_name(
+ "Test".to_string(),
+ "00".to_string(),
+ "00".to_string(),
+ None,
+ "mkv".to_string()
+ );
+ assert_eq!(expected_name, result);
+ }
+}