|
@@ -1,11 +1,15 @@
|
|
-use lib_ot::core::{NodeAttributes, NodeData, NodeTree, Path, TransactionBuilder};
|
|
|
|
|
|
+use lib_ot::core::{
|
|
|
|
+ NodeAttributes, NodeBody, NodeBodyChangeset, NodeData, NodeTree, Path, TextDelta, TransactionBuilder,
|
|
|
|
+};
|
|
|
|
|
|
pub enum NodeScript {
|
|
pub enum NodeScript {
|
|
InsertNode { path: Path, node: NodeData },
|
|
InsertNode { path: Path, node: NodeData },
|
|
- InsertAttributes { path: Path, attributes: NodeAttributes },
|
|
|
|
|
|
+ UpdateAttributes { path: Path, attributes: NodeAttributes },
|
|
|
|
+ UpdateBody { path: Path, changeset: NodeBodyChangeset },
|
|
DeleteNode { path: Path },
|
|
DeleteNode { path: Path },
|
|
AssertNumberOfChildrenAtPath { path: Option<Path>, len: usize },
|
|
AssertNumberOfChildrenAtPath { path: Option<Path>, len: usize },
|
|
AssertNode { path: Path, expected: Option<NodeData> },
|
|
AssertNode { path: Path, expected: Option<NodeData> },
|
|
|
|
+ AssertNodeDelta { path: Path, expected: TextDelta },
|
|
}
|
|
}
|
|
|
|
|
|
pub struct NodeTest {
|
|
pub struct NodeTest {
|
|
@@ -34,12 +38,19 @@ impl NodeTest {
|
|
|
|
|
|
self.node_tree.apply(transaction).unwrap();
|
|
self.node_tree.apply(transaction).unwrap();
|
|
}
|
|
}
|
|
- NodeScript::InsertAttributes { path, attributes } => {
|
|
|
|
|
|
+ NodeScript::UpdateAttributes { path, attributes } => {
|
|
let transaction = TransactionBuilder::new(&self.node_tree)
|
|
let transaction = TransactionBuilder::new(&self.node_tree)
|
|
.update_attributes_at_path(&path, attributes)
|
|
.update_attributes_at_path(&path, attributes)
|
|
.finalize();
|
|
.finalize();
|
|
self.node_tree.apply(transaction).unwrap();
|
|
self.node_tree.apply(transaction).unwrap();
|
|
}
|
|
}
|
|
|
|
+ NodeScript::UpdateBody { path, changeset } => {
|
|
|
|
+ //
|
|
|
|
+ let transaction = TransactionBuilder::new(&self.node_tree)
|
|
|
|
+ .update_body_at_path(&path, changeset)
|
|
|
|
+ .finalize();
|
|
|
|
+ self.node_tree.apply(transaction).unwrap();
|
|
|
|
+ }
|
|
NodeScript::DeleteNode { path } => {
|
|
NodeScript::DeleteNode { path } => {
|
|
let transaction = TransactionBuilder::new(&self.node_tree)
|
|
let transaction = TransactionBuilder::new(&self.node_tree)
|
|
.delete_node_at_path(&path)
|
|
.delete_node_at_path(&path)
|
|
@@ -47,7 +58,7 @@ impl NodeTest {
|
|
self.node_tree.apply(transaction).unwrap();
|
|
self.node_tree.apply(transaction).unwrap();
|
|
}
|
|
}
|
|
NodeScript::AssertNode { path, expected } => {
|
|
NodeScript::AssertNode { path, expected } => {
|
|
- let node_id = self.node_tree.node_at_path(path);
|
|
|
|
|
|
+ let node_id = self.node_tree.node_id_at_path(path);
|
|
|
|
|
|
match node_id {
|
|
match node_id {
|
|
None => assert!(node_id.is_none()),
|
|
None => assert!(node_id.is_none()),
|
|
@@ -66,11 +77,19 @@ impl NodeTest {
|
|
assert_eq!(len, expected_len)
|
|
assert_eq!(len, expected_len)
|
|
}
|
|
}
|
|
Some(path) => {
|
|
Some(path) => {
|
|
- let node_id = self.node_tree.node_at_path(path).unwrap();
|
|
|
|
|
|
+ let node_id = self.node_tree.node_id_at_path(path).unwrap();
|
|
let len = self.node_tree.number_of_children(Some(node_id));
|
|
let len = self.node_tree.number_of_children(Some(node_id));
|
|
assert_eq!(len, expected_len)
|
|
assert_eq!(len, expected_len)
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
+ NodeScript::AssertNodeDelta { path, expected } => {
|
|
|
|
+ let node = self.node_tree.get_node_at_path(&path).unwrap();
|
|
|
|
+ if let NodeBody::Delta(delta) = node.body.clone() {
|
|
|
|
+ debug_assert_eq!(delta, expected);
|
|
|
|
+ } else {
|
|
|
|
+ panic!("Node body type not match, expect Delta");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|