added test

master
Mathias Rothenhaeusler 2023-07-31 19:38:24 +02:00
parent 22adb1bedd
commit 1812caa171
2 changed files with 33 additions and 1 deletions

View File

@ -1,3 +1,4 @@
nr;text;flag
123213;bla bal;1
123123;second one;0
77732;hahah;3

1 nr text flag
2 123213 bla bal 1
3 123123 second one 0
4 77732 hahah 3

View File

@ -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, &params);
assert_eq!(3, result.len());
}
}