AppFlowy/shared-lib/lib-ot/tests/node/operation_delta_test.rs
Nathan.fooo 6bb1c4e89c
feat: run rustfmt with custom defined fmt configuration (#1848)
* chore: update rustfmt

* chore: apply rustfmt format
2023-02-13 09:29:49 +08:00

44 lines
1.1 KiB
Rust

use crate::node::script::NodeScript::{AssertNodeDelta, InsertNode, UpdateBody};
use crate::node::script::{edit_node_delta, NodeTest};
use lib_ot::core::NodeDataBuilder;
use lib_ot::text_delta::DeltaTextOperationBuilder;
#[test]
fn operation_update_delta_test() {
let mut test = NodeTest::new();
let initial_delta = DeltaTextOperationBuilder::new().build();
let new_delta = DeltaTextOperationBuilder::new()
.retain(initial_delta.utf16_base_len)
.insert("Hello, world")
.build();
let (changeset, expected) = edit_node_delta(&initial_delta, new_delta);
let node = NodeDataBuilder::new("text")
.insert_delta(initial_delta.clone())
.build();
let scripts = vec![
InsertNode {
path: 0.into(),
node_data: node,
rev_id: 1,
},
UpdateBody {
path: 0.into(),
changeset: changeset.clone(),
},
AssertNodeDelta {
path: 0.into(),
expected,
},
UpdateBody {
path: 0.into(),
changeset: changeset.inverted(),
},
AssertNodeDelta {
path: 0.into(),
expected: initial_delta,
},
];
test.run_scripts(scripts);
}