MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / test_apply_replace

Function test_apply_replace

atomic-core/src/crdt/apply/leaf.rs:828–869  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

826
827 #[test]
828 fn test_apply_replace() {
829 let mut txn = MockTxn::new();
830 let mut context = ApplyContext::new(ApplyOptions::default());
831 let branch_id = create_test_branch(&mut txn, 1, 0);
832 let leaf_id = LeafId::new(NodeId::new(1), 0);
833
834 // Create first
835 let insert_op = LeafOp::Insert {
836 after: None,
837 kind: TokenKind::Word,
838 content: b"hello".to_vec(),
839 };
840 apply_leaf_op(
841 &mut txn,
842 &mut context,
843 branch_id,
844 leaf_id,
845 &insert_op,
846 b"hello",
847 )
848 .unwrap();
849
850 // Replace content
851 let replace_op = LeafOp::Replace {
852 leaf: leaf_id,
853 new_content: b"world".to_vec(),
854 };
855 apply_leaf_op(
856 &mut txn,
857 &mut context,
858 branch_id,
859 leaf_id,
860 &replace_op,
861 b"world",
862 )
863 .unwrap();
864
865 // Leaf should still exist with same ID
866 let leaf = txn.get_leaf(leaf_id).unwrap().unwrap();
867 assert!(leaf.state().is_alive());
868 assert_eq!(context.stats().leaves_replaced(), 1);
869 }
870
871 #[test]
872 fn test_apply_replace_not_found() {

Callers

nothing calls this directly

Calls 4

create_test_branchFunction · 0.85
apply_leaf_opFunction · 0.70
unwrapMethod · 0.45
get_leafMethod · 0.45

Tested by

no test coverage detected