Skip to content

Commit

Permalink
refactor: remove difference dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
amaanq committed May 26, 2024
1 parent c440f2a commit fc146ad
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 22 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ clap = { version = "4.5.4", features = [
] }
ctor = "0.2.8"
ctrlc = { version = "3.4.4", features = ["termination"] }
difference = "2.0.0"
dirs = "5.0.1"
filetime = "0.2.23"
fs4 = "0.8.3"
Expand All @@ -75,6 +74,7 @@ semver = "1.0.23"
serde = { version = "1.0.202", features = ["derive"] }
serde_derive = "1.0.197"
serde_json = { version = "1.0.117", features = ["preserve_order"] }
similar = "2.5.0"
smallbitvec = "2.5.3"
tempfile = "3.10.1"
thiserror = "1.0.61"
Expand Down
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ anstyle.workspace = true
anyhow.workspace = true
clap.workspace = true
ctrlc.workspace = true
difference.workspace = true
dirs.workspace = true
filetime.workspace = true
glob.workspace = true
Expand All @@ -47,6 +46,7 @@ semver.workspace = true
serde.workspace = true
serde_derive.workspace = true
serde_json.workspace = true
similar.workspace = true
smallbitvec.workspace = true
tiny_http.workspace = true
walkdir.workspace = true
Expand Down
33 changes: 20 additions & 13 deletions cli/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ use std::{

use anstyle::{AnsiColor, Color, Style};
use anyhow::{anyhow, Context, Result};
use difference::{Changeset, Difference};
use indoc::indoc;
use lazy_static::lazy_static;
use regex::{
bytes::{Regex as ByteRegex, RegexBuilder as ByteRegexBuilder},
Regex,
};
use similar::{ChangeTag, TextDiff};
use tree_sitter::{format_sexp, Language, LogType, Parser, Query};
use walkdir::WalkDir;

Expand Down Expand Up @@ -276,32 +276,39 @@ pub fn print_diff_key() {
}

pub fn print_diff(actual: &str, expected: &str, use_color: bool) {
let changeset = Changeset::new(actual, expected, "\n");
for diff in &changeset.diffs {
match diff {
Difference::Same(part) => {
let diff = TextDiff::from_lines(actual, expected);
for diff in diff.iter_all_changes() {
match diff.tag() {
ChangeTag::Equal => {
if use_color {
print!("{part}{}", changeset.split);
print!("{diff}");
} else {
print!("correct:\n{part}{}", changeset.split);
print!(" {diff}");
}
}
Difference::Add(part) => {
ChangeTag::Insert => {
if use_color {
println!("{}{}", paint(Some(AnsiColor::Green), part), changeset.split);
print!("{}", paint(Some(AnsiColor::Green), diff.as_str().unwrap()));
} else {
print!("expected:\n{part}{}", changeset.split);
print!("+{diff}");
}
if diff.missing_newline() {
println!();
}
}
Difference::Rem(part) => {
ChangeTag::Delete => {
if use_color {
println!("{}{}", paint(Some(AnsiColor::Red), part), changeset.split);
print!("{}", paint(Some(AnsiColor::Red), diff.as_str().unwrap()));
} else {
print!("unexpected:\n{part}{}", changeset.split);
print!("-{diff}");
}
if diff.missing_newline() {
println!();
}
}
}
}

println!();
}

Expand Down

0 comments on commit fc146ad

Please sign in to comment.