use super::semantic::Difference;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ComparisonKind {
DecodedTzif,
ZdumpBehaviour { lo: i32, hi: i32 },
}
#[derive(Debug, Clone)]
pub struct ZoneComparison {
pub zone: String,
pub kind: ComparisonKind,
pub differences: Vec<Difference>,
pub byte_identical: bool,
}
impl ZoneComparison {
pub fn is_match(&self) -> bool {
self.differences.is_empty()
}
pub fn summary(&self) -> String {
let label = match self.kind {
ComparisonKind::DecodedTzif => "decoded TZif match".to_string(),
ComparisonKind::ZdumpBehaviour { lo, hi } => {
format!("zdump behaviour match over {lo}..{hi}")
}
};
let mut s = String::new();
if self.is_match() {
s.push_str(&format!(
"{}: {label}{}",
self.zone,
if self.byte_identical {
" (byte-identical)"
} else {
""
}
));
} else {
let what = match self.kind {
ComparisonKind::DecodedTzif => "decoded-TZif",
ComparisonKind::ZdumpBehaviour { .. } => "zdump-behaviour",
};
s.push_str(&format!(
"{}: {} {what} difference(s):",
self.zone,
self.differences.len()
));
for d in &self.differences {
s.push_str(&format!(
"\n - {}: ours={:?} theirs={:?}",
d.what, d.ours, d.theirs
));
}
}
s
}
}