Code formatting

This commit is contained in:
2025-03-22 16:01:40 -04:00
parent c1039859ea
commit 0b40ed903d

View File

@@ -1,29 +1,29 @@
mod song_tests { mod song_tests {
// use std::fs::{self, File}; // use std::fs::{self, File};
use std::fs; use std::fs;
use std::fs::File; use std::fs::File;
use std::io::{Read, Write}; use std::io::{Read, Write};
use std::path::Path; use std::path::Path;
use tempfile::tempdir; use tempfile::tempdir;
use icarus_models::song; use icarus_models::song;
use icarus_models::types; use icarus_models::types;
fn get_tests_directory() -> String { fn get_tests_directory() -> String {
String::from(env!("CARGO_MANIFEST_DIR").to_owned() + "/tests/") String::from(env!("CARGO_MANIFEST_DIR").to_owned() + "/tests/")
} }
fn does_directory_exists(directory: &String) -> bool { fn does_directory_exists(directory: &String) -> bool {
let path = Path::new(directory); let path = Path::new(directory);
if let Ok(dir_i) = fs::metadata(path) { if let Ok(dir_i) = fs::metadata(path) {
dir_i.is_dir() dir_i.is_dir()
} else { } else {
false false
} }
} }
fn extract_data_from_file(filepath: &String) -> Result<Vec<u8>, std::io::Error> { fn extract_data_from_file(filepath: &String) -> Result<Vec<u8>, std::io::Error> {
match std::fs::File::open(filepath) { match std::fs::File::open(filepath) {
Ok(mut file) => { Ok(mut file) => {
let mut buffer: Vec<u8> = Vec::new(); let mut buffer: Vec<u8> = Vec::new();
@@ -37,10 +37,10 @@ fn extract_data_from_file(filepath: &String) -> Result<Vec<u8>, std::io::Error>
Err(err) Err(err)
} }
} }
} }
#[test] #[test]
fn test_song_to_data() { fn test_song_to_data() {
println!("Test"); println!("Test");
let some_val = true; let some_val = true;
@@ -103,10 +103,10 @@ fn test_song_to_data() {
assert!(false, "Could not get song path: {:?}", err); assert!(false, "Could not get song path: {:?}", err);
} }
} }
} }
#[test] #[test]
fn test_song_path_check() { fn test_song_path_check() {
let mut song = song::Song::default(); let mut song = song::Song::default();
song.directory = get_tests_directory(); song.directory = get_tests_directory();
song.filename = String::from("track01.flac"); song.filename = String::from("track01.flac");
@@ -115,10 +115,10 @@ fn test_song_path_check() {
does_directory_exists(&song.directory), does_directory_exists(&song.directory),
"Directory does not exist" "Directory does not exist"
); );
} }
#[test] #[test]
fn test_song_generate_filename() { fn test_song_generate_filename() {
let mut song = song::Song::default(); let mut song = song::Song::default();
song.directory = get_tests_directory(); song.directory = get_tests_directory();
song.filename = String::from("track01.flac"); song.filename = String::from("track01.flac");
@@ -135,7 +135,8 @@ fn test_song_generate_filename() {
assert_eq!(song.directory.is_empty(), false); assert_eq!(song.directory.is_empty(), false);
// song_cpy.directory = String::from(temp_dir.path().to_str()); // song_cpy.directory = String::from(temp_dir.path().to_str());
song_cpy.filename = song.generate_filename(types::MusicTypes::FlacExtension, true); song_cpy.filename =
song.generate_filename(types::MusicTypes::FlacExtension, true);
println!("Directory: {:?}", song_cpy.directory); println!("Directory: {:?}", song_cpy.directory);
println!("File to be created: {:?}", song_cpy.filename); println!("File to be created: {:?}", song_cpy.filename);
@@ -164,5 +165,5 @@ fn test_song_generate_filename() {
assert!(false, "Error extracting song data: {:?}", err); assert!(false, "Error extracting song data: {:?}", err);
} }
} }
} }
} }