use docs_native_crdt::Editor; use serde_json::json; #[test] fn every_rule_delta_converges_with_remote_apply() { for fresh in [false, true] { let mut authority = Editor::new("rule-delta-convergence", 800); let remote = Editor::new("rule-delta-convergence", 900); let initial = authority.command(&json!({"op":"insert_element","at":0,"type":"paragraph"})).unwrap(); remote.apply(&initial).unwrap(); let mut source = Editor::new("rule-delta-convergence", 801); source.apply(&authority.snapshot()).unwrap(); for (index, command) in [ json!({"op":"display_edit","at":0,"length":0,"text":"-"}), json!({"op":"display_autoformat","at":0,"length":1,"kind":"bullet_list","level":0}), json!({"op":"display_revert_rule","at":0,"kind":"bullet_list","prior_type":"paragraph","prior_attrs":{},"text":"- "}), json!({"op":"display_edit","at":2,"length":0,"text":"Alpha"}), json!({"op":"display_edit","at":7,"length":0,"text":"\n"}), json!({"op":"display_edit","at":8,"length":0,"text":"Beta"}), ].iter().enumerate() { if fresh { source = Editor::new("rule-delta-convergence", 810 + index as u64); source.apply(&authority.snapshot()).unwrap(); } let delta = source.command(command).unwrap(); authority.apply_local(&delta).unwrap(); remote.apply(&delta).unwrap(); assert_eq!(authority.projection()["children"], remote.projection()["children"], "fresh={fresh}, step={index}, command={command}"); } } }