|
@@ -11,11 +11,10 @@ fn main() {
|
|
|
#[test]
|
|
|
fn test_documents() {
|
|
|
let mut document = DocumentTree::new();
|
|
|
- let transaction = {
|
|
|
- let mut tb = TransactionBuilder::new(&document);
|
|
|
- tb.insert_node_at_path(0, NodeSubTree::new("text"));
|
|
|
- tb.finalize()
|
|
|
- };
|
|
|
+ let transaction = TransactionBuilder::new(&document)
|
|
|
+ .insert_node_at_path(0, NodeSubTree::new("text"))
|
|
|
+ .finalize();
|
|
|
+
|
|
|
document.apply(transaction).unwrap();
|
|
|
|
|
|
assert!(document.node_at_path(0).is_some());
|
|
@@ -23,21 +22,17 @@ fn test_documents() {
|
|
|
let node_data = document.get_node_data(node).unwrap();
|
|
|
assert_eq!(node_data.node_type, "text");
|
|
|
|
|
|
- let transaction = {
|
|
|
- let mut tb = TransactionBuilder::new(&document);
|
|
|
- tb.update_attributes_at_path(
|
|
|
+ let transaction = TransactionBuilder::new(&document)
|
|
|
+ .update_attributes_at_path(
|
|
|
&vec![0].into(),
|
|
|
HashMap::from([("subtype".into(), Some("bullet-list".into()))]),
|
|
|
- );
|
|
|
- tb.finalize()
|
|
|
- };
|
|
|
+ )
|
|
|
+ .finalize();
|
|
|
document.apply(transaction).unwrap();
|
|
|
|
|
|
- let transaction = {
|
|
|
- let mut tb = TransactionBuilder::new(&document);
|
|
|
- tb.delete_node_at_path(&vec![0].into());
|
|
|
- tb.finalize()
|
|
|
- };
|
|
|
+ let transaction = TransactionBuilder::new(&document)
|
|
|
+ .delete_node_at_path(&vec![0].into())
|
|
|
+ .finalize();
|
|
|
document.apply(transaction).unwrap();
|
|
|
assert!(document.node_at_path(0).is_none());
|
|
|
}
|
|
@@ -45,29 +40,24 @@ fn test_documents() {
|
|
|
#[test]
|
|
|
fn test_inserts_nodes() {
|
|
|
let mut document = DocumentTree::new();
|
|
|
- let transaction = {
|
|
|
- let mut tb = TransactionBuilder::new(&document);
|
|
|
- tb.insert_node_at_path(0, NodeSubTree::new("text"));
|
|
|
- tb.insert_node_at_path(1, NodeSubTree::new("text"));
|
|
|
- tb.insert_node_at_path(2, NodeSubTree::new("text"));
|
|
|
- tb.finalize()
|
|
|
- };
|
|
|
+ let transaction = TransactionBuilder::new(&document)
|
|
|
+ .insert_node_at_path(0, NodeSubTree::new("text"))
|
|
|
+ .insert_node_at_path(1, NodeSubTree::new("text"))
|
|
|
+ .insert_node_at_path(2, NodeSubTree::new("text"))
|
|
|
+ .finalize();
|
|
|
document.apply(transaction).unwrap();
|
|
|
|
|
|
- let transaction = {
|
|
|
- let mut tb = TransactionBuilder::new(&document);
|
|
|
- tb.insert_node_at_path(1, NodeSubTree::new("text"));
|
|
|
- tb.finalize()
|
|
|
- };
|
|
|
+ let transaction = TransactionBuilder::new(&document)
|
|
|
+ .insert_node_at_path(1, NodeSubTree::new("text"))
|
|
|
+ .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_node_at_path(
|
|
|
+ let transaction = TransactionBuilder::new(&document)
|
|
|
+ .insert_node_at_path(
|
|
|
0,
|
|
|
NodeSubTree {
|
|
|
note_type: "text".into(),
|
|
@@ -75,9 +65,8 @@ fn test_inserts_subtrees() {
|
|
|
delta: None,
|
|
|
children: vec![NodeSubTree::new("image")],
|
|
|
},
|
|
|
- );
|
|
|
- tb.finalize()
|
|
|
- };
|
|
|
+ )
|
|
|
+ .finalize();
|
|
|
document.apply(transaction).unwrap();
|
|
|
|
|
|
let node = document.node_at_path(&Path(vec![0, 0])).unwrap();
|
|
@@ -88,20 +77,16 @@ fn test_inserts_subtrees() {
|
|
|
#[test]
|
|
|
fn test_update_nodes() {
|
|
|
let mut document = DocumentTree::new();
|
|
|
- let transaction = {
|
|
|
- let mut tb = TransactionBuilder::new(&document);
|
|
|
- tb.insert_node_at_path(&vec![0], NodeSubTree::new("text"));
|
|
|
- tb.insert_node_at_path(&vec![1], NodeSubTree::new("text"));
|
|
|
- tb.insert_node_at_path(vec![2], NodeSubTree::new("text"));
|
|
|
- tb.finalize()
|
|
|
- };
|
|
|
+ let transaction = TransactionBuilder::new(&document)
|
|
|
+ .insert_node_at_path(&vec![0], NodeSubTree::new("text"))
|
|
|
+ .insert_node_at_path(&vec![1], NodeSubTree::new("text"))
|
|
|
+ .insert_node_at_path(vec![2], NodeSubTree::new("text"))
|
|
|
+ .finalize();
|
|
|
document.apply(transaction).unwrap();
|
|
|
|
|
|
- let transaction = {
|
|
|
- let mut tb = TransactionBuilder::new(&document);
|
|
|
- tb.update_attributes_at_path(&vec![1].into(), HashMap::from([("bolded".into(), Some("true".into()))]));
|
|
|
- tb.finalize()
|
|
|
- };
|
|
|
+ let transaction = TransactionBuilder::new(&document)
|
|
|
+ .update_attributes_at_path(&vec![1].into(), HashMap::from([("bolded".into(), Some("true".into()))]))
|
|
|
+ .finalize();
|
|
|
document.apply(transaction).unwrap();
|
|
|
|
|
|
let node = document.node_at_path(&Path(vec![1])).unwrap();
|
|
@@ -113,20 +98,16 @@ fn test_update_nodes() {
|
|
|
#[test]
|
|
|
fn test_delete_nodes() {
|
|
|
let mut document = DocumentTree::new();
|
|
|
- let transaction = {
|
|
|
- let mut tb = TransactionBuilder::new(&document);
|
|
|
- tb.insert_node_at_path(0, NodeSubTree::new("text"));
|
|
|
- tb.insert_node_at_path(1, NodeSubTree::new("text"));
|
|
|
- tb.insert_node_at_path(2, NodeSubTree::new("text"));
|
|
|
- tb.finalize()
|
|
|
- };
|
|
|
+ let transaction = TransactionBuilder::new(&document)
|
|
|
+ .insert_node_at_path(0, NodeSubTree::new("text"))
|
|
|
+ .insert_node_at_path(1, NodeSubTree::new("text"))
|
|
|
+ .insert_node_at_path(2, NodeSubTree::new("text"))
|
|
|
+ .finalize();
|
|
|
document.apply(transaction).unwrap();
|
|
|
|
|
|
- let transaction = {
|
|
|
- let mut tb = TransactionBuilder::new(&document);
|
|
|
- tb.delete_node_at_path(&Path(vec![1]));
|
|
|
- tb.finalize()
|
|
|
- };
|
|
|
+ let transaction = TransactionBuilder::new(&document)
|
|
|
+ .delete_node_at_path(&Path(vec![1]))
|
|
|
+ .finalize();
|
|
|
document.apply(transaction).unwrap();
|
|
|
|
|
|
let len = document.number_of_children();
|
|
@@ -136,12 +117,10 @@ fn test_delete_nodes() {
|
|
|
#[test]
|
|
|
fn test_errors() {
|
|
|
let mut document = DocumentTree::new();
|
|
|
- let transaction = {
|
|
|
- let mut tb = TransactionBuilder::new(&document);
|
|
|
- tb.insert_node_at_path(0, NodeSubTree::new("text"));
|
|
|
- tb.insert_node_at_path(100, NodeSubTree::new("text"));
|
|
|
- tb.finalize()
|
|
|
- };
|
|
|
+ let transaction = TransactionBuilder::new(&document)
|
|
|
+ .insert_node_at_path(0, NodeSubTree::new("text"))
|
|
|
+ .insert_node_at_path(100, NodeSubTree::new("text"))
|
|
|
+ .finalize();
|
|
|
let result = document.apply(transaction);
|
|
|
assert_eq!(result.err().unwrap().code, OTErrorCode::PathNotFound);
|
|
|
}
|