use docs_core::{fragment_html, fragment_json, fragment_text}; use yrs::updates::decoder::Decode; use yrs::{Doc, Options, Transact, Update, Xml, XmlFragment}; fn doc_from(bytes: &[u8]) -> Doc { let doc = Doc::with_options(Options::with_guid_and_client_id("fixture".into(), 1)); let update = Update::decode_v1(bytes).expect("decode fixture"); doc.transact_mut() .apply_update(update) .expect("apply fixture"); doc } #[test] fn reads_paragraphs_as_blocks() { let doc = doc_from(include_bytes!("../../fixtures/vectors/fragment/simple.bin")); assert_eq!(fragment_text(&doc), "First paragraph.\n\nSecond paragraph."); } #[test] fn renders_paragraphs_as_html() { let doc = doc_from(include_bytes!("../../fixtures/vectors/fragment/simple.bin")); assert_eq!( fragment_html(&doc), "
First paragraph.
Second paragraph.
" ); } #[test] fn renders_marks() { let doc = doc_from(include_bytes!("../../fixtures/vectors/fragment/marks.bin")); let html = fragment_html(&doc); assert!(html.contains("bold"), "got {html}"); assert!(html.contains("italic"), "got {html}"); } #[test] fn renders_headings_and_lists() { let doc = doc_from(include_bytes!("../../fixtures/vectors/fragment/nested.bin")); let html = fragment_html(&doc); assert_eq!( html, "One
Two