mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 16:54:01 +00:00
Replace last usages of difference with dissimilar
This commit is contained in:
parent
c9cec381bc
commit
974313eb87
9
Cargo.lock
generated
9
Cargo.lock
generated
@ -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",
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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<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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user