Add a basic unit test for matched_lines_for_hunk

html_output
Wilfred Hughes 2022-02-12 12:08:06 +07:00
parent ef5ae1ad8d
commit 92cf448081
1 changed files with 29 additions and 0 deletions

@ -685,6 +685,8 @@ pub fn matched_lines_for_hunk(
#[cfg(test)]
mod tests {
use std::iter::FromIterator;
use super::*;
use crate::{
positions::SingleLineSpan,
@ -818,4 +820,31 @@ mod tests {
]
)
}
#[test]
fn test_matched_lines_for_hunk() {
let matched_lines = &[
(Some(0.into()), Some(0.into())),
(Some(1.into()), Some(1.into())),
(Some(2.into()), Some(2.into())),
];
let novel_lhs = HashSet::from_iter([1.into()]);
let novel_rhs = HashSet::from_iter([1.into()]);
let hunk = Hunk {
novel_lhs,
novel_rhs,
lines: vec![(Some(1.into()), Some(1.into()))],
};
let res = matched_lines_for_hunk(matched_lines, &hunk);
assert_eq!(
res,
vec![
(Some(0.into()), Some(0.into())),
(Some(1.into()), Some(1.into())),
(Some(2.into()), Some(2.into())),
]
);
}
}