diff --git a/src/lib.rs b/src/lib.rs index 34ee6e6..c27f28d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,75 @@ pub mod meta; pub mod properties; pub mod types; + +pub mod test_util { + pub mod util { + + use std::io::{self, Write}; + + // Function to save a Vec to a file + pub fn save_bytes_to_file(bytes: &[u8], file_path: &String) -> io::Result<()> { + let file = std::path::Path::new(file_path); + let mut file = std::fs::File::create(file)?; + + match file.write_all(bytes) { + Ok(_res) => Ok(()), + Err(err) => Err(err), + } + } + pub fn get_full_path( + directory: &String, + filename: &String, + ) -> Result { + match path_buf(directory, filename) { + Ok(pf) => Ok(pf.display().to_string()), + Err(err) => Err(err), + } + } + + pub fn copy_file( + source_path: &String, + destination_path: &String, + ) -> Result { + let src_path = std::path::Path::new(source_path); + let dest_path = std::path::Path::new(destination_path); + + match std::fs::copy(src_path, dest_path) { + Ok(bytes) => Ok(bytes), + Err(err) => Err(err), + } + } + + pub fn file_exists(directory: &String, filename: &String) -> Result { + match path_buf(directory, filename) { + Ok(pf) => Ok(pf.exists()), + Err(err) => Err(err), + } + } + + fn path_buf( + directory: &String, + filename: &String, + ) -> Result { + let dir_path = std::path::Path::new(&directory); + Ok(dir_path.join(filename)) + } + + pub const TESTFILEDIRECTORY: &str = "tests/sample_tracks3"; + + pub fn get_filename(track: i32) -> String { + let mut filename = String::from("track"); + + if track < 10 { + filename += "0"; + filename += &track.to_string(); + } else { + filename += &track.to_string(); + } + + filename += ".flac"; + + filename + } + } +} diff --git a/src/meta.rs b/src/meta.rs index 3deb1a3..85e00c2 100644 --- a/src/meta.rs +++ b/src/meta.rs @@ -275,84 +275,15 @@ pub mod metadata { #[cfg(test)] mod tests { - use util::{file_exists, get_full_path}; use super::*; - mod util { - - use std::io::{self, Write}; - - // Function to save a Vec to a file - pub fn save_bytes_to_file(bytes: &[u8], file_path: &String) -> io::Result<()> { - let file = std::path::Path::new(file_path); - let mut file = std::fs::File::create(file)?; - - match file.write_all(bytes) { - Ok(_res) => Ok(()), - Err(err) => Err(err), - } - } - pub fn get_full_path( - directory: &String, - filename: &String, - ) -> Result { - match path_buf(directory, filename) { - Ok(pf) => Ok(pf.display().to_string()), - Err(err) => Err(err), - } - } - - pub fn copy_file( - source_path: &String, - destination_path: &String, - ) -> Result { - let src_path = std::path::Path::new(source_path); - let dest_path = std::path::Path::new(destination_path); - - match std::fs::copy(src_path, dest_path) { - Ok(bytes) => Ok(bytes), - Err(err) => Err(err), - } - } - - pub fn file_exists(directory: &String, filename: &String) -> Result { - match path_buf(directory, filename) { - Ok(pf) => Ok(pf.exists()), - Err(err) => Err(err), - } - } - - fn path_buf( - directory: &String, - filename: &String, - ) -> Result { - let dir_path = std::path::Path::new(&directory); - Ok(dir_path.join(filename)) - } - - pub const TESTFILEDIRECTORY: &str = "tests/sample_tracks3"; - - pub fn get_filename(track: i32) -> String { - let mut filename = String::from("track"); - - if track < 10 { - filename += "0"; - filename += &track.to_string(); - } else { - filename += &track.to_string(); - } - - filename += ".flac"; - - filename - } - } mod get { use super::metadata::get_meta; - use super::*; use crate::types; + use crate::test_util::util; + use crate::test_util::util::{file_exists, get_full_path}; #[test] fn test_get_title() { @@ -606,8 +537,9 @@ mod tests { mod set { use super::metadata::{get_meta, set_meta}; - use super::*; use crate::types; + use crate::test_util::util; + use crate::test_util::util::{file_exists, get_full_path}; #[test] fn test_set_title() { @@ -1143,6 +1075,8 @@ mod tests { mod pictures { use super::*; + use crate::test_util::util; + use crate::test_util::util::{file_exists, get_full_path}; #[test] fn test_get_picture() { diff --git a/src/properties.rs b/src/properties.rs index 90ed30b..b2531ac 100644 --- a/src/properties.rs +++ b/src/properties.rs @@ -21,3 +21,7 @@ pub fn get_duration(song_path: &String) -> Result