main.rs 956 B

1234567891011121314151617181920212223242526272829
  1. use std::collections::HashMap;
  2. use lib_ot::core::{DocumentTree, NodeData, Position, TransactionBuilder};
  3. #[test]
  4. fn main() {
  5. // Create a new arena
  6. let _document = DocumentTree::new();
  7. }
  8. #[test]
  9. fn test_documents() {
  10. let mut document = DocumentTree::new();
  11. let mut tb = TransactionBuilder::new(&document);
  12. tb.insert_nodes(&Position(vec![0]), &vec![NodeData::new("text")]);
  13. let transaction = tb.finalize();
  14. document.apply(transaction);
  15. assert!(document.node_at_path(&Position(vec![0])).is_some());
  16. let node = document.node_at_path(&Position(vec![0])).unwrap();
  17. let node_data = document.arena.get(node).unwrap().get();
  18. assert_eq!(node_data.node_type, "text");
  19. let mut tb = TransactionBuilder::new(&document);
  20. tb.update_attributes(&Position(vec![0]), HashMap::from([
  21. ("subtype".into(), Some("bullet-list".into())),
  22. ]));
  23. let transaction = tb.finalize();
  24. document.apply(transaction);
  25. }