test schedule can pass

master
Bel LaPointe 2025-11-12 14:44:35 -07:00
parent fa7b537106
commit c06091d576
1 changed files with 52 additions and 2 deletions

View File

@ -205,6 +205,11 @@ impl File {
for before in before.iter() {
if !after.contains(before) {
self.append(Delta::remove_at(before.clone(), now))?;
if let Some(due) = before.next_due(Delta::now_time()) {
if due >= Delta::now_time() {
self.append(Delta::add_at(before.clone(), due))?;
}
}
}
}
for after in after.iter() {
@ -422,7 +427,7 @@ mod test_file {
{{"ts":2, "op":"Add", "task": "old"}}
{{"ts":{}, "op":"Add", "task": "enqueued for persistence"}}
"#,
2147483647,
Delta::now_time() + 5,
)
.as_str(),
);
@ -453,6 +458,45 @@ mod test_file {
tests::file_contains(&d, "plain", "old");
});
}
#[test]
fn test_schedule_date_future() {
tests::with_dir(|d| {
tests::write_file(&d, "plain", "[]");
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());
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());
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());
});
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@ -714,7 +758,13 @@ impl Events {
let mut result = vec![];
for event in self.0.iter() {
match event.op {
Op::Add => result.push(event.task.clone()),
Op::Add => match event.task.next_due(event.ts) {
Some(next_due) => match next_due <= Delta::now_time() {
true => result.push(event.task.clone()),
false => {}
},
None => result.push(event.task.clone()),
},
Op::Remove => {
let mut i = (result.len() - 1) as i32;
while i >= 0 {