2022-08-18 12:15:34 +00:00
|
|
|
use std::collections::HashMap;
|
2022-08-19 04:04:43 +00:00
|
|
|
use lib_ot::core::{DocumentTree, NodeData, TransactionBuilder};
|
2021-12-15 15:01:50 +00:00
|
|
|
|
2022-08-16 08:25:52 +00:00
|
|
|
#[test]
|
|
|
|
fn main() {
|
|
|
|
// Create a new arena
|
|
|
|
let _document = DocumentTree::new();
|
|
|
|
}
|
2022-08-17 08:48:45 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_documents() {
|
2022-08-17 09:43:58 +00:00
|
|
|
let mut document = DocumentTree::new();
|
2022-08-18 09:49:20 +00:00
|
|
|
let mut tb = TransactionBuilder::new(&document);
|
2022-08-19 04:04:43 +00:00
|
|
|
tb.insert_nodes(&vec![0].into(), &vec![NodeData::new("text")]);
|
2022-08-18 12:15:34 +00:00
|
|
|
let transaction = tb.finalize();
|
|
|
|
document.apply(transaction);
|
|
|
|
|
2022-08-19 04:04:43 +00:00
|
|
|
assert!(document.node_at_path(&vec![0].into()).is_some());
|
|
|
|
let node = document.node_at_path(&vec![0].into()).unwrap();
|
2022-08-18 12:15:34 +00:00
|
|
|
let node_data = document.arena.get(node).unwrap().get();
|
|
|
|
assert_eq!(node_data.node_type, "text");
|
|
|
|
|
|
|
|
let mut tb = TransactionBuilder::new(&document);
|
2022-08-19 04:04:43 +00:00
|
|
|
tb.update_attributes(&vec![0].into(), HashMap::from([
|
2022-08-18 12:15:34 +00:00
|
|
|
("subtype".into(), Some("bullet-list".into())),
|
|
|
|
]));
|
2022-08-18 08:19:50 +00:00
|
|
|
let transaction = tb.finalize();
|
|
|
|
document.apply(transaction);
|
2022-08-19 04:04:43 +00:00
|
|
|
|
|
|
|
let mut tb = TransactionBuilder::new(&document);
|
|
|
|
tb.delete_node(&vec![0].into());
|
|
|
|
let transaction = tb.finalize();
|
|
|
|
document.apply(transaction);
|
|
|
|
assert!(document.node_at_path(&vec![0].into()).is_none());
|
2022-08-17 08:48:45 +00:00
|
|
|
}
|