|
@@ -10,9 +10,11 @@ fn main() {
|
|
|
#[test]
|
|
|
fn test_documents() {
|
|
|
let mut document = DocumentTree::new();
|
|
|
- let mut tb = TransactionBuilder::new(&document);
|
|
|
- tb.insert_nodes(&vec![0].into(), &vec![NodeData::new("text")]);
|
|
|
- let transaction = tb.finalize();
|
|
|
+ let transaction = {
|
|
|
+ let mut tb = TransactionBuilder::new(&document);
|
|
|
+ tb.insert_nodes_at_path(&vec![0].into(), &vec![NodeData::new("text")]);
|
|
|
+ tb.finalize()
|
|
|
+ };
|
|
|
document.apply(transaction);
|
|
|
|
|
|
assert!(document.node_at_path(&vec![0].into()).is_some());
|
|
@@ -20,17 +22,21 @@ fn test_documents() {
|
|
|
let node_data = document.arena.get(node).unwrap().get();
|
|
|
assert_eq!(node_data.node_type, "text");
|
|
|
|
|
|
- let mut tb = TransactionBuilder::new(&document);
|
|
|
- tb.update_attributes(
|
|
|
- &vec![0].into(),
|
|
|
- HashMap::from([("subtype".into(), Some("bullet-list".into()))]),
|
|
|
- );
|
|
|
- let transaction = tb.finalize();
|
|
|
+ let transaction = {
|
|
|
+ let mut tb = TransactionBuilder::new(&document);
|
|
|
+ tb.update_attributes_at_path(
|
|
|
+ &vec![0].into(),
|
|
|
+ HashMap::from([("subtype".into(), Some("bullet-list".into()))]),
|
|
|
+ );
|
|
|
+ tb.finalize()
|
|
|
+ };
|
|
|
document.apply(transaction);
|
|
|
|
|
|
- let mut tb = TransactionBuilder::new(&document);
|
|
|
- tb.delete_node(&vec![0].into());
|
|
|
- let transaction = tb.finalize();
|
|
|
+ let transaction = {
|
|
|
+ let mut tb = TransactionBuilder::new(&document);
|
|
|
+ tb.delete_node_at_path(&vec![0].into());
|
|
|
+ tb.finalize()
|
|
|
+ };
|
|
|
document.apply(transaction);
|
|
|
assert!(document.node_at_path(&vec![0].into()).is_none());
|
|
|
}
|
|
@@ -40,16 +46,16 @@ fn test_inserts_nodes() {
|
|
|
let mut document = DocumentTree::new();
|
|
|
let transaction = {
|
|
|
let mut tb = TransactionBuilder::new(&document);
|
|
|
- tb.insert_nodes(&vec![0].into(), &vec![NodeData::new("text")]);
|
|
|
- tb.insert_nodes(&vec![1].into(), &vec![NodeData::new("text")]);
|
|
|
- tb.insert_nodes(&vec![2].into(), &vec![NodeData::new("text")]);
|
|
|
+ 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.finalize()
|
|
|
};
|
|
|
document.apply(transaction);
|
|
|
|
|
|
let transaction = {
|
|
|
let mut tb = TransactionBuilder::new(&document);
|
|
|
- tb.insert_nodes(&vec![1].into(), &vec![NodeData::new("text")]);
|
|
|
+ tb.insert_nodes_at_path(&vec![1].into(), &vec![NodeData::new("text")]);
|
|
|
tb.finalize()
|
|
|
};
|
|
|
document.apply(transaction);
|
|
@@ -60,18 +66,16 @@ fn test_update_nodes() {
|
|
|
let mut document = DocumentTree::new();
|
|
|
let transaction = {
|
|
|
let mut tb = TransactionBuilder::new(&document);
|
|
|
- tb.insert_nodes(&vec![0].into(), &vec![NodeData::new("text")]);
|
|
|
- tb.insert_nodes(&vec![1].into(), &vec![NodeData::new("text")]);
|
|
|
- tb.insert_nodes(&vec![2].into(), &vec![NodeData::new("text")]);
|
|
|
+ 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.finalize()
|
|
|
};
|
|
|
document.apply(transaction);
|
|
|
|
|
|
let transaction = {
|
|
|
let mut tb = TransactionBuilder::new(&document);
|
|
|
- tb.update_attributes(&vec![1].into(), HashMap::from([
|
|
|
- ("bolded".into(), Some("true".into())),
|
|
|
- ]));
|
|
|
+ tb.update_attributes_at_path(&vec![1].into(), HashMap::from([("bolded".into(), Some("true".into()))]));
|
|
|
tb.finalize()
|
|
|
};
|
|
|
document.apply(transaction);
|
|
@@ -81,3 +85,26 @@ fn test_update_nodes() {
|
|
|
let is_bold = node_data.attributes.borrow().0.get("bolded").unwrap().clone();
|
|
|
assert_eq!(is_bold.unwrap(), "true");
|
|
|
}
|
|
|
+
|
|
|
+#[test]
|
|
|
+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.finalize()
|
|
|
+ };
|
|
|
+ document.apply(transaction);
|
|
|
+
|
|
|
+ let transaction = {
|
|
|
+ let mut tb = TransactionBuilder::new(&document);
|
|
|
+ tb.delete_node_at_path(&Position(vec![1]));
|
|
|
+ tb.finalize()
|
|
|
+ };
|
|
|
+ document.apply(transaction);
|
|
|
+
|
|
|
+ let len = document.root.children(&document.arena).fold(0, |count, _| count + 1);
|
|
|
+ assert_eq!(len, 2);
|
|
|
+}
|