diff --git a/.cargo/mutants.toml b/.cargo/mutants.toml index f792efc3..4377544d 100644 --- a/.cargo/mutants.toml +++ b/.cargo/mutants.toml @@ -10,6 +10,7 @@ examine_globs = [ "src/blockdir.rs", "src/blockhash.rs", "src/bin/conserve.rs", + "src/counters.rs", "src/jsonio.rs", "src/restore.rs", "src/transport.rs", diff --git a/src/counters.rs b/src/counters.rs index 2f60060e..b9f64445 100644 --- a/src/counters.rs +++ b/src/counters.rs @@ -80,3 +80,44 @@ impl Debug for Counters { s.finish() } } + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn simple_counts() { + let counters = Counters::default(); + counters.count(Counter::Files, 1); + counters.count(Counter::Files, 2); + counters.set(Counter::FileBytes, 100); + assert_eq!(counters.get(Counter::Files), 3); + assert_eq!(counters.get(Counter::Dirs), 0); + assert_eq!(counters.get(Counter::FileBytes), 100); + } + + #[test] + fn iter_counters() { + let counters = Counters::default(); + counters.count(Counter::Files, 2); + dbg!(&counters); + + counters.iter().for_each(|(c, v)| { + assert_eq!(counters.get(c), v); + }); + assert_eq!(counters.iter().count(), Counter::COUNT); + assert!(counters + .iter() + .all(|(c, v)| (c == Counter::Files) == (v == 2))); + } + + #[test] + fn debug_form() { + let counters = Counters::default(); + counters.count(Counter::Files, 2); + let d = format!("{counters:#?}"); + println!("{}", d); + assert!(d.contains("Files: 2")); + assert!(d.contains("Dirs: 0")); + } +}