Skip to content

Commit ae2ea10

Browse files
Merge #7182
7182: Replace last usages of difference with dissimilar r=matklad a=Jesse-Bakker Co-authored-by: Jesse Bakker <github@jessebakker.com>
2 parents c9cec38 + 974313e commit ae2ea10

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

Cargo.lock

Lines changed: 1 addition & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/proc_macro_srv/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ test_utils = { path = "../test_utils", version = "0.0.0" }
2121

2222
[dev-dependencies]
2323
cargo_metadata = "=0.12.0"
24-
difference = "2.0.0"
2524

2625
# used as proc macro test targets
2726
serde_derive = "1.0.106"

crates/test_utils/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ doctest = false
1111

1212
[dependencies]
1313
# Avoid adding deps here, this crate is widely used in tests it should compile fast!
14-
difference = "2.0.0"
14+
dissimilar = "1.0.2"
1515
text-size = "1.0.0"
1616
serde_json = "1.0.48"
1717
rustc-hash = "1.1.0"

crates/test_utils/src/lib.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use serde_json::Value;
2020
use stdx::lines_with_ends;
2121
use text_size::{TextRange, TextSize};
2222

23-
pub use difference::Changeset as __Changeset;
23+
pub use dissimilar::diff as __diff;
2424
pub use rustc_hash::FxHashMap;
2525

2626
pub use crate::fixture::Fixture;
@@ -45,8 +45,8 @@ macro_rules! assert_eq_text {
4545
if left.trim() == right.trim() {
4646
std::eprintln!("Left:\n{:?}\n\nRight:\n{:?}\n\nWhitespace difference\n", left, right);
4747
} else {
48-
let changeset = $crate::__Changeset::new(left, right, "\n");
49-
std::eprintln!("Left:\n{}\n\nRight:\n{}\n\nDiff:\n{}\n", left, right, changeset);
48+
let diff = $crate::__diff(left, right);
49+
std::eprintln!("Left:\n{}\n\nRight:\n{}\n\nDiff:\n{}\n", left, right, $crate::format_diff(diff));
5050
}
5151
std::eprintln!($($tt)*);
5252
panic!("text differs");
@@ -392,3 +392,16 @@ pub fn project_dir() -> PathBuf {
392392
let dir = env!("CARGO_MANIFEST_DIR");
393393
PathBuf::from(dir).parent().unwrap().parent().unwrap().to_owned()
394394
}
395+
396+
pub fn format_diff(chunks: Vec<dissimilar::Chunk>) -> String {
397+
let mut buf = String::new();
398+
for chunk in chunks {
399+
let formatted = match chunk {
400+
dissimilar::Chunk::Equal(text) => text.into(),
401+
dissimilar::Chunk::Delete(text) => format!("\x1b[41m{}\x1b[0m", text),
402+
dissimilar::Chunk::Insert(text) => format!("\x1b[42m{}\x1b[0m", text),
403+
};
404+
buf.push_str(&formatted);
405+
}
406+
buf
407+
}

0 commit comments

Comments
 (0)