From 61b84fc2435071d0f3758d8f55a13a23bde50bf1 Mon Sep 17 00:00:00 2001 From: Sylwester Fraczek Date: Wed, 24 Apr 2024 20:05:23 +0200 Subject: [PATCH] cargo fmt --- src/lib.rs | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 7e60b3b..74b1803 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -250,8 +250,8 @@ fn compute_sold_taxation(transactions: &Vec) -> (f32, f32) { pub fn format_sold_transactions_to_string() {} use std::collections::HashSet; -use std::path::Path; use std::ffi::OsStr; +use std::path::Path; /* Check: if file names have no duplicates @@ -262,7 +262,7 @@ pub fn validate_file_names(files: &Vec) -> Result<(), String> { let mut names_set = HashSet::new(); let mut spreadsheet_count = 0; let mut errors = Vec::::new(); - + for file_str in files { let path = Path::new(&file_str); if !path.is_file() { @@ -279,7 +279,7 @@ pub fn validate_file_names(files: &Vec) -> Result<(), String> { // Couldn't test it on windows. errors.push(format!("File has no name: {}", file_str)); } - + match path.extension().and_then(OsStr::to_str) { Some("xlsx") => spreadsheet_count += 1, Some("csv") | Some("pdf") => {}, @@ -289,9 +289,12 @@ pub fn validate_file_names(files: &Vec) -> Result<(), String> { } if spreadsheet_count > 1 { - errors.push(format!("Expected a single xlsx spreadsheet, found: {}", spreadsheet_count)); + errors.push(format!( + "Expected a single xlsx spreadsheet, found: {}", + spreadsheet_count + )); } - + if errors.len() > 0 { return Err(errors.join("\n")); } @@ -315,7 +318,7 @@ pub fn run_taxation( String, > { validate_file_names(&names)?; - + let mut parsed_interests_transactions: Vec<(String, f32)> = vec![]; let mut parsed_div_transactions: Vec<(String, f32, f32)> = vec![]; let mut parsed_sold_transactions: Vec<(String, String, f32, f32, f32)> = vec![]; @@ -429,7 +432,7 @@ pub fn run_taxation( #[cfg(test)] mod tests { use super::*; - + #[test] fn test_validate_file_names_invalid_path() { let files = vec![ @@ -452,7 +455,10 @@ mod tests { ]; let result = validate_file_names(&files); - assert_eq!(result.err(), Some(String::from("Expected a single xlsx spreadsheet, found: 2"))); + assert_eq!( + result.err(), + Some(String::from("Expected a single xlsx spreadsheet, found: 2")) + ); } #[test] @@ -483,7 +489,10 @@ mod tests { let files = vec![String::from("LICENCE")]; let result = validate_file_names(&files); - assert_eq!(result.err(), Some(String::from("File has no extension: LICENCE"))); + assert_eq!( + result.err(), + Some(String::from("File has no extension: LICENCE")) + ); } #[test]