Ed diff: compact ranges of lines where possible (fixes #21)

This commit is contained in:
Olivier Tilloy
2024-02-23 22:52:54 +01:00
committed by Sylvestre Ledru
parent 0a67bf9fb8
commit a89f30afa0
+10
View File
@@ -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",
@@ -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/";