use std::path::Path;
use std::time::Duration;
#[derive(Debug, Clone)]
pub enum ReportEvent<'a> {
Progress {
current: usize,
total: usize,
path: &'a Path,
},
FileResult {
path: &'a Path,
outcome: FileOutcome,
duration: Duration,
},
Error {
path: Option<&'a Path>,
message: &'a str,
},
Warning {
message: &'a str,
},
Info {
message: &'a str,
},
Success {
message: &'a str,
},
Timing {
operation: &'a str,
duration: Duration,
},
BatchSummary {
total: usize,
formatted: usize,
unchanged: usize,
would_change: usize,
failed: usize,
duration: Duration,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FileOutcome {
Formatted,
Unchanged,
Skipped,
Failed,
}
#[cfg(test)]
mod tests {
use super::*;
use std::path::PathBuf;
#[test]
fn test_file_outcome_equality() {
assert_eq!(FileOutcome::Formatted, FileOutcome::Formatted);
assert_ne!(FileOutcome::Formatted, FileOutcome::Unchanged);
}
#[test]
fn test_report_event_creation() {
let path = PathBuf::from("test.yaml");
assert!(matches!(
ReportEvent::Progress {
current: 1,
total: 10,
path: &path,
},
ReportEvent::Progress { .. }
));
assert!(matches!(
ReportEvent::FileResult {
path: &path,
outcome: FileOutcome::Formatted,
duration: Duration::from_millis(100),
},
ReportEvent::FileResult { .. }
));
assert!(matches!(
ReportEvent::Error {
path: Some(&path),
message: "Test error",
},
ReportEvent::Error { .. }
));
assert!(matches!(
ReportEvent::Warning {
message: "Test warning",
},
ReportEvent::Warning { .. }
));
assert!(matches!(
ReportEvent::Info {
message: "Test info",
},
ReportEvent::Info { .. }
));
assert!(matches!(
ReportEvent::Success {
message: "Test success",
},
ReportEvent::Success { .. }
));
assert!(matches!(
ReportEvent::Timing {
operation: "parse",
duration: Duration::from_secs(1),
},
ReportEvent::Timing { .. }
));
assert!(matches!(
ReportEvent::BatchSummary {
total: 10,
formatted: 5,
unchanged: 3,
would_change: 1,
failed: 1,
duration: Duration::from_secs(5),
},
ReportEvent::BatchSummary { .. }
));
}
}