oficina / docs Public

Clone
git clone https://amadan.net/oficina/docs

Plain git — no account needed to clone.

Download

Download this file

1use crate::tests::edit_traces::load_testing_data;
2use crate::{Doc, GetString, OffsetKind, Options, Text, Transact};
3use std::time::Instant;
4
5#[test]
6fn edit_trace_automerge() {
7 test_editing_trace("../assets/editing-traces/sequential_traces/automerge-paper.json.gz");
8}
9
10#[test]
11fn edit_trace_friendsforever() {
12 test_editing_trace("../assets/editing-traces/sequential_traces/friendsforever_flat.json.gz");
13}
14
15#[test]
16fn edit_trace_sephblog1() {
17 test_editing_trace("../assets/editing-traces/sequential_traces/seph-blog1.json.gz");
18}
19
20#[test]
21fn edit_trace_sveltecomponent() {
22 test_editing_trace("../assets/editing-traces/sequential_traces/sveltecomponent.json.gz");
23}
24
25#[test]
26fn edit_trace_rustcode() {
27 test_editing_trace("../assets/editing-traces/sequential_traces/rustcode.json.gz");
28}
29
30fn test_editing_trace(fpath: &str) {
31 let data = load_testing_data(fpath);
32 let doc = Doc::with_options(Options {
33 offset_kind: if data.using_byte_positions {
34 OffsetKind::Bytes
35 } else {
36 OffsetKind::Utf16
37 },
38 ..Options::default()
39 });
40 let txt = doc.get_or_insert_text("text");
41 let start = Instant::now();
42 for t in data.txns {
43 let mut txn = doc.transact_mut();
44 for patch in t.patches {
45 let at = patch.0;
46 let delete = patch.1;
47 let content = patch.2;
48
49 if delete != 0 {
50 txt.remove_range(&mut txn, at as u32, delete as u32);
51 }
52 if !content.is_empty() {
53 txt.insert(&mut txn, at as u32, &content);
54 }
55 }
56 }
57 let finish = Instant::now();
58 println!("elapsed: {}ms", (finish - start).as_millis());
59 assert_eq!(txt.get_string(&doc.transact()), data.end_content);
60}
61