Skip to content

Commit

Permalink
Fix offset when no overlap
Browse files Browse the repository at this point in the history
  • Loading branch information
cruessler committed Sep 17, 2024
1 parent 3f0de4b commit 68e5f17
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion gix-blame/tests/blame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,13 @@ fn process_change(
//
// <--> (hunk)
// <----> (added)
new_hunks_to_blame.push(hunk);
let line_range_in_next_destination =
LineRange::with_offset(hunk.range_in_destination.clone(), *offset_in_destination);

new_hunks_to_blame.push(UnblamedHunk::from_destination(
line_range_in_next_destination.into(),
hunk.offset() + *offset_in_destination,
));

(None, Some(Change::Added(added, number_of_lines_deleted)))
}
Expand Down Expand Up @@ -1173,6 +1179,36 @@ fn process_change_works_added_hunk_7() {
assert_eq!(offset_in_destination, Offset::Added(3));
}

#[test]
fn process_change_works_no_overlap() {
let mut lines_blamed: Vec<BlameEntry> = vec![];
let mut new_hunks_to_blame: Vec<UnblamedHunk> = vec![];
let mut offset_in_destination: Offset = Offset::Deleted(3);
let suspect = ObjectId::null(gix_hash::Kind::Sha1);

let (hunk, change) = process_change(
&mut lines_blamed,
&mut new_hunks_to_blame,
&mut offset_in_destination,
suspect,
// range_in_destination: 2..5
Some(UnblamedHunk::new(3..6, Offset::Added(1))),
Some(Change::Added(7..10, 1)),
);

assert_eq!(hunk, None);
assert_eq!(change, Some(Change::Added(7..10, 1)));
assert_eq!(lines_blamed, vec![]);
assert_eq!(
new_hunks_to_blame,
vec![UnblamedHunk {
range_in_blamed_file: 3..6,
range_in_destination: 5..8
}]
);
assert_eq!(offset_in_destination, Offset::Deleted(3));
}

#[test]
fn process_change_works_unchanged_hunk() {
let mut lines_blamed: Vec<BlameEntry> = vec![];
Expand Down

0 comments on commit 68e5f17

Please sign in to comment.