Add basic unit tests
This commit is contained in:
parent
8d9a2329be
commit
afd3c527f2
8 changed files with 128 additions and 1 deletions
|
@ -13,7 +13,7 @@ use rules::*;
|
||||||
use utils::status_icon::*;
|
use utils::status_icon::*;
|
||||||
|
|
||||||
const VIDEO_EXTENSIONS: [&str; 14] = ["mkv", "mp4", "avi", "webm", "mov", "wmv", "flv", "ogg", "ogv", "yuv", "amv", "mpg", "mpeg", "m4v"];
|
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<title>.+)(?P<titleSeparator>-\s)?(?P<seasonPrefix>[Ss]|\s|\.)(?P<season>\d{1,3})(?P<episodePrefix>[Ee]|[Xx])(?P<episode>\d{1,3})([Ee](?P<episode2>\d{2,3}))?((?P<nameSeparator>\s-\s)?(?P<name>.+))?\.(?P<ext>...)$";
|
pub(crate) const SERIES_REGEX: &str = r"^(?P<title>.+)(?P<titleSeparator>-\s)?(?P<seasonPrefix>[Ss]|\s|\.)(?P<season>\d{1,3})(?P<episodePrefix>[Ee]|[Xx])(?P<episode>\d{1,3})([Ee](?P<episode2>\d{2,3}))?((?P<nameSeparator>\s-\s)?(?P<name>.+))?\.(?P<ext>...)$";
|
||||||
// const FILE_EXT_REGEX: &str = r"^(?P<title>.+)\.(?P<ext>...)$";
|
// const FILE_EXT_REGEX: &str = r"^(?P<title>.+)\.(?P<ext>...)$";
|
||||||
// const MOVIE_REGEX: &str = r"^(?P<title>.+)\s(?P<year>\(\d{4}\))\s(?P<resolution>\[.+\])\.(?P<ext>...)$";
|
// const MOVIE_REGEX: &str = r"^(?P<title>.+)\s(?P<year>\(\d{4}\))\s(?P<resolution>\[.+\])\.(?P<ext>...)$";
|
||||||
|
|
||||||
|
|
|
@ -50,3 +50,23 @@ impl Rule for EpisodeMarker {
|
||||||
return Ok(FixStatus::NotImplemented)
|
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())));
|
||||||
|
}
|
||||||
|
}
|
|
@ -35,4 +35,24 @@ impl Rule for DashInTitle {
|
||||||
|
|
||||||
return Ok(FixStatus::Fixed(name))
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -16,3 +16,23 @@ impl Rule for HasEpisodeName {
|
||||||
return Ok(FixStatus::NotImplemented)
|
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));
|
||||||
|
}
|
||||||
|
}
|
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,3 +16,23 @@ impl Rule for MissingNameSeparator {
|
||||||
return Ok(FixStatus::NotImplemented)
|
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));
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,6 +14,7 @@ pub use has_episode_name::HasEpisodeName;
|
||||||
pub use has_dash_in_title::DashInTitle;
|
pub use has_dash_in_title::DashInTitle;
|
||||||
pub use missing_name_separator::MissingNameSeparator;
|
pub use missing_name_separator::MissingNameSeparator;
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum NonCompliantReason {
|
pub enum NonCompliantReason {
|
||||||
DashInTitle,
|
DashInTitle,
|
||||||
MissingName,
|
MissingName,
|
||||||
|
|
|
@ -4,3 +4,32 @@ pub fn episode_name(title: String, season: String, episode: String, name: Option
|
||||||
None => format!("{} S{}E{}.{}", title, season, episode, format),
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue