Skip to content

Commit

Permalink
Alternative fix for #37 that lets the code hobble on
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Jul 28, 2022
1 parent 3a938ae commit ff5f4ca
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 0 additions & 2 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ pub fn get_diff_ratio(ops: &[DiffOp], old_len: usize, new_len: usize) -> f32 {
/// This will leave holes behind in long periods of equal ranges so that
/// you can build things like unified diffs.
pub fn group_diff_ops(mut ops: Vec<DiffOp>, n: usize) -> Vec<Vec<DiffOp>> {
assert!(n > 0, "n must be 1 or larger");

if ops.is_empty() {
return vec![];
}
Expand Down
8 changes: 5 additions & 3 deletions src/text/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,10 +760,12 @@ fn test_serde_ops() {
}

#[test]
#[should_panic = "n must be 1 or larger"]
fn test_regression_issue_37() {
let config = TextDiffConfig::default();
let diff = config.diff_lines("", "");
let diff = config.diff_lines("\u{18}\n\n", "\n\n\r");
let mut output = diff.unified_diff();
output.context_radius(0).to_string();
assert_eq!(
output.context_radius(0).to_string(),
"@@ -1 +1,0 @@\n-\u{18}\n@@ -2,0 +2,2 @@\n+\n+\r"
);
}
2 changes: 1 addition & 1 deletion src/udiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl UnifiedDiffHunkRange {
impl fmt::Display for UnifiedDiffHunkRange {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut beginning = self.start() + 1;
let len = self.end() - self.start();
let len = self.end().saturating_sub(self.start());
if len == 1 {
write!(f, "{}", beginning)
} else {
Expand Down

0 comments on commit ff5f4ca

Please sign in to comment.