2022-08-18 12:15:34 +00:00
|
|
|
use std::collections::HashMap;
|
2022-08-18 09:49:20 +00:00
|
|
|
use lib_ot::core::{DocumentTree, NodeData, Position, 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-18 12:15:34 +00:00
|
|
|
tb.insert_nodes(&Position(vec![0]), &vec![NodeData::new("text")]);
|
|
|
|
let transaction = tb.finalize();
|
|
|
|
document.apply(transaction);
|
|
|
|
|
|
|
|
assert!(document.node_at_path(&Position(vec![0])).is_some());
|
|
|
|
let node = document.node_at_path(&Position(vec![0])).unwrap();
|
|
|
|
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(&Position(vec![0]), HashMap::from([
|
|
|
|
("subtype".into(), Some("bullet-list".into())),
|
|
|
|
]));
|
2022-08-18 08:19:50 +00:00
|
|
|
let transaction = tb.finalize();
|
|
|
|
document.apply(transaction);
|
2022-08-17 08:48:45 +00:00
|
|
|
}
|