Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/zipper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1999,7 +1999,7 @@ pub(crate) mod read_zipper_core {
PathMap::new_with_root_in(root_node, root_val, self.alloc.clone())
}
fn get_trie_ref(&self) -> TrieRef<'_, V, A> {
TrieRefBorrowed::new_with_key_and_path_in(self.focus_parent_borrowed(), || self.val(), self.node_key(), b"", self.alloc.clone()).into()
TrieRefBorrowed::new_with_key_and_path_in(self.focus_parent(), || self.val(), self.node_key(), b"", self.alloc.clone()).into()
}
fn get_focus(&self) -> OpaqueAbstractNodeRef<'_, V, A> {
self.get_focus_at([])
Expand Down
22 changes: 22 additions & 0 deletions src/zipper_head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1523,6 +1523,28 @@ mod tests {
assert_eq!(paths, vec![b"ax".to_vec(), b"bx".to_vec(), b"c".to_vec(), b"dx".to_vec()]);
}

/// `get_trie_ref`, `get_focus` and forks from a head's read zipper, which owns its root node
#[test]
fn head_read_zipper_trie_refs() {
let mut map = PathMap::<u64>::new();
for p in [&[1u8, 2, 1][..], &[1, 2, 1, 0], &[1, 3], &[0]] { map.set_val_at(p, 7); }
let zh = map.zipper_head();
for path in [&[][..], &[1u8], &[1u8, 2], &[9u8]] {
let mut rz = zh.read_zipper_at_path(path).unwrap();
for step in [&[][..], &[2u8], &[2u8, 1]] {
rz.reset();
rz.descend_to(step);
let tr = rz.get_trie_ref();
assert_eq!(tr.val(), rz.val(), "{path:?} {step:?}");
assert_eq!(tr.child_mask(), rz.child_mask(), "{path:?} {step:?}");
let _ = rz.get_focus();
let fork = rz.fork_read_zipper();
assert_eq!(fork.get_trie_ref().val(), rz.val(), "{path:?} {step:?}");
assert_eq!(fork.trie_ref_at_path(&[0u8]).val(), rz.val_at(&[0u8]), "{path:?} {step:?}");
}
}
}

/// A `ZipperHead` from a write zipper made with a borrowed path, and the zipper used afterwards
#[test]
fn zipper_head_from_write_zipper_at_borrowed_path() {
Expand Down