Skip to content

Commit a89f30a

Browse files
oSoMoNsylvestre
authored andcommitted
Ed diff: compact ranges of lines where possible (fixes #21)
1 parent 0a67bf9 commit a89f30a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/ed_diff.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ pub fn diff(expected: &[u8], actual: &[u8]) -> Result<Vec<u8>, DiffError> {
122122
expected_count + line_number_expected - 1
123123
)
124124
.unwrap(),
125+
(1, _) => writeln!(&mut output, "{}c", line_number_expected).unwrap(),
125126
_ => writeln!(
126127
&mut output,
127128
"{},{}c",
@@ -156,6 +157,15 @@ mod tests {
156157
Ok(output)
157158
}
158159

160+
#[test]
161+
fn test_basic() {
162+
let from = b"a\n";
163+
let to = b"b\n";
164+
let diff = diff(from, to).unwrap();
165+
let expected = vec!["1c", "b", ".", ""].join("\n");
166+
assert_eq!(diff, expected.as_bytes());
167+
}
168+
159169
#[test]
160170
fn test_permutations() {
161171
let target = "target/ed-diff/";

0 commit comments

Comments
 (0)