diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /vendor/annotate-snippets/tests/diff | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/annotate-snippets/tests/diff')
-rw-r--r-- | vendor/annotate-snippets/tests/diff/mod.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/vendor/annotate-snippets/tests/diff/mod.rs b/vendor/annotate-snippets/tests/diff/mod.rs new file mode 100644 index 000000000..576c6c4d6 --- /dev/null +++ b/vendor/annotate-snippets/tests/diff/mod.rs @@ -0,0 +1,43 @@ +use difference::{Changeset, Difference}; +use yansi_term::Color::{Black, Green, Red}; + +pub fn get_diff(left: &str, right: &str) -> String { + let mut output = String::new(); + + let Changeset { diffs, .. } = Changeset::new(left, right, "\n"); + + for i in 0..diffs.len() { + match diffs[i] { + Difference::Same(ref x) => { + output += &format!(" {}\n", x); + } + Difference::Add(ref x) => { + match diffs[i - 1] { + Difference::Rem(ref y) => { + output += &format!("{}", Green.paint("+")); + let Changeset { diffs, .. } = Changeset::new(y, x, " "); + for c in diffs { + match c { + Difference::Same(ref z) => { + output += &format!("{} ", Green.paint(z.as_str())); + } + Difference::Add(ref z) => { + output += &format!("{} ", Black.on(Green).paint(z.as_str())); + } + _ => (), + } + } + output += "\n"; + } + _ => { + output += &format!("+{}\n", Green.paint(x.as_str())); + } + }; + } + Difference::Rem(ref x) => { + output += &format!("-{}\n", Red.paint(x.as_str())); + } + } + } + output +} |