use docs_core::{ apply_update, edit::{edit, EditError}, fragment_json, initial::initialize, snapshot_bytes, }; use yrs::{Doc, Options, ReadTxn, Transact, XmlElementPrelim, XmlFragment}; fn doc(client: u64) -> Doc { Doc::with_options(Options::with_guid_and_client_id("edit".into(), client)) } type TestEdit<'a> = (u32, u32, Vec<(u8, &'a str)>); fn input(edits: &[TestEdit<'_>]) -> Vec { let mut out = (edits.len() as u32).to_be_bytes().to_vec(); for (index, delete, blocks) in edits { out.extend(index.to_be_bytes()); out.extend(delete.to_be_bytes()); out.extend((blocks.len() as u32).to_be_bytes()); for (level, text) in blocks { out.push(*level); out.extend((text.len() as u32).to_be_bytes()); out.extend(text.as_bytes()); } } out } fn seeded(client: u64) -> Doc { let source = doc(1); let mut raw = Vec::new(); for text in ["first", "second", "third"] { raw.push(0); raw.extend((text.len() as u32).to_be_bytes()); raw.extend(text.as_bytes()); } initialize(&source, &raw).unwrap(); let d = doc(client); apply_update(&d, &snapshot_bytes(&source)).unwrap(); d } #[test] fn splices_are_normal_updates_and_preserve_untouched_items() { let d = seeded(2); let before = snapshot_bytes(&d); let bytes = edit( &d, &input(&[(2, 1, vec![]), (1, 1, vec![(3, "