Passing test

This commit is contained in:
2025-04-12 12:51:53 -04:00
parent f424e8962c
commit 8555ca4ed2

View File

@@ -9,35 +9,6 @@ mod meta_type {
} }
} }
mod meta {
use super::*;
use taglib;
pub fn get_meta(t: meta_type::Type, filepath: &String) -> Result<String, taglib::FileError> {
match t {
meta_type::Type::Title => match get_file(filepath) {
Ok(file) => match get_tag(&file) {
Ok(tag) => match tag.title() {
Some(title) => Ok(title),
None => Err(taglib::FileError::NoAvailableTag),
},
Err(err) => Err(err),
},
Err(err) => Err(err),
},
_ => Err(taglib::FileError::InvalidFile),
}
}
fn get_file(filepath: &String) -> Result<taglib::File, taglib::FileError> {
taglib::File::new(filepath)
}
fn get_tag(tag: &taglib::File) -> Result<taglib::Tag, taglib::FileError> {
tag.tag()
}
}
mod meta_nouveaou { mod meta_nouveaou {
use super::*; use super::*;
@@ -47,15 +18,16 @@ mod meta_nouveaou {
match t { match t {
meta_type::Type::Title => match new_meta(&filepath) { meta_type::Type::Title => match new_meta(&filepath) {
Ok(metaa) => { Ok(metaa) => {
let mut result = String::new();
for item in metaa.tags { for item in metaa.tags {
result += &String::from(" "); if item.0 == "TITLE" {
result += &item.0; return Ok(item.1);
result += &item.1; }
} }
Ok(result) Err(std::io::Error::new(
std::io::ErrorKind::InvalidData,
"Tag not found",
))
} }
Err(err) => Err(err), Err(err) => Err(err),
}, },
@@ -85,7 +57,7 @@ mod tests {
#[test] #[test]
fn test_get_title() { fn test_get_title() {
let filename = String::from("track01.flac"); let filename = String::from("track01.flac");
let dir = String::from("tests"); let dir = String::from("tests/sample_tracks3");
let dir_path = std::path::Path::new(&dir); let dir_path = std::path::Path::new(&dir);
let full_path = dir_path.join(filename); let full_path = dir_path.join(filename);
@@ -95,9 +67,9 @@ mod tests {
let filepath = full_path.display().to_string(); let filepath = full_path.display().to_string();
match meta_nouveaou::get_meta(meta_type::Type::Title, &filepath) { match meta_nouveaou::get_meta(meta_type::Type::Title, &filepath) {
Ok(_title) => { Ok(title) => {
let found = _title.contains("Just"); let found = title == "Just roll it";
assert!(found, "Meta information was not found"); assert!(found, "Meta information was not found {:?}", title);
} }
Err(err) => { Err(err) => {
assert!(false, "Error: {:?}", err); assert!(false, "Error: {:?}", err);