Skip to content

Commit

Permalink
chore: remove unmaintained difference in favor of similar (#6694)
Browse files Browse the repository at this point in the history
## Description

closes #5421.

Removes unmaintained `difference` create used in swayfmt and uses
`similar` instead. Security wise this is not an important problem as the
dependency is only used as a dev-dependency. But the pr is a part of an
effort cleaning `RUSTSEC` issues mainly for housekeeping reasons of our
ever growing repo.
  • Loading branch information
kayagokalp authored Nov 5, 2024
1 parent 431eab1 commit 16318d3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
8 changes: 1 addition & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion swayfmt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ thiserror.workspace = true
toml = { workspace = true, features = ["parse"] }

[dev-dependencies]
difference = "2.0.0"
paste = "1.0"
prettydiff = "0.6"
similar = "2.0"
test-macros = { path = "test_macros" }
23 changes: 14 additions & 9 deletions swayfmt/test_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,23 @@ macro_rules! fmt_test_inner {
#[macro_export]
macro_rules! assert_eq_pretty {
($got:expr, $expected:expr) => {
let got = &$got;
let expected = &$expected;
let got = &$got[..];
let expected = &$expected[..];

if got != expected {
use difference::{Changeset, Difference};
let changeset = Changeset::new(expected, got, "\n");
for diff in changeset.diffs {
match diff {
Difference::Same(s) => println!("{}", s),
Difference::Add(s) => println!("\x1b[32m+{}\x1b[0m", s), // Green color for additions
Difference::Rem(s) => println!("\x1b[31m-{}\x1b[0m", s), // Red color for removals
use similar::TextDiff;

let diff = TextDiff::from_lines(expected, got);
for op in diff.ops() {
for change in diff.iter_changes(op) {
match change.tag() {
similar::ChangeTag::Equal => print!("{}", change),
similar::ChangeTag::Insert => print!("\x1b[32m+{}\x1b[0m", change), // Green for additions
similar::ChangeTag::Delete => print!("\x1b[31m-{}\x1b[0m", change), // Red for deletions
}
}
}
println!();
panic!("printed outputs differ!");
}
};
Expand Down

0 comments on commit 16318d3

Please sign in to comment.