diffutilslib/macros.rs
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 placeholder "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";
13#[macro_export]
14macro_rules! assert_diff_eq {
15 ($actual:expr, $expected:expr) => {{
16 use regex::Regex;
17 use std::str;
18
19 let diff = str::from_utf8(&$actual).unwrap();
20 let re = Regex::new(r"\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+ [+-]\d{4}").unwrap();
21 let actual = re.replacen(diff, 2, "TIMESTAMP");
22
23 assert_eq!(actual, $expected);
24 }};
25}