Skip to content

Commit 900e1c3

Browse files
Tests: Replace modification time in diff with "TIMESTAMP" placeholder
1 parent 0a77fe1 commit 900e1c3

4 files changed

Lines changed: 24 additions & 12 deletions

File tree

src/context_diff.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -749,8 +749,8 @@ mod tests {
749749
);
750750

751751
let expected_full = [
752-
"*** target/context-diff/foo\t",
753-
"--- target/context-diff/bar\t",
752+
"*** target/context-diff/foo\tTIMESTAMP",
753+
"--- target/context-diff/bar\tTIMESTAMP",
754754
"***************",
755755
"*** 1,3 ****",
756756
" a",
@@ -777,8 +777,8 @@ mod tests {
777777
);
778778

779779
let expected_brief = [
780-
"*** target/context-diff/foo\t",
781-
"--- target/context-diff/bar\t",
780+
"*** target/context-diff/foo\tTIMESTAMP",
781+
"--- target/context-diff/bar\tTIMESTAMP",
782782
"",
783783
]
784784
.join("\n");

src/macros.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
// asserts equality of the actual diff and expected diff
2+
// considering datetime varitations
3+
//
4+
// It replaces the modification time in the actual diff
5+
// with placeholer "TIMESTAMP" and then asserts the equality
6+
//
7+
// For eg.
8+
// let brief = "*** fruits_old.txt\t2024-03-24 23:43:05.189597645 +0530\n
9+
// --- fruits_new.txt\t2024-03-24 23:35:08.922581904 +0530\n";
10+
//
11+
// replaced = "*** fruits_old.txt\tTIMESTAMP\n
12+
// --- fruits_new.txt\tTIMESTAMP\n";
113
#[macro_export]
214
macro_rules! assert_diff_eq {
315
($actual:expr, $expected:expr) => {{
@@ -6,7 +18,7 @@ macro_rules! assert_diff_eq {
618

719
let diff = str::from_utf8(&$actual).unwrap();
820
let re = Regex::new(r"\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+ [+-]\d{4}").unwrap();
9-
let actual = re.replace_all(diff, "");
21+
let actual = re.replace_all(diff, "TIMESTAMP");
1022

1123
assert_eq!(actual, $expected);
1224
}};

src/unified_diff.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -903,8 +903,8 @@ mod tests {
903903
);
904904

905905
let expected_full = [
906-
"--- target/context-diff/foo\t",
907-
"+++ target/context-diff/bar\t",
906+
"--- target/context-diff/foo\tTIMESTAMP",
907+
"+++ target/context-diff/bar\tTIMESTAMP",
908908
"@@ -1,3 +1,3 @@",
909909
" a",
910910
"-b",
@@ -927,8 +927,8 @@ mod tests {
927927
);
928928

929929
let expected_brief = [
930-
"--- target/context-diff/foo\t",
931-
"+++ target/context-diff/bar\t",
930+
"--- target/context-diff/foo\tTIMESTAMP",
931+
"+++ target/context-diff/bar\tTIMESTAMP",
932932
"",
933933
]
934934
.join("\n");

tests/integration.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ fn read_from_stdin() -> Result<(), Box<dyn std::error::Error>> {
185185
assert_diff_eq!(
186186
output,
187187
format!(
188-
"--- {}\t\n+++ -\t\n@@ -1 +1 @@\n-foo\n+bar\n",
188+
"--- {}\tTIMESTAMP\n+++ -\tTIMESTAMP\n@@ -1 +1 @@\n-foo\n+bar\n",
189189
file1.path().to_string_lossy()
190190
)
191191
);
@@ -201,7 +201,7 @@ fn read_from_stdin() -> Result<(), Box<dyn std::error::Error>> {
201201
assert_diff_eq!(
202202
output,
203203
format!(
204-
"--- -\t\n+++ {}\t\n@@ -1 +1 @@\n-foo\n+bar\n",
204+
"--- -\tTIMESTAMP\n+++ {}\tTIMESTAMP\n@@ -1 +1 @@\n-foo\n+bar\n",
205205
file2.path().to_string_lossy()
206206
)
207207
);
@@ -226,7 +226,7 @@ fn read_from_stdin() -> Result<(), Box<dyn std::error::Error>> {
226226
assert_diff_eq!(
227227
output,
228228
format!(
229-
"--- {}\t\n+++ /dev/stdin\t\n@@ -1 +1 @@\n-foo\n+bar\n",
229+
"--- {}\tTIMESTAMP\n+++ /dev/stdin\tTIMESTAMP\n@@ -1 +1 @@\n-foo\n+bar\n",
230230
file1.path().to_string_lossy()
231231
)
232232
);

0 commit comments

Comments
 (0)