Fix Locator::from_index
Enhance language::tests::test_random_collaborators so that it checks buffer invariants. Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
e5faaeb2f2
commit
f9f75e98f8
4 changed files with 46 additions and 34 deletions
|
@ -602,36 +602,3 @@ fn test_random_concurrent_edits(mut rng: StdRng) {
|
|||
buffer.check_invariants();
|
||||
}
|
||||
}
|
||||
|
||||
impl Buffer {
|
||||
fn check_invariants(&self) {
|
||||
// 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 self.snapshot.fragments.items(&None) {
|
||||
assert!(fragment.id > prev_fragment_id);
|
||||
prev_fragment_id = fragment.id.clone();
|
||||
|
||||
let insertion_fragment = self
|
||||
.snapshot
|
||||
.insertions
|
||||
.get(
|
||||
&InsertionFragmentKey {
|
||||
timestamp: fragment.insertion_timestamp.local(),
|
||||
split_offset: fragment.insertion_offset,
|
||||
},
|
||||
&(),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(insertion_fragment.fragment_id, fragment.id);
|
||||
}
|
||||
|
||||
let mut cursor = self.snapshot.fragments.cursor::<Option<&Locator>>();
|
||||
for insertion_fragment in self.snapshot.insertions.cursor::<()>() {
|
||||
cursor.seek(&Some(&insertion_fragment.fragment_id), Bias::Left, &None);
|
||||
let fragment = cursor.item().unwrap();
|
||||
assert_eq!(insertion_fragment.fragment_id, fragment.id);
|
||||
assert_eq!(insertion_fragment.split_offset, fragment.insertion_offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue