|
@@ -1,4 +1,4 @@
|
|
|
-use lib_ot::core::{DocumentTree, NodeData, TransactionBuilder};
|
|
|
+use lib_ot::core::{DocumentTree, NodeData, Position, TransactionBuilder};
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
#[test]
|
|
@@ -36,7 +36,7 @@ fn test_documents() {
|
|
|
}
|
|
|
|
|
|
#[test]
|
|
|
-fn test_transform_paths() {
|
|
|
+fn test_inserts_nodes() {
|
|
|
let mut document = DocumentTree::new();
|
|
|
let transaction = {
|
|
|
let mut tb = TransactionBuilder::new(&document);
|
|
@@ -54,3 +54,30 @@ fn test_transform_paths() {
|
|
|
};
|
|
|
document.apply(transaction);
|
|
|
}
|
|
|
+
|
|
|
+#[test]
|
|
|
+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.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.finalize()
|
|
|
+ };
|
|
|
+ document.apply(transaction);
|
|
|
+
|
|
|
+ let node = document.node_at_path(&Position(vec![1])).unwrap();
|
|
|
+ let node_data = document.arena.get(node).unwrap().get();
|
|
|
+ let is_bold = node_data.attributes.borrow().0.get("bolded").unwrap().clone();
|
|
|
+ assert_eq!(is_bold.unwrap(), "true");
|
|
|
+}
|