operation_delta_test.rs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. use crate::node::script::NodeScript::{AssertNodeDelta, InsertNode, UpdateBody};
  2. use crate::node::script::{edit_node_delta, NodeTest};
  3. use lib_ot::core::NodeDataBuilder;
  4. use lib_ot::text_delta::DeltaTextOperationBuilder;
  5. #[test]
  6. fn operation_update_delta_test() {
  7. let mut test = NodeTest::new();
  8. let initial_delta = DeltaTextOperationBuilder::new().build();
  9. let new_delta = DeltaTextOperationBuilder::new()
  10. .retain(initial_delta.utf16_base_len)
  11. .insert("Hello, world")
  12. .build();
  13. let (changeset, expected) = edit_node_delta(&initial_delta, new_delta);
  14. let node = NodeDataBuilder::new("text").insert_delta(initial_delta.clone()).build();
  15. let scripts = vec![
  16. InsertNode {
  17. path: 0.into(),
  18. node_data: node,
  19. rev_id: 1,
  20. },
  21. UpdateBody {
  22. path: 0.into(),
  23. changeset: changeset.clone(),
  24. },
  25. AssertNodeDelta {
  26. path: 0.into(),
  27. expected,
  28. },
  29. UpdateBody {
  30. path: 0.into(),
  31. changeset: changeset.inverted(),
  32. },
  33. AssertNodeDelta {
  34. path: 0.into(),
  35. expected: initial_delta,
  36. },
  37. ];
  38. test.run_scripts(scripts);
  39. }