aboutsummaryrefslogtreecommitdiff
path: root/crates/test_utils/src
diff options
context:
space:
mode:
authorJesse Bakker <[email protected]>2021-01-06 17:13:29 +0000
committerJesse Bakker <[email protected]>2021-01-06 17:13:29 +0000
commit974313eb87b5086ddb07ab14c50192fcb9dcd5e9 (patch)
tree5429b3539462f0805fecb8abea6fdc4a31e52044 /crates/test_utils/src
parentc9cec381bcfd97e5f3536e31a9c546ab5c0665e6 (diff)
Replace last usages of difference with dissimilar
Diffstat (limited to 'crates/test_utils/src')
-rw-r--r--crates/test_utils/src/lib.rs19
1 files changed, 16 insertions, 3 deletions
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;
20use stdx::lines_with_ends; 20use stdx::lines_with_ends;
21use text_size::{TextRange, TextSize}; 21use text_size::{TextRange, TextSize};
22 22
23pub use difference::Changeset as __Changeset; 23pub use dissimilar::diff as __diff;
24pub use rustc_hash::FxHashMap; 24pub use rustc_hash::FxHashMap;
25 25
26pub use crate::fixture::Fixture; 26pub 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
396pub 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}