From 7da6aa8ae97b83667c242ae31ad618eb80b9af97 Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Tue, 2 Dec 2025 17:17:31 -0700 Subject: [PATCH] still unsure about triggered vs snapshot time... --- pttodoest/src/main.rs | 100 ++++++++++++------------------------------ 1 file changed, 27 insertions(+), 73 deletions(-) diff --git a/pttodoest/src/main.rs b/pttodoest/src/main.rs index 7c4aad6..6a365b9 100755 --- a/pttodoest/src/main.rs +++ b/pttodoest/src/main.rs @@ -354,12 +354,7 @@ mod test_file { "{:?}", f.events().unwrap().snapshot().unwrap(), ); - assert_eq!( - 8, - f.events().unwrap().0.len(), - "{:?}", - f.events().unwrap().0 - ); + assert_eq!(8, f.events().unwrap().0.len(), "{:?}", f.events().unwrap()); assert_eq!(0, f.stage().unwrap().len(), "{:?}", f.stage().unwrap()); tests::file_contains(&d, "plain", "[]"); }); @@ -443,12 +438,7 @@ mod test_file { tests::file_contains(&d, "plain", "new"); f.stage_persisted().unwrap(); - assert_eq!( - 8, - f.events().unwrap().0.len(), - "{:?}", - f.events().unwrap().0 - ); + assert_eq!(8, f.events().unwrap().0.len(), "{:?}", f.events().unwrap()); assert_eq!(3, f.stage().unwrap().len(), "{:?}", f.stage().unwrap()); tests::file_contains(&d, "plain", "new"); tests::file_contains(&d, "plain", "old"); @@ -467,30 +457,15 @@ mod test_file { let task = Task(serde_yaml::Value::Mapping(m)); f.append(Delta::add(task)).unwrap(); - assert_eq!( - 1, - f.events().unwrap().0.len(), - "{:?}", - f.events().unwrap().0 - ); + assert_eq!(1, f.events().unwrap().0.len(), "{:?}", f.events().unwrap()); assert_eq!(0, f.stage().unwrap().len(), "{:?}", f.stage()); f.persist_stage().unwrap(); - assert_eq!( - 1, - f.events().unwrap().0.len(), - "{:?}", - f.events().unwrap().0 - ); + assert_eq!(1, f.events().unwrap().0.len(), "{:?}", f.events().unwrap()); assert_eq!(0, f.stage().unwrap().len(), "{:?}", f.stage()); f.stage_persisted().unwrap(); - assert_eq!( - 1, - f.events().unwrap().0.len(), - "{:?}", - f.events().unwrap().0 - ); + assert_eq!(1, f.events().unwrap().0.len(), "{:?}", f.events().unwrap()); assert_eq!(0, f.stage().unwrap().len(), "{:?}", f.stage()); }); } @@ -504,45 +479,24 @@ mod test_file { ".plain.host", format!( r#" - {{"ts":1, "op":"Add", "task": "stage"}} - {{"ts":2, "op":"Snapshot", "task": null, "tasks": ["removed", "old"]}} + {{"ts":3, "op":"Add", "task": "scheduled add for after snapshot"}} + {{"ts":2, "op":"Snapshot", "task": null, "tasks": ["removed"]}} "#, - //Delta::now_time() + 50, ) .as_str(), ); let f = File::new(&d.path().join("plain").to_str().unwrap().to_string()); - let mut m = serde_yaml::Mapping::new(); - m.insert("schedule".into(), "2036-01-02".into()); - let task = Task(serde_yaml::Value::Mapping(m)); - - f.append(Delta::add(task)).unwrap(); - assert_eq!( - 1, - f.events().unwrap().0.len(), - "{:?}", - f.events().unwrap().0 - ); - assert_eq!(0, f.stage().unwrap().len(), "{:?}", f.stage()); + assert_eq!(2, f.events().unwrap().0.len(), "{:?}", f.events().unwrap()); + assert_eq!(1, f.stage().unwrap().len(), "{:?}", f.stage()); f.persist_stage().unwrap(); - assert_eq!( - 1, - f.events().unwrap().0.len(), - "{:?}", - f.events().unwrap().0 - ); - assert_eq!(0, f.stage().unwrap().len(), "{:?}", f.stage()); + assert_eq!(4, f.events().unwrap().0.len(), "{:?}", f.events().unwrap()); + assert_eq!(1, f.stage().unwrap().len(), "{:?}", f.stage()); f.stage_persisted().unwrap(); - assert_eq!( - 1, - f.events().unwrap().0.len(), - "{:?}", - f.events().unwrap().0 - ); - assert_eq!(0, f.stage().unwrap().len(), "{:?}", f.stage()); + assert_eq!(5, f.events().unwrap().0.len(), "{:?}", f.events().unwrap()); + assert_eq!(2, f.stage().unwrap().len(), "{:?}", f.stage()); }); } @@ -557,12 +511,7 @@ mod test_file { let task = Task(serde_yaml::Value::Mapping(m)); f.append(Delta::add(task)).unwrap(); - assert_eq!( - 1, - f.events().unwrap().0.len(), - "{:?}", - f.events().unwrap().0 - ); + assert_eq!(1, f.events().unwrap().0.len(), "{:?}", f.events().unwrap()); assert_eq!(0, f.stage().unwrap().len(), "{:?}", f.stage()); f.persist_stage().unwrap(); @@ -570,7 +519,7 @@ mod test_file { 1, f.events().unwrap().0.len(), "events after 1 add scheduled: {:?}", - f.events().unwrap().0 + f.events().unwrap() ); assert_eq!( 1, @@ -587,12 +536,7 @@ mod test_file { ); f.stage_persisted().unwrap(); - assert_eq!( - 2, - f.events().unwrap().0.len(), - "{:?}", - f.events().unwrap().0 - ); + assert_eq!(2, f.events().unwrap().0.len(), "{:?}", f.events().unwrap()); assert_eq!(1, f.stage().unwrap().len(), "{:?}", f.stage()); }); } @@ -801,9 +745,19 @@ mod test_task { } } -#[derive(Debug, Clone)] +#[derive(Clone)] struct Events(Vec); +impl std::fmt::Debug for Events { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let mut arr = vec![]; + for i in self.0.iter() { + arr.push(format!("{:?}", i.clone())); + } + write!(f, "[\n {}\n]", arr.join("\n ")) + } +} + impl Events { pub fn new(file: &String) -> Result { let logs = match std::fs::read_dir(Self::dir(&file)) {