added test
parent
22adb1bedd
commit
1812caa171
|
@ -1,3 +1,4 @@
|
|||
nr;text;flag
|
||||
123213;bla bal;1
|
||||
123123;second one;0
|
||||
123123;second one;0
|
||||
77732;hahah;3
|
||||
|
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue