From 71d327163e52633cd4eb4e269fda88008d59a549 Mon Sep 17 00:00:00 2001 From: asmodeus-oos Date: Tue, 13 Oct 2026 15:28:25 +0300 Subject: [PATCH] test: end-of-document citation stays closed through typing and reload (probes #898, not reproducible) --- crates/zotero/src/tests.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/crates/zotero/src/tests.rs b/crates/zotero/src/tests.rs index 4a8d5810e..394480719 100644 --- a/crates/zotero/src/tests.rs +++ b/crates/zotero/src/tests.rs @@ -546,3 +546,25 @@ fn a_new_field_is_never_empty_so_zotero_keeps_a_new_bibliography() { z.ok("Document_complete", json!([1])); assert_eq!(z.text(), "Text. Doe, J. (2020)."); } + +#[test] +fn citation_at_document_end_stays_closed() { + // #898: citing at the very end, typing after it, saving and reloading must all keep + // the field's end marker in place. + let mut z = Z::new("Hello", 5); + z.begin(); + let id = z.cite(0, r"{\rtf (Doe, {\i{}2020})}"); + z.ok("Document_complete", json!([1])); + // Type right after the citation, at the very end of the document. + z.s.run("text.insert", &json!({"text": "!"}).into()).unwrap(); + assert_eq!(z.text(), "Hello (Doe, 2020)!"); + let ranges = z.s.doc.field_ranges(StoryRef::Body); + assert_eq!(ranges.len(), 1); + assert!(z.s.sel.focus.off > ranges[0].end.off, "typed text lands outside the field"); + let f = z.ok("Document_getFields", json!([1, "ReferenceMark"])); + assert_eq!(f, json!([[id], [CITE], [0]])); + // Save and reload: the end marker must survive the round trip. + let bytes = wordcraft_engine::io::save_bytes("probe.docx", &z.s.doc).unwrap(); + let back = wordcraft_engine::io::open_bytes("probe.docx", &bytes).unwrap(); + assert_eq!(back.field_ranges(StoryRef::Body).len(), 1); +}