From be632d3da36627e465a91b5bcc44395f09a63755 Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Tue, 11 Nov 2025 17:31:44 -0700 Subject: [PATCH] testing reveals the stage as source of truth IS angry --- pttodoest/src/main.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) 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)]