diff --git a/src/validate.rs b/src/validate.rs index 9b90c42..a9d3192 100644 --- a/src/validate.rs +++ b/src/validate.rs @@ -5,11 +5,37 @@ use crate::util; pub fn validate(verbosity: u8, config: util::config::Config) { println!("Validating"); + let in_suffix = "in"; //TODO make this configurable? + let out_suffix = "out"; // get list of all file names in input/output - let in_files: Vec; - let out_files: Vec; + let in_files: Vec = get_dir_files(config.input_path).expect("Failed to read the input directory contents"); + let out_files: Vec = get_dir_files(config.output_path).expect("Failed to read the output directory contents"); + + let mismatch: Vec<(PathBuf, PathBuf)>; + let mut invalid_suffix_in: Vec = vec![]; + let mut invalid_suffix_out: Vec = vec![]; // check if they end in .in or .out respectively + for file in in_files { + if !file.ends_with(in_suffix) { + invalid_suffix_in.push(file); + } + } + + for file in out_files { + if !file.ends_with(out_suffix) { + invalid_suffix_out.push(file); + } + } + + // print the delinquints + if invalid_suffix_in.len() > 0 { + print_invalid_suffixes(invalid_suffix_in, String::from(in_suffix)); + } + + if invalid_suffix_out.len() > 0 { + print_invalid_suffixes(invalid_suffix_out, String::from(out_suffix)); + } // make sure each has a match } @@ -35,15 +61,44 @@ fn get_dir_files(path: PathBuf) -> Result, &'static str> { return Ok(res); } +fn compare_files(in_files: Vec, out_files: Vec) -> Vec { + let mut res: Vec = vec![]; -fn check_suffix(path: PathBuf, suf: String) -> bool { - return false; + res.append(&mut compare_list(in_files, out_files)); + res.append(&mut compare_list(out_files, in_files)); + + return res; } -fn check_match(path1: PathBuf, path2: PathBuf, in_suf: String, out_suf: String) -> bool { - return false; +fn compare_list(from: Vec, against: Vec) -> Vec { + let res: Vec = vec![]; + + // Compare each input file to each output file + for file in from { + let beg = file.file_stem().unwrap(); // ignore suffix + for out in against { + if beg == out.file_stem().unwrap() { + break; + } + } + res.push(file); // if the file does not have a counterpart, then push to the lost files + } + + return res; } +fn print_invalid_suffixes(files: Vec, exp: String) { + println!("Invalid suffixes detected 😱:" ); + println!("Current => Suggested"); + for mut file in files { + let initial = match file.to_str() { + Some(x) => x, + _ => panic!("Failed to load the file"), + }; + + println!("{} => {}", initial, file.set_extension(exp).to_string()); + } +} #[cfg(test)] mod tests {