|
@@ -1,4 +1,4 @@
|
|
|
-use lib_ot::core::{DocumentTree, NodeData, Position, TransactionBuilder};
|
|
|
+use lib_ot::core::{DocumentTree, NodeAttributes, NodeSubTree, Position, TransactionBuilder};
|
|
|
use lib_ot::errors::OTErrorCode;
|
|
|
use std::collections::HashMap;
|
|
|
|
|
@@ -13,7 +13,7 @@ fn test_documents() {
|
|
|
let mut document = DocumentTree::new();
|
|
|
let transaction = {
|
|
|
let mut tb = TransactionBuilder::new(&document);
|
|
|
- tb.insert_nodes_at_path(&vec![0].into(), &vec![NodeData::new("text")]);
|
|
|
+ tb.insert_nodes_at_path(&vec![0].into(), &vec![Box::new(NodeSubTree::new("text"))]);
|
|
|
tb.finalize()
|
|
|
};
|
|
|
document.apply(transaction).unwrap();
|
|
@@ -47,29 +47,52 @@ fn test_inserts_nodes() {
|
|
|
let mut document = DocumentTree::new();
|
|
|
let transaction = {
|
|
|
let mut tb = TransactionBuilder::new(&document);
|
|
|
- tb.insert_nodes_at_path(&vec![0].into(), &vec![NodeData::new("text")]);
|
|
|
- tb.insert_nodes_at_path(&vec![1].into(), &vec![NodeData::new("text")]);
|
|
|
- tb.insert_nodes_at_path(&vec![2].into(), &vec![NodeData::new("text")]);
|
|
|
+ tb.insert_nodes_at_path(&vec![0].into(), &vec![Box::new(NodeSubTree::new("text"))]);
|
|
|
+ tb.insert_nodes_at_path(&vec![1].into(), &vec![Box::new(NodeSubTree::new("text"))]);
|
|
|
+ tb.insert_nodes_at_path(&vec![2].into(), &vec![Box::new(NodeSubTree::new("text"))]);
|
|
|
tb.finalize()
|
|
|
};
|
|
|
document.apply(transaction).unwrap();
|
|
|
|
|
|
let transaction = {
|
|
|
let mut tb = TransactionBuilder::new(&document);
|
|
|
- tb.insert_nodes_at_path(&vec![1].into(), &vec![NodeData::new("text")]);
|
|
|
+ tb.insert_nodes_at_path(&vec![1].into(), &vec![Box::new(NodeSubTree::new("text"))]);
|
|
|
tb.finalize()
|
|
|
};
|
|
|
document.apply(transaction).unwrap();
|
|
|
}
|
|
|
|
|
|
+#[test]
|
|
|
+fn test_inserts_subtrees() {
|
|
|
+ let mut document = DocumentTree::new();
|
|
|
+ let transaction = {
|
|
|
+ let mut tb = TransactionBuilder::new(&document);
|
|
|
+ tb.insert_nodes_at_path(
|
|
|
+ &vec![0].into(),
|
|
|
+ &vec![Box::new(NodeSubTree {
|
|
|
+ node_type: "text".into(),
|
|
|
+ attributes: NodeAttributes::new(),
|
|
|
+ delta: None,
|
|
|
+ children: vec![Box::new(NodeSubTree::new("image".into()))],
|
|
|
+ })],
|
|
|
+ );
|
|
|
+ tb.finalize()
|
|
|
+ };
|
|
|
+ document.apply(transaction).unwrap();
|
|
|
+
|
|
|
+ let node = document.node_at_path(&Position(vec![0, 0])).unwrap();
|
|
|
+ let data = document.arena.get(node).unwrap().get();
|
|
|
+ assert_eq!(data.node_type, "image");
|
|
|
+}
|
|
|
+
|
|
|
#[test]
|
|
|
fn test_update_nodes() {
|
|
|
let mut document = DocumentTree::new();
|
|
|
let transaction = {
|
|
|
let mut tb = TransactionBuilder::new(&document);
|
|
|
- tb.insert_nodes_at_path(&vec![0].into(), &vec![NodeData::new("text")]);
|
|
|
- tb.insert_nodes_at_path(&vec![1].into(), &vec![NodeData::new("text")]);
|
|
|
- tb.insert_nodes_at_path(&vec![2].into(), &vec![NodeData::new("text")]);
|
|
|
+ tb.insert_nodes_at_path(&vec![0].into(), &vec![Box::new(NodeSubTree::new("text"))]);
|
|
|
+ tb.insert_nodes_at_path(&vec![1].into(), &vec![Box::new(NodeSubTree::new("text"))]);
|
|
|
+ tb.insert_nodes_at_path(&vec![2].into(), &vec![Box::new(NodeSubTree::new("text"))]);
|
|
|
tb.finalize()
|
|
|
};
|
|
|
document.apply(transaction).unwrap();
|
|
@@ -92,9 +115,9 @@ fn test_delete_nodes() {
|
|
|
let mut document = DocumentTree::new();
|
|
|
let transaction = {
|
|
|
let mut tb = TransactionBuilder::new(&document);
|
|
|
- tb.insert_nodes_at_path(&vec![0].into(), &vec![NodeData::new("text")]);
|
|
|
- tb.insert_nodes_at_path(&vec![1].into(), &vec![NodeData::new("text")]);
|
|
|
- tb.insert_nodes_at_path(&vec![2].into(), &vec![NodeData::new("text")]);
|
|
|
+ tb.insert_nodes_at_path(&vec![0].into(), &vec![Box::new(NodeSubTree::new("text"))]);
|
|
|
+ tb.insert_nodes_at_path(&vec![1].into(), &vec![Box::new(NodeSubTree::new("text"))]);
|
|
|
+ tb.insert_nodes_at_path(&vec![2].into(), &vec![Box::new(NodeSubTree::new("text"))]);
|
|
|
tb.finalize()
|
|
|
};
|
|
|
document.apply(transaction).unwrap();
|
|
@@ -115,8 +138,8 @@ fn test_errors() {
|
|
|
let mut document = DocumentTree::new();
|
|
|
let transaction = {
|
|
|
let mut tb = TransactionBuilder::new(&document);
|
|
|
- tb.insert_nodes_at_path(&vec![0].into(), &vec![NodeData::new("text")]);
|
|
|
- tb.insert_nodes_at_path(&vec![100].into(), &vec![NodeData::new("text")]);
|
|
|
+ tb.insert_nodes_at_path(&vec![0].into(), &vec![Box::new(NodeSubTree::new("text"))]);
|
|
|
+ tb.insert_nodes_at_path(&vec![100].into(), &vec![Box::new(NodeSubTree::new("text"))]);
|
|
|
tb.finalize()
|
|
|
};
|
|
|
let result = document.apply(transaction);
|