Improve diff op grouping for full matches

This changes the behavior of the diff op grouping function to return
an empty result if the diff is a full match.  This also adds an example
to demonstrate unified diff rendering.
This commit is contained in:
Armin Ronacher 2021-01-30 23:11:35 +01:00
parent 4459c5ee3a
commit 020701c4d5
5 changed files with 62 additions and 3 deletions

22
examples/udiff.rs Normal file
View file

@ -0,0 +1,22 @@
use std::fs::read_to_string;
use std::process::exit;
use similar::text::TextDiff;
fn main() {
let args: Vec<_> = std::env::args_os().collect();
if args.len() != 3 {
eprintln!("usage: udiff [old] [new]");
exit(1);
}
let old = read_to_string(&args[1]).unwrap();
let new = read_to_string(&args[2]).unwrap();
print!(
"{}",
TextDiff::from_lines(&old, &new).unified_diff().header(
&args[1].as_os_str().to_string_lossy(),
&args[2].as_os_str().to_string_lossy()
)
);
}