Function snapbox::report::write_diff
source · pub fn write_diff(
writer: &mut dyn Write,
expected: &Data,
actual: &Data,
expected_name: Option<&dyn Display>,
actual_name: Option<&dyn Display>,
palette: Palette
) -> Result<(), Error>
Examples found in repository?
examples/diff.rs (lines 14-21)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
fn main() {
let mut args = std::env::args();
let _ = args.next().expect("expects `$ diff <old> <new>`");
let old_path = args.next().expect("expects `$ diff <old> <new>`");
let new_path = args.next().expect("expects `$ diff <old> <new>`");
if args.next().is_some() {
panic!("expects `$ diff <old> <new>`");
}
let old = snapbox::Data::text(std::fs::read_to_string(&old_path).unwrap());
let new = snapbox::Data::text(std::fs::read_to_string(&new_path).unwrap());
let mut output = String::new();
snapbox::report::write_diff(
&mut output,
&old,
&new,
Some(&old_path),
Some(&new_path),
snapbox::report::Palette::color(),
)
.unwrap();
println!("{output}");
}