|
|
|
@@ -118,3 +118,34 @@ fn find_diff(vec1: &[CsvLine], vec2: &[CsvLine], diff: &mut Vec<CsvLine>, params
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod test {
|
|
|
|
|
use std::{fs::File, io::BufReader, path::Path};
|
|
|
|
|
|
|
|
|
|
use crate::csv::compare::{compare, CsvLine, Params};
|
|
|
|
|
|
|
|
|
|
fn get_reader(file_path: String) -> BufReader<File> {
|
|
|
|
|
let path = Path::new(&file_path);
|
|
|
|
|
assert!(path.is_file());
|
|
|
|
|
let file = File::open(path);
|
|
|
|
|
match file {
|
|
|
|
|
Ok(_) => BufReader::new(file.unwrap()),
|
|
|
|
|
Err(_) => panic!("error, could not read file"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_find_diff() {
|
|
|
|
|
let file1 = get_reader("./assets/csv1.csv".to_string());
|
|
|
|
|
let file2 = get_reader("./assets/csv2.csv".to_string());
|
|
|
|
|
let params: Params = Params {
|
|
|
|
|
delimiter: ';'.to_string(),
|
|
|
|
|
source: "./assets/csv1.csv".to_owned(),
|
|
|
|
|
compared: "./assets/csv1.csv".to_owned(),
|
|
|
|
|
column: 1,
|
|
|
|
|
output: Some("./assets/result.csv".to_owned()),
|
|
|
|
|
};
|
|
|
|
|
let result: Vec<CsvLine> = compare(file1, file2, ¶ms);
|
|
|
|
|
assert_eq!(3, result.len());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|