| 1 | use docs_native_crdt::Editor; |
| 2 | use serde_json::json; |
| 3 | fn main() { |
| 4 | let destination = std::env::args().nth(1).expect("output directory"); |
| 5 | for fresh in [false, true] { |
| 6 | let directory = |
| 7 | std::path::Path::new(&destination).join(if fresh { "fresh" } else { "retained" }); |
| 8 | std::fs::create_dir_all(&directory).unwrap(); |
| 9 | let mut authority = Editor::new("rule-delta-convergence", 800); |
| 10 | let remote = Editor::new("rule-delta-convergence", 900); |
| 11 | let initial = authority |
| 12 | .command(&json!({"op":"insert_element","at":0,"type":"paragraph"})) |
| 13 | .unwrap(); |
| 14 | remote.apply(&initial).unwrap(); |
| 15 | std::fs::write(directory.join("0.bin"), &initial).unwrap(); |
| 16 | let mut source = Editor::new("rule-delta-convergence", 801); |
| 17 | source.apply(&authority.snapshot()).unwrap(); |
| 18 | for (index, command) in [ |
| 19 | json!({"op":"display_edit","at":0,"length":0,"text":"-"}), |
| 20 | json!({"op":"display_autoformat","at":0,"length":1,"kind":"bullet_list","level":0}), |
| 21 | json!({"op":"display_revert_rule","at":0,"kind":"bullet_list","prior_type":"paragraph","prior_attrs":{},"text":"- "}), |
| 22 | json!({"op":"display_edit","at":2,"length":0,"text":"Alpha"}), |
| 23 | json!({"op":"display_edit","at":7,"length":0,"text":"\n"}), |
| 24 | json!({"op":"display_edit","at":8,"length":0,"text":"Beta"}), |
| 25 | ].iter().enumerate() { |
| 26 | if fresh { source = Editor::new("rule-delta-convergence", 810 + index as u64); source.apply(&authority.snapshot()).unwrap(); } |
| 27 | let delta = source.command(command).unwrap(); |
| 28 | authority.apply_local(&delta).unwrap(); |
| 29 | remote.apply(&delta).unwrap(); |
| 30 | std::fs::write(directory.join(format!("{}.bin", index + 1)), &delta).unwrap(); |
| 31 | std::fs::write(directory.join(format!("{}.snapshot", index + 1)), authority.snapshot()).unwrap(); |
| 32 | } |
| 33 | std::fs::write( |
| 34 | directory.join("authority.json"), |
| 35 | authority.projection().to_string(), |
| 36 | ) |
| 37 | .unwrap(); |
| 38 | std::fs::write( |
| 39 | directory.join("remote.json"), |
| 40 | remote.projection().to_string(), |
| 41 | ) |
| 42 | .unwrap(); |
| 43 | std::fs::write(directory.join("remote.snapshot"), remote.snapshot()).unwrap(); |
| 44 | } |
| 45 | } |
| 46 | |