From 519e0a1019b9f74ce8a12773a47d613a05aecdf8 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 13 Nov 2026 03:34:43 +0000 Subject: changes: test what transactions never write against a document ready for it `what_transactions_never_write_is_refused` checked changes built on the insert against a document without the deletion the insert builds on. Such a change isn't ready, and nothing is asked of it: the honest insert passed for that reason, and the two crafted from it weren't refused. Each is checked now against a document that holds what it builds on. --- src/document/changes.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/document/changes.rs') diff --git a/src/document/changes.rs b/src/document/changes.rs index 5569995..1e674dc 100644 --- a/src/document/changes.rs +++ b/src/document/changes.rs @@ -1256,9 +1256,13 @@ mod tests { let delete = theirs.get_last_local_change().unwrap(); change(&mut theirs, |doc| doc.insert(&list, 0, "b").unwrap()); let insert = theirs.get_last_local_change().unwrap(); - for honest in [&delete, &insert] { + // The insert builds on the delete: checked against a document that holds it, + // or it isn't ready, and nothing is asked of it. + let mut with_delete = ours.clone(); + with_delete.apply_changes([delete.clone()]).unwrap(); + for (doc, honest) in [(&ours, &delete), (&with_delete, &insert)] { assert_eq!( - Written::default().check(&ours, honest, &honest.decode()), + Written::default().check(doc, honest, &honest.decode()), None ); } @@ -1273,12 +1277,13 @@ mod tests { let mark_end = crafted(&insert, |change| { change.operations[0].action = OpType::MarkEnd(false); }); - for crafted in [nothing_replaced, at_head, mark_end] { - assert!( - Written::default() - .check(&ours, &crafted, &crafted.decode()) - .is_some() - ); + for (doc, crafted) in [ + (&ours, nothing_replaced), + (&with_delete, at_head), + (&with_delete, mark_end), + ] { + let why = Written::default().check(doc, &crafted, &crafted.decode()); + assert!(why.is_some(), "{:?}", crafted.decode().operations[0]); } } -- cgit v1.3.1