diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-01-06 17:16:04 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-01-06 17:16:04 +0000 |
commit | ae2ea108e08bdd53362335e5a4e61a83feb296a0 (patch) | |
tree | 5429b3539462f0805fecb8abea6fdc4a31e52044 | |
parent | c9cec381bcfd97e5f3536e31a9c546ab5c0665e6 (diff) | |
parent | 974313eb87b5086ddb07ab14c50192fcb9dcd5e9 (diff) |
Merge #7182
7182: Replace last usages of difference with dissimilar r=matklad a=Jesse-Bakker
Co-authored-by: Jesse Bakker <[email protected]>
-rw-r--r-- | Cargo.lock | 9 | ||||
-rw-r--r-- | crates/proc_macro_srv/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/test_utils/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/test_utils/src/lib.rs | 19 |
4 files changed, 18 insertions, 13 deletions
diff --git a/Cargo.lock b/Cargo.lock index fe45f9dec..6b9020424 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -343,12 +343,6 @@ dependencies = [ | |||
343 | ] | 343 | ] |
344 | 344 | ||
345 | [[package]] | 345 | [[package]] |
346 | name = "difference" | ||
347 | version = "2.0.0" | ||
348 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
349 | checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" | ||
350 | |||
351 | [[package]] | ||
352 | name = "dissimilar" | 346 | name = "dissimilar" |
353 | version = "1.0.2" | 347 | version = "1.0.2" |
354 | source = "registry+https://github.com/rust-lang/crates.io-index" | 348 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1170,7 +1164,6 @@ name = "proc_macro_srv" | |||
1170 | version = "0.0.0" | 1164 | version = "0.0.0" |
1171 | dependencies = [ | 1165 | dependencies = [ |
1172 | "cargo_metadata", | 1166 | "cargo_metadata", |
1173 | "difference", | ||
1174 | "libloading", | 1167 | "libloading", |
1175 | "mbe", | 1168 | "mbe", |
1176 | "memmap", | 1169 | "memmap", |
@@ -1621,7 +1614,7 @@ dependencies = [ | |||
1621 | name = "test_utils" | 1614 | name = "test_utils" |
1622 | version = "0.0.0" | 1615 | version = "0.0.0" |
1623 | dependencies = [ | 1616 | dependencies = [ |
1624 | "difference", | 1617 | "dissimilar", |
1625 | "rustc-hash", | 1618 | "rustc-hash", |
1626 | "serde_json", | 1619 | "serde_json", |
1627 | "stdx", | 1620 | "stdx", |
diff --git a/crates/proc_macro_srv/Cargo.toml b/crates/proc_macro_srv/Cargo.toml index df9a55c10..f78c17194 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" } | |||
21 | 21 | ||
22 | [dev-dependencies] | 22 | [dev-dependencies] |
23 | cargo_metadata = "=0.12.0" | 23 | cargo_metadata = "=0.12.0" |
24 | difference = "2.0.0" | ||
25 | 24 | ||
26 | # used as proc macro test targets | 25 | # used as proc macro test targets |
27 | serde_derive = "1.0.106" | 26 | serde_derive = "1.0.106" |
diff --git a/crates/test_utils/Cargo.toml b/crates/test_utils/Cargo.toml index 93eecc678..06341f003 100644 --- a/crates/test_utils/Cargo.toml +++ b/crates/test_utils/Cargo.toml | |||
@@ -11,7 +11,7 @@ doctest = false | |||
11 | 11 | ||
12 | [dependencies] | 12 | [dependencies] |
13 | # Avoid adding deps here, this crate is widely used in tests it should compile fast! | 13 | # 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" |
15 | text-size = "1.0.0" | 15 | text-size = "1.0.0" |
16 | serde_json = "1.0.48" | 16 | serde_json = "1.0.48" |
17 | rustc-hash = "1.1.0" | 17 | rustc-hash = "1.1.0" |
diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs index 05940a546..656dd2072 100644 --- a/crates/test_utils/src/lib.rs +++ b/crates/test_utils/src/lib.rs | |||
@@ -20,7 +20,7 @@ use serde_json::Value; | |||
20 | use stdx::lines_with_ends; | 20 | use stdx::lines_with_ends; |
21 | use text_size::{TextRange, TextSize}; | 21 | use text_size::{TextRange, TextSize}; |
22 | 22 | ||
23 | pub use difference::Changeset as __Changeset; | 23 | pub use dissimilar::diff as __diff; |
24 | pub use rustc_hash::FxHashMap; | 24 | pub use rustc_hash::FxHashMap; |
25 | 25 | ||
26 | pub use crate::fixture::Fixture; | 26 | pub use crate::fixture::Fixture; |
@@ -45,8 +45,8 @@ macro_rules! assert_eq_text { | |||
45 | if left.trim() == right.trim() { | 45 | if left.trim() == right.trim() { |
46 | std::eprintln!("Left:\n{:?}\n\nRight:\n{:?}\n\nWhitespace difference\n", left, right); | 46 | std::eprintln!("Left:\n{:?}\n\nRight:\n{:?}\n\nWhitespace difference\n", left, right); |
47 | } else { | 47 | } else { |
48 | let changeset = $crate::__Changeset::new(left, right, "\n"); | 48 | let diff = $crate::__diff(left, right); |
49 | std::eprintln!("Left:\n{}\n\nRight:\n{}\n\nDiff:\n{}\n", left, right, changeset); | 49 | std::eprintln!("Left:\n{}\n\nRight:\n{}\n\nDiff:\n{}\n", left, right, $crate::format_diff(diff)); |
50 | } | 50 | } |
51 | std::eprintln!($($tt)*); | 51 | std::eprintln!($($tt)*); |
52 | panic!("text differs"); | 52 | panic!("text differs"); |
@@ -392,3 +392,16 @@ pub fn project_dir() -> PathBuf { | |||
392 | let dir = env!("CARGO_MANIFEST_DIR"); | 392 | let dir = env!("CARGO_MANIFEST_DIR"); |
393 | PathBuf::from(dir).parent().unwrap().parent().unwrap().to_owned() | 393 | PathBuf::from(dir).parent().unwrap().parent().unwrap().to_owned() |
394 | } | 394 | } |
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 | } | ||