refactor(utils): assert line by line
This commit is contained in:
parent
b106023696
commit
69c9d27193
2 changed files with 16 additions and 22 deletions
|
|
@ -68,17 +68,7 @@ fn test_preprocess_expand_labels_shortcut_single_language() {
|
|||
r#"description: "The english description" => { language: [en] },"#,
|
||||
r#"alias: ("Alias 1", "Alias 2") => { language: [en] },"#,
|
||||
];
|
||||
// assert line by line the output
|
||||
// TODO: extract in a external function
|
||||
let mut i: usize = 0;
|
||||
for actual_output in pout.code_output.split("\n").collect::<Vec<&str>>().iter() {
|
||||
if actual_output.trim().len() == 0 {
|
||||
continue;
|
||||
}
|
||||
let expected_line = expected_out.iter().nth(i).unwrap().trim();
|
||||
assert_eq!(actual_output.trim(), expected_line);
|
||||
i += 1;
|
||||
}
|
||||
crate::utils::assert_line_by_line(&pout.code_output, expected_out);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -100,17 +90,7 @@ fn test_preprocess_expand_labels_shortcut_multiple_languages() {
|
|||
r#"description: "description en" => { language: [en] },"#,
|
||||
r#"alias: ("another alias1", "another alias2") => { language: [en] },"#
|
||||
];
|
||||
// assert line by line the output
|
||||
// TODO: extract in a external function
|
||||
let mut i: usize = 0;
|
||||
for actual_output in pout.code_output.split("\n").collect::<Vec<&str>>().iter() {
|
||||
if actual_output.trim().len() == 0 {
|
||||
continue;
|
||||
}
|
||||
let expected_line = expected_out.iter().nth(i).unwrap().trim();
|
||||
assert_eq!(actual_output.trim(), expected_line);
|
||||
i += 1;
|
||||
}
|
||||
crate::utils::assert_line_by_line(&pout.code_output, expected_out);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -108,3 +108,17 @@ macro_rules! contains {
|
|||
($( !$array.contains($not_val) ) && *) && $( $array.contains($val) ) && *
|
||||
};
|
||||
}
|
||||
|
||||
/// Test if two buffers are equals line by line
|
||||
/// Useful in unit tests
|
||||
pub fn assert_line_by_line(actual_output: &str, expected_output_lines: Vec<&str>) {
|
||||
let actual_output_lines: Vec<&str> = actual_output
|
||||
.split("\n")
|
||||
.filter(|l| !l.trim().is_empty())
|
||||
.collect();
|
||||
for (actual_line, expected_line) in actual_output_lines
|
||||
.iter().zip(expected_output_lines)
|
||||
{
|
||||
assert_eq!(actual_line.trim(), expected_line);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue