Start on maintaining an insertions tree

I'm correctly assigning fragment ids to all fragments in the fragments tree, but I have a randomized test failure when making sure that the insertions tree matches the state of the fragments tree.
This commit is contained in:
Nathan Sobo 2021-12-08 22:05:13 -07:00
parent ec54010e3c
commit dd38eb1264
4 changed files with 140 additions and 68 deletions

View file

@ -51,7 +51,7 @@ fn test_random_edits(mut rng: StdRng) {
);
for _i in 0..operations {
let (old_ranges, new_text, _) = buffer.randomly_edit(&mut rng, 5);
let (old_ranges, new_text, _) = buffer.randomly_edit(&mut rng, 1);
for old_range in old_ranges.iter().rev() {
reference_string.replace_range(old_range.clone(), &new_text);
}
@ -78,6 +78,27 @@ fn test_random_edits(mut rng: StdRng) {
TextSummary::from(&reference_string[range])
);
// Ensure every fragment is ordered by locator in the fragment tree and corresponds
// to an insertion fragment in the insertions tree.
let mut prev_fragment_id = Locator::min();
for fragment in buffer.snapshot.fragments.items(&None) {
assert!(fragment.id > prev_fragment_id);
prev_fragment_id = fragment.id.clone();
let insertion_fragment = buffer
.snapshot
.insertions
.get(
&InsertionFragmentKey {
timestamp: fragment.insertion_timestamp,
split_offset: fragment.insertion_offset,
},
&(),
)
.unwrap();
assert_eq!(insertion_fragment.fragment_id, fragment.id);
}
if rng.gen_bool(0.3) {
buffer_versions.push((buffer.clone(), buffer.subscribe()));
}