diff --git a/Cargo.lock b/Cargo.lock index 6235103..4453f09 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -129,6 +129,7 @@ dependencies = [ "diff", "predicates", "pretty_assertions", + "regex", "same-file", "tempfile", ] @@ -301,9 +302,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.3" +version = "1.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" dependencies = [ "aho-corasick", "memchr", diff --git a/Cargo.toml b/Cargo.toml index 940e3d1..32f0cda 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ path = "src/main.rs" [dependencies] chrono = "0.4.35" diff = "0.1.10" +regex = "1.10.4" same-file = "1.0.6" [dev-dependencies] diff --git a/src/context_diff.rs b/src/context_diff.rs index fa09f7c..bb1dfe1 100644 --- a/src/context_diff.rs +++ b/src/context_diff.rs @@ -433,11 +433,12 @@ mod tests { if f != 2 { bet.write_all(b"l\n").unwrap(); } + let _ = File::create(&format!("{target}/aalef")).unwrap(); // This test diff is intentionally reversed. // We want it to turn the alef into bet. let diff = diff( &alef, - "a/alef", + &format!("{target}/aalef"), &bet, &format!("{target}/alef"), 2, @@ -512,11 +513,12 @@ mod tests { if f != 2 { bet.write_all(b"l\n").unwrap(); } + let _ = File::create(&format!("{target}/aalef_")).unwrap(); // This test diff is intentionally reversed. // We want it to turn the alef into bet. let diff = diff( &alef, - "a/alef_", + &format!("{target}/aalef_"), &bet, &format!("{target}/alef_"), 2, @@ -594,11 +596,12 @@ mod tests { if alef.is_empty() && bet.is_empty() { continue; }; + let _ = File::create(&format!("{target}/aalefx")).unwrap(); // This test diff is intentionally reversed. // We want it to turn the alef into bet. let diff = diff( &alef, - "a/alefx", + &format!("{target}/aalefx"), &bet, &format!("{target}/alefx"), 2, @@ -679,11 +682,12 @@ mod tests { if f != 2 { bet.write_all(b"f\n").unwrap(); } + let _ = File::create(&format!("{target}/aalefr")).unwrap(); // This test diff is intentionally reversed. // We want it to turn the alef into bet. let diff = diff( &alef, - "a/alefr", + &format!("{target}/aalefr"), &bet, &format!("{target}/alefr"), 2, @@ -720,9 +724,15 @@ mod tests { #[test] fn test_stop_early() { + use regex::Regex; + use std::fs::File; + use std::str; + let from_filename = "foo"; + let _ = File::create(&format!("foo")).unwrap(); let from = vec!["a", "b", "c", ""].join("\n"); let to_filename = "bar"; + let _ = File::create(&format!("bar")).unwrap(); let to = vec!["a", "d", "c", ""].join("\n"); let context_size: usize = 3; @@ -734,6 +744,11 @@ mod tests { context_size, false, ); + + let diff_full_text = str::from_utf8(&diff_full).unwrap(); + let re = Regex::new(r"\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+ [+-]\d{4}").unwrap(); + let diff_full = re.replace_all(diff_full_text, ""); + let expected_full = vec![ "*** foo\t", "--- bar\t", @@ -749,7 +764,7 @@ mod tests { "", ] .join("\n"); - assert_eq!(diff_full, expected_full.as_bytes()); + assert_eq!(diff_full, expected_full); let diff_brief = diff( from.as_bytes(), @@ -759,8 +774,12 @@ mod tests { context_size, true, ); + + let diff_brief_text = str::from_utf8(&diff_brief).unwrap(); + let re = Regex::new(r"\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+ [+-]\d{4}").unwrap(); + let diff_brief = re.replace_all(diff_brief_text, ""); let expected_brief = vec!["*** foo\t", "--- bar\t", ""].join("\n"); - assert_eq!(diff_brief, expected_brief.as_bytes()); + assert_eq!(diff_brief, expected_brief); let nodiff_full = diff( from.as_bytes(),