Allow specifying MAX_EXCERPTS
via an env variable in random tests
This commit is contained in:
parent
3e2f684545
commit
ec39c9d335
7 changed files with 12 additions and 7 deletions
|
@ -3,7 +3,7 @@ use std::{cmp, sync::Arc};
|
||||||
use editor::{
|
use editor::{
|
||||||
diagnostic_block_renderer, diagnostic_style,
|
diagnostic_block_renderer, diagnostic_style,
|
||||||
display_map::{BlockDisposition, BlockProperties},
|
display_map::{BlockDisposition, BlockProperties},
|
||||||
Anchor, Editor, ExcerptProperties, MultiBuffer,
|
Editor, ExcerptProperties, MultiBuffer,
|
||||||
};
|
};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
action, elements::*, keymap::Binding, AppContext, Entity, ModelHandle, MutableAppContext,
|
action, elements::*, keymap::Binding, AppContext, Entity, ModelHandle, MutableAppContext,
|
||||||
|
|
|
@ -532,7 +532,7 @@ mod tests {
|
||||||
let text = RandomCharIter::new(&mut rng).take(len).collect::<String>();
|
let text = RandomCharIter::new(&mut rng).take(len).collect::<String>();
|
||||||
MultiBuffer::build_simple(&text, cx)
|
MultiBuffer::build_simple(&text, cx)
|
||||||
} else {
|
} else {
|
||||||
MultiBuffer::build_random(rng.gen_range(1..=5), &mut rng, cx)
|
MultiBuffer::build_random(&mut rng, cx)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1123,7 +1123,7 @@ mod tests {
|
||||||
log::info!("initial buffer text: {:?}", text);
|
log::info!("initial buffer text: {:?}", text);
|
||||||
MultiBuffer::build_simple(&text, cx)
|
MultiBuffer::build_simple(&text, cx)
|
||||||
} else {
|
} else {
|
||||||
MultiBuffer::build_random(rng.gen_range(1..=5), &mut rng, cx)
|
MultiBuffer::build_random(&mut rng, cx)
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut buffer_snapshot = buffer.read(cx).snapshot(cx);
|
let mut buffer_snapshot = buffer.read(cx).snapshot(cx);
|
||||||
|
|
|
@ -1252,7 +1252,7 @@ mod tests {
|
||||||
let buffer = if rng.gen() {
|
let buffer = if rng.gen() {
|
||||||
MultiBuffer::build_simple(&text, cx)
|
MultiBuffer::build_simple(&text, cx)
|
||||||
} else {
|
} else {
|
||||||
MultiBuffer::build_random(rng.gen_range(1..=5), &mut rng, cx)
|
MultiBuffer::build_random(&mut rng, cx)
|
||||||
};
|
};
|
||||||
let mut buffer_snapshot = buffer.read(cx).snapshot(cx);
|
let mut buffer_snapshot = buffer.read(cx).snapshot(cx);
|
||||||
let mut map = FoldMap::new(buffer_snapshot.clone()).0;
|
let mut map = FoldMap::new(buffer_snapshot.clone()).0;
|
||||||
|
|
|
@ -458,7 +458,7 @@ mod tests {
|
||||||
let text = RandomCharIter::new(&mut rng).take(len).collect::<String>();
|
let text = RandomCharIter::new(&mut rng).take(len).collect::<String>();
|
||||||
MultiBuffer::build_simple(&text, cx)
|
MultiBuffer::build_simple(&text, cx)
|
||||||
} else {
|
} else {
|
||||||
MultiBuffer::build_random(rng.gen_range(1..=5), &mut rng, cx)
|
MultiBuffer::build_random(&mut rng, cx)
|
||||||
};
|
};
|
||||||
let buffer_snapshot = buffer.read(cx).snapshot(cx);
|
let buffer_snapshot = buffer.read(cx).snapshot(cx);
|
||||||
log::info!("Buffer text: {:?}", buffer_snapshot.text());
|
log::info!("Buffer text: {:?}", buffer_snapshot.text());
|
||||||
|
|
|
@ -1021,7 +1021,7 @@ mod tests {
|
||||||
|
|
||||||
let buffer = cx.update(|cx| {
|
let buffer = cx.update(|cx| {
|
||||||
if rng.gen() {
|
if rng.gen() {
|
||||||
MultiBuffer::build_random(rng.gen_range(1..=5), &mut rng, cx)
|
MultiBuffer::build_random(&mut rng, cx)
|
||||||
} else {
|
} else {
|
||||||
let len = rng.gen_range(0..10);
|
let len = rng.gen_range(0..10);
|
||||||
let text = RandomCharIter::new(&mut rng).take(len).collect::<String>();
|
let text = RandomCharIter::new(&mut rng).take(len).collect::<String>();
|
||||||
|
|
|
@ -178,13 +178,18 @@ impl MultiBuffer {
|
||||||
|
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
pub fn build_random(
|
pub fn build_random(
|
||||||
excerpts: usize,
|
|
||||||
mut rng: &mut impl rand::Rng,
|
mut rng: &mut impl rand::Rng,
|
||||||
cx: &mut gpui::MutableAppContext,
|
cx: &mut gpui::MutableAppContext,
|
||||||
) -> ModelHandle<Self> {
|
) -> ModelHandle<Self> {
|
||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
|
use std::env;
|
||||||
use text::RandomCharIter;
|
use text::RandomCharIter;
|
||||||
|
|
||||||
|
let max_excerpts = env::var("MAX_EXCERPTS")
|
||||||
|
.map(|i| i.parse().expect("invalid `MAX_EXCERPTS` variable"))
|
||||||
|
.unwrap_or(5);
|
||||||
|
let excerpts = rng.gen_range(1..=max_excerpts);
|
||||||
|
|
||||||
cx.add_model(|cx| {
|
cx.add_model(|cx| {
|
||||||
let mut multibuffer = MultiBuffer::new(0);
|
let mut multibuffer = MultiBuffer::new(0);
|
||||||
let mut buffers = Vec::new();
|
let mut buffers = Vec::new();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue