Dependency switch #13

Merged
phoenix merged 7 commits from switch_dependency into devel 2025-04-12 19:21:59 +00:00
Showing only changes of commit 8f2f88669d - Show all commits

View File

@@ -61,19 +61,51 @@ pub mod meta_next {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use util::{file_exists, get_full_path};
use super::*; use super::*;
mod util {
pub fn get_full_path(
directory: &String,
filename: &String,
) -> Result<String, std::io::Error> {
match path_buf(directory, filename) {
Ok(pf) => Ok(pf.display().to_string()),
Err(err) => Err(err),
}
}
pub fn file_exists(directory: &String, filename: &String) -> Result<bool, std::io::Error> {
match path_buf(directory, filename) {
Ok(pf) => Ok(pf.exists()),
Err(err) => Err(err),
}
}
fn path_buf(
directory: &String,
filename: &String,
) -> Result<std::path::PathBuf, std::io::Error> {
let dir_path = std::path::Path::new(&directory);
Ok(dir_path.join(filename))
}
}
#[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/sample_tracks3"); 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);
println!("Path: {:?}", full_path); // println!("Path: {:?}", full_path);
assert!(full_path.exists(), "Path does not exists {:?}", full_path); // assert!(full_path.exists(), "Path does not exists {:?}", full_path);
let filepath = full_path.display().to_string(); match file_exists(&dir, &filename) {
Ok(_) => {
// let filepath = full_path.display().to_string();
let filepath = get_full_path(&dir, &filename).unwrap();
match meta_next::get_meta(meta_type::Type::Title, &filepath) { match meta_next::get_meta(meta_type::Type::Title, &filepath) {
Ok(title) => { Ok(title) => {
@@ -85,4 +117,9 @@ mod tests {
} }
} }
} }
Err(err) => {
assert!(false, "Error: File does not exist {:?}", err.to_string());
}
};
}
} }