|
| 1 | +use gix::bstr::BString; |
| 2 | +use std::num::NonZero; |
| 3 | + |
| 4 | +#[test] |
| 5 | +fn simple() -> crate::Result { |
| 6 | + let repo = crate::named_repo("make_blame_repo.sh")?; |
| 7 | + |
| 8 | + let suspect = repo.head_id()?; |
| 9 | + let outcome = repo.blame_file("simple.txt".into(), suspect, Default::default())?; |
| 10 | + |
| 11 | + assert_eq!(outcome.entries.len(), 4); |
| 12 | + |
| 13 | + Ok(()) |
| 14 | +} |
| 15 | + |
| 16 | +#[test] |
| 17 | +fn with_options() -> crate::Result { |
| 18 | + let repo = crate::named_repo("make_blame_repo.sh")?; |
| 19 | + |
| 20 | + let options = gix::blame::Options { |
| 21 | + range: gix::blame::BlameRanges::from_range(1..=2), |
| 22 | + ..Default::default() |
| 23 | + }; |
| 24 | + |
| 25 | + let suspect = repo.head_id()?; |
| 26 | + let outcome = repo.blame_file("simple.txt".into(), suspect, options)?; |
| 27 | + |
| 28 | + assert_eq!(outcome.entries.len(), 2); |
| 29 | + |
| 30 | + let entries_with_lines: Vec<_> = outcome.entries_with_lines().collect(); |
| 31 | + |
| 32 | + assert!(matches!( |
| 33 | + entries_with_lines.as_slice(), |
| 34 | + &[ |
| 35 | + ( |
| 36 | + gix::blame::BlameEntry { |
| 37 | + start_in_blamed_file: 0, |
| 38 | + start_in_source_file: 0, |
| 39 | + source_file_name: None, |
| 40 | + .. |
| 41 | + }, |
| 42 | + _, |
| 43 | + ), |
| 44 | + ( |
| 45 | + gix::blame::BlameEntry { |
| 46 | + start_in_blamed_file: 1, |
| 47 | + start_in_source_file: 1, |
| 48 | + source_file_name: None, |
| 49 | + .. |
| 50 | + }, |
| 51 | + _, |
| 52 | + ) |
| 53 | + ] |
| 54 | + )); |
| 55 | + |
| 56 | + assert_eq!(entries_with_lines[0].0.len, NonZero::new(1).unwrap()); |
| 57 | + assert_eq!(entries_with_lines[1].0.len, NonZero::new(1).unwrap()); |
| 58 | + |
| 59 | + assert_eq!(entries_with_lines[0].1, vec![BString::new("line 1\n".into())]); |
| 60 | + assert_eq!(entries_with_lines[1].1, vec![BString::new("line 2\n".into())]); |
| 61 | + |
| 62 | + Ok(()) |
| 63 | +} |
0 commit comments