diff --git a/pttodoest/src/main.rs b/pttodoest/src/main.rs index 57040c0..03ebf7f 100755 --- a/pttodoest/src/main.rs +++ b/pttodoest/src/main.rs @@ -316,6 +316,44 @@ mod test_file { tests::file_contains(&d, "plain", "[]"); }); } + + #[test] + fn test_file_deletion_to_persist() { + tests::with_dir(|d| { + tests::write_file(&d, "plain", "- initial\n- 1"); + tests::write_file( + &d, + ".plain.host_a", + r#" + {"ts":1, "patch":{"op":"replace", "path":"", "value": ["initial"]}} + {"ts":3, "patch":{"op":"add", "path":"/-", "value": {"k":"v"}}} + "#, + ); + tests::write_file( + &d, + ".plain.host_b", + r#" + {"ts":2, "patch":{"op":"add", "path":"/-", "value": 1}} + "#, + ); + + let f = File::new(&d.path().join("plain").to_str().unwrap().to_string()); + + assert_eq!(3, f.events().unwrap().0.len()); + assert_eq!(2, f.stage().unwrap().len()); + tests::file_contains(&d, "plain", "- initial\n- 1"); + + f.persist_stage().unwrap(); + assert_eq!(4, f.events().unwrap().0.len()); + assert_eq!(2, f.stage().unwrap().len()); + tests::file_contains(&d, "plain", "- initial\n- 1"); + + f.stage_persisted().unwrap(); + assert_eq!(4, f.events().unwrap().0.len()); + assert_eq!(2, f.stage().unwrap().len()); + tests::file_contains(&d, "plain", "- initial\n- 1"); + }); + } } #[derive(Debug, Clone, Serialize, Deserialize)]