Replace last usages of difference with dissimilar

This commit is contained in:
Jesse Bakker 2021-01-06 18:13:29 +01:00
parent c9cec381bc
commit 974313eb87
4 changed files with 18 additions and 13 deletions

9
Cargo.lock generated
View file

@ -342,12 +342,6 @@ dependencies = [
"lazy_static", "lazy_static",
] ]
[[package]]
name = "difference"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198"
[[package]] [[package]]
name = "dissimilar" name = "dissimilar"
version = "1.0.2" version = "1.0.2"
@ -1170,7 +1164,6 @@ name = "proc_macro_srv"
version = "0.0.0" version = "0.0.0"
dependencies = [ dependencies = [
"cargo_metadata", "cargo_metadata",
"difference",
"libloading", "libloading",
"mbe", "mbe",
"memmap", "memmap",
@ -1621,7 +1614,7 @@ dependencies = [
name = "test_utils" name = "test_utils"
version = "0.0.0" version = "0.0.0"
dependencies = [ dependencies = [
"difference", "dissimilar",
"rustc-hash", "rustc-hash",
"serde_json", "serde_json",
"stdx", "stdx",

View file

@ -21,7 +21,6 @@ test_utils = { path = "../test_utils", version = "0.0.0" }
[dev-dependencies] [dev-dependencies]
cargo_metadata = "=0.12.0" cargo_metadata = "=0.12.0"
difference = "2.0.0"
# used as proc macro test targets # used as proc macro test targets
serde_derive = "1.0.106" serde_derive = "1.0.106"

View file

@ -11,7 +11,7 @@ doctest = false
[dependencies] [dependencies]
# Avoid adding deps here, this crate is widely used in tests it should compile fast! # Avoid adding deps here, this crate is widely used in tests it should compile fast!
difference = "2.0.0" dissimilar = "1.0.2"
text-size = "1.0.0" text-size = "1.0.0"
serde_json = "1.0.48" serde_json = "1.0.48"
rustc-hash = "1.1.0" rustc-hash = "1.1.0"

View file

@ -20,7 +20,7 @@ use serde_json::Value;
use stdx::lines_with_ends; use stdx::lines_with_ends;
use text_size::{TextRange, TextSize}; use text_size::{TextRange, TextSize};
pub use difference::Changeset as __Changeset; pub use dissimilar::diff as __diff;
pub use rustc_hash::FxHashMap; pub use rustc_hash::FxHashMap;
pub use crate::fixture::Fixture; pub use crate::fixture::Fixture;
@ -45,8 +45,8 @@ macro_rules! assert_eq_text {
if left.trim() == right.trim() { if left.trim() == right.trim() {
std::eprintln!("Left:\n{:?}\n\nRight:\n{:?}\n\nWhitespace difference\n", left, right); std::eprintln!("Left:\n{:?}\n\nRight:\n{:?}\n\nWhitespace difference\n", left, right);
} else { } else {
let changeset = $crate::__Changeset::new(left, right, "\n"); let diff = $crate::__diff(left, right);
std::eprintln!("Left:\n{}\n\nRight:\n{}\n\nDiff:\n{}\n", left, right, changeset); std::eprintln!("Left:\n{}\n\nRight:\n{}\n\nDiff:\n{}\n", left, right, $crate::format_diff(diff));
} }
std::eprintln!($($tt)*); std::eprintln!($($tt)*);
panic!("text differs"); panic!("text differs");
@ -392,3 +392,16 @@ pub fn project_dir() -> PathBuf {
let dir = env!("CARGO_MANIFEST_DIR"); let dir = env!("CARGO_MANIFEST_DIR");
PathBuf::from(dir).parent().unwrap().parent().unwrap().to_owned() PathBuf::from(dir).parent().unwrap().parent().unwrap().to_owned()
} }
pub fn format_diff(chunks: Vec<dissimilar::Chunk>) -> String {
let mut buf = String::new();
for chunk in chunks {
let formatted = match chunk {
dissimilar::Chunk::Equal(text) => text.into(),
dissimilar::Chunk::Delete(text) => format!("\x1b[41m{}\x1b[0m", text),
dissimilar::Chunk::Insert(text) => format!("\x1b[42m{}\x1b[0m", text),
};
buf.push_str(&formatted);
}
buf
}