mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-04 10:12:47 +00:00
Get randomized test passing on basic excerpt list features
Co-Authored-By: Max Brunsfeld <maxbrunsfeld@gmail.com>
This commit is contained in:
parent
4578938ea1
commit
88e3d87098
1 changed files with 21 additions and 20 deletions
|
@ -7,7 +7,7 @@ use std::{cmp, iter, ops::Range};
|
||||||
use sum_tree::{Bias, Cursor, SumTree};
|
use sum_tree::{Bias, Cursor, SumTree};
|
||||||
use text::{
|
use text::{
|
||||||
subscription::{Subscription, Topic},
|
subscription::{Subscription, Topic},
|
||||||
Anchor, AnchorRangeExt, Edit, Patch, TextSummary,
|
Anchor, AnchorRangeExt, Edit, TextSummary,
|
||||||
};
|
};
|
||||||
use theme::SyntaxTheme;
|
use theme::SyntaxTheme;
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ impl ExcerptList {
|
||||||
}
|
}
|
||||||
excerpts_to_edit.sort_unstable_by_key(|(excerpt_id, _)| *excerpt_id);
|
excerpts_to_edit.sort_unstable_by_key(|(excerpt_id, _)| *excerpt_id);
|
||||||
|
|
||||||
let mut patch = Patch::<usize>::default();
|
let mut edits = Vec::new();
|
||||||
let mut new_excerpts = SumTree::new();
|
let mut new_excerpts = SumTree::new();
|
||||||
let mut cursor = snapshot.excerpts.cursor::<(ExcerptId, usize)>();
|
let mut cursor = snapshot.excerpts.cursor::<(ExcerptId, usize)>();
|
||||||
|
|
||||||
|
@ -156,21 +156,22 @@ impl ExcerptList {
|
||||||
&(),
|
&(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let edits = buffer
|
edits.extend(
|
||||||
.edits_since_in_range::<usize>(
|
buffer
|
||||||
old_excerpt.buffer.version(),
|
.edits_since_in_range::<usize>(
|
||||||
old_excerpt.range.clone(),
|
old_excerpt.buffer.version(),
|
||||||
)
|
old_excerpt.range.clone(),
|
||||||
.map(|mut edit| {
|
)
|
||||||
let excerpt_old_start = cursor.start().1;
|
.map(|mut edit| {
|
||||||
let excerpt_new_start = new_excerpts.summary().text.bytes;
|
let excerpt_old_start = cursor.start().1;
|
||||||
edit.old.start += excerpt_old_start;
|
let excerpt_new_start = new_excerpts.summary().text.bytes;
|
||||||
edit.old.end += excerpt_old_start;
|
edit.old.start += excerpt_old_start;
|
||||||
edit.new.start += excerpt_new_start;
|
edit.old.end += excerpt_old_start;
|
||||||
edit.new.end += excerpt_new_start;
|
edit.new.start += excerpt_new_start;
|
||||||
edit
|
edit.new.end += excerpt_new_start;
|
||||||
});
|
edit
|
||||||
patch = patch.compose(edits);
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
cursor.next(&());
|
cursor.next(&());
|
||||||
}
|
}
|
||||||
|
@ -179,7 +180,7 @@ impl ExcerptList {
|
||||||
drop(cursor);
|
drop(cursor);
|
||||||
snapshot.excerpts = new_excerpts;
|
snapshot.excerpts = new_excerpts;
|
||||||
|
|
||||||
self.subscriptions.publish(&patch);
|
self.subscriptions.publish(edits);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,7 +383,7 @@ mod tests {
|
||||||
let buffer_1 = cx.add_model(|cx| Buffer::new(0, sample_text(6, 6, 'a'), cx));
|
let buffer_1 = cx.add_model(|cx| Buffer::new(0, sample_text(6, 6, 'a'), cx));
|
||||||
let buffer_2 = cx.add_model(|cx| Buffer::new(0, sample_text(6, 6, 'g'), cx));
|
let buffer_2 = cx.add_model(|cx| Buffer::new(0, sample_text(6, 6, 'g'), cx));
|
||||||
|
|
||||||
let list = cx.add_model(|cx| ExcerptList::new());
|
let list = cx.add_model(|_| ExcerptList::new());
|
||||||
|
|
||||||
let subscription = list.update(cx, |list, cx| {
|
let subscription = list.update(cx, |list, cx| {
|
||||||
let subscription = list.subscribe();
|
let subscription = list.subscribe();
|
||||||
|
@ -485,7 +486,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gpui::test(iterations = 100)]
|
#[gpui::test(iterations = 100)]
|
||||||
fn test_random(cx: &mut MutableAppContext, mut rng: StdRng) {
|
fn test_random_excerpts(cx: &mut MutableAppContext, mut rng: StdRng) {
|
||||||
let operations = env::var("OPERATIONS")
|
let operations = env::var("OPERATIONS")
|
||||||
.map(|i| i.parse().expect("invalid `OPERATIONS` variable"))
|
.map(|i| i.parse().expect("invalid `OPERATIONS` variable"))
|
||||||
.unwrap_or(10);
|
.unwrap_or(10);
|
||||||
|
|
Loading…
Reference in a new issue