Skip to content

Commit

Permalink
Ed diff: compact ranges of lines where possible (fixes #21)
Browse files Browse the repository at this point in the history
  • Loading branch information
oSoMoN authored and sylvestre committed Feb 24, 2024
1 parent 0a67bf9 commit a89f30a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/ed_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ pub fn diff(expected: &[u8], actual: &[u8]) -> Result<Vec<u8>, DiffError> {
expected_count + line_number_expected - 1
)
.unwrap(),
(1, _) => writeln!(&mut output, "{}c", line_number_expected).unwrap(),
_ => writeln!(
&mut output,
"{},{}c",
Expand Down Expand Up @@ -156,6 +157,15 @@ mod tests {
Ok(output)
}

#[test]
fn test_basic() {
let from = b"a\n";
let to = b"b\n";
let diff = diff(from, to).unwrap();
let expected = vec!["1c", "b", ".", ""].join("\n");
assert_eq!(diff, expected.as_bytes());
}

#[test]
fn test_permutations() {
let target = "target/ed-diff/";
Expand Down

0 comments on commit a89f30a

Please sign in to comment.