From 974313eb87b5086ddb07ab14c50192fcb9dcd5e9 Mon Sep 17 00:00:00 2001 From: Jesse Bakker Date: Wed, 6 Jan 2021 18:13:29 +0100 Subject: [PATCH] Replace last usages of difference with dissimilar --- Cargo.lock | 9 +-------- crates/proc_macro_srv/Cargo.toml | 1 - crates/test_utils/Cargo.toml | 2 +- crates/test_utils/src/lib.rs | 19 ++++++++++++++++--- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fe45f9decd..6b9020424a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -342,12 +342,6 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "difference" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" - [[package]] name = "dissimilar" version = "1.0.2" @@ -1170,7 +1164,6 @@ name = "proc_macro_srv" version = "0.0.0" dependencies = [ "cargo_metadata", - "difference", "libloading", "mbe", "memmap", @@ -1621,7 +1614,7 @@ dependencies = [ name = "test_utils" version = "0.0.0" dependencies = [ - "difference", + "dissimilar", "rustc-hash", "serde_json", "stdx", diff --git a/crates/proc_macro_srv/Cargo.toml b/crates/proc_macro_srv/Cargo.toml index df9a55c10e..f78c171945 100644 --- a/crates/proc_macro_srv/Cargo.toml +++ b/crates/proc_macro_srv/Cargo.toml @@ -21,7 +21,6 @@ test_utils = { path = "../test_utils", version = "0.0.0" } [dev-dependencies] cargo_metadata = "=0.12.0" -difference = "2.0.0" # used as proc macro test targets serde_derive = "1.0.106" diff --git a/crates/test_utils/Cargo.toml b/crates/test_utils/Cargo.toml index 93eecc6788..06341f003d 100644 --- a/crates/test_utils/Cargo.toml +++ b/crates/test_utils/Cargo.toml @@ -11,7 +11,7 @@ doctest = false [dependencies] # 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" serde_json = "1.0.48" rustc-hash = "1.1.0" diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs index 05940a546f..656dd2072b 100644 --- a/crates/test_utils/src/lib.rs +++ b/crates/test_utils/src/lib.rs @@ -20,7 +20,7 @@ use serde_json::Value; use stdx::lines_with_ends; use text_size::{TextRange, TextSize}; -pub use difference::Changeset as __Changeset; +pub use dissimilar::diff as __diff; pub use rustc_hash::FxHashMap; pub use crate::fixture::Fixture; @@ -45,8 +45,8 @@ macro_rules! assert_eq_text { if left.trim() == right.trim() { std::eprintln!("Left:\n{:?}\n\nRight:\n{:?}\n\nWhitespace difference\n", left, right); } else { - let changeset = $crate::__Changeset::new(left, right, "\n"); - std::eprintln!("Left:\n{}\n\nRight:\n{}\n\nDiff:\n{}\n", left, right, changeset); + let diff = $crate::__diff(left, right); + std::eprintln!("Left:\n{}\n\nRight:\n{}\n\nDiff:\n{}\n", left, right, $crate::format_diff(diff)); } std::eprintln!($($tt)*); panic!("text differs"); @@ -392,3 +392,16 @@ pub fn project_dir() -> PathBuf { let dir = env!("CARGO_MANIFEST_DIR"); PathBuf::from(dir).parent().unwrap().parent().unwrap().to_owned() } + +pub fn format_diff(chunks: Vec) -> 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 +}