Skip to content

Commit

Permalink
Take offset into account
Browse files Browse the repository at this point in the history
  • Loading branch information
cruessler committed Sep 10, 2024
1 parent d64fb23 commit 77e5f03
Showing 1 changed file with 60 additions and 1 deletion.
61 changes: 60 additions & 1 deletion gix-blame/tests/blame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,10 @@ fn process_changes(
(new_hunk, changes_iter.next().cloned())
}
(_, _) => {
new_hunks_to_blame.push(hunk);
new_hunks_to_blame.push(UnblamedHunk::new(
hunk.range_in_blamed_file.clone(),
hunk.offset() + offset_in_destination,
));

let new_hunk = hunks_iter.next().cloned();

Expand Down Expand Up @@ -861,6 +864,62 @@ fn process_changes_works_added_hunk_8() {
assert_eq!(new_hunks_to_blame, vec![UnblamedHunk::new(2..3, 2)]);
}

#[test]
fn process_changes_works_added_hunk_9() {
let suspect = ObjectId::null(gix_hash::Kind::Sha1);
let mut lines_blamed: Vec<BlameEntry> = vec![BlameEntry {
range: 30..31,
commit_id: suspect,
}];
let hunks_to_blame: Vec<UnblamedHunk> = vec![
UnblamedHunk {
range_in_blamed_file: 0..30,
range_in_destination: 0..30,
},
UnblamedHunk {
range_in_blamed_file: 31..37,
range_in_destination: 31..37,
},
];
let changes: Vec<Change> = vec![
Change::Unchanged(0..16),
Change::Added(16..17, 0),
Change::Unchanged(17..37),
];
let new_hunks_to_blame = process_changes(&mut lines_blamed, hunks_to_blame, changes, suspect);

assert_eq!(
lines_blamed,
vec![
BlameEntry {
range: 16..17,
commit_id: suspect
},
BlameEntry {
range: 30..31,
commit_id: suspect
}
]
);
assert_eq!(
new_hunks_to_blame,
vec![
UnblamedHunk {
range_in_blamed_file: 0..16,
range_in_destination: 0..16
},
UnblamedHunk {
range_in_blamed_file: 17..30,
range_in_destination: 16..29
},
UnblamedHunk {
range_in_blamed_file: 31..37,
range_in_destination: 30..36
}
]
);
}

fn odb_at(worktree_path: &Path, name: &str) -> gix_odb::Handle {
gix_odb::at(worktree_path.join(name).join(".git/objects")).unwrap()
}
Expand Down

0 comments on commit 77e5f03

Please sign in to comment.