]> git.proxmox.com Git - rustc.git/blame - vendor/annotate-snippets-0.6.1/tests/diff/mod.rs
Update upstream source from tag 'upstream/1.52.1+dfsg1'
[rustc.git] / vendor / annotate-snippets-0.6.1 / tests / diff / mod.rs
CommitLineData
f20569fa
XL
1use ansi_term::Color::{Black, Green, Red};
2use difference::{Changeset, Difference};
3
4pub fn get_diff(left: &str, right: &str) -> String {
5 let mut output = String::new();
6
7 let Changeset { diffs, .. } = Changeset::new(left, right, "\n");
8
9 for i in 0..diffs.len() {
10 match diffs[i] {
11 Difference::Same(ref x) => {
12 output += &format!(" {}\n", x);
13 }
14 Difference::Add(ref x) => {
15 match diffs[i - 1] {
16 Difference::Rem(ref y) => {
17 output += &format!("{}", Green.paint("+"));
18 let Changeset { diffs, .. } = Changeset::new(y, x, " ");
19 for c in diffs {
20 match c {
21 Difference::Same(ref z) => {
22 output += &format!("{} ", Green.paint(z.as_str()));
23 }
24 Difference::Add(ref z) => {
25 output += &format!("{} ", Black.on(Green).paint(z.as_str()));
26 }
27 _ => (),
28 }
29 }
30 output += "\n";
31 }
32 _ => {
33 output += &format!("+{}\n", Green.paint(x.as_str()));
34 }
35 };
36 }
37 Difference::Rem(ref x) => {
38 output += &format!("-{}\n", Red.paint(x.as_str()));
39 }
40 }
41 }
42 return output;
43}