mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-12 21:32:40 +00:00
Move buffer rows test into WrapMap
randomized test
Also, change the way we assert on buffer rows to reflect the fact that we will still show the line as soft-wrapped when there is a fold that spans multiple buffer rows.
This commit is contained in:
parent
d6eb6d33b6
commit
42e2b9ff4d
3 changed files with 28 additions and 68 deletions
|
@ -290,75 +290,10 @@ mod tests {
|
||||||
language::{Language, LanguageConfig},
|
language::{Language, LanguageConfig},
|
||||||
settings::Theme,
|
settings::Theme,
|
||||||
test::*,
|
test::*,
|
||||||
util::RandomCharIter,
|
|
||||||
};
|
};
|
||||||
use buffer::History;
|
use buffer::History;
|
||||||
use gpui::MutableAppContext;
|
use gpui::MutableAppContext;
|
||||||
use rand::prelude::*;
|
use std::sync::Arc;
|
||||||
use std::{env, sync::Arc};
|
|
||||||
|
|
||||||
#[gpui::test]
|
|
||||||
async fn test_random(mut cx: gpui::TestAppContext) {
|
|
||||||
cx.foreground().set_block_on_ticks(usize::MAX..=usize::MAX);
|
|
||||||
let iterations = env::var("ITERATIONS")
|
|
||||||
.map(|i| i.parse().expect("invalid `ITERATIONS` variable"))
|
|
||||||
.unwrap_or(100);
|
|
||||||
let operations = env::var("OPERATIONS")
|
|
||||||
.map(|i| i.parse().expect("invalid `OPERATIONS` variable"))
|
|
||||||
.unwrap_or(10);
|
|
||||||
let seed_range = if let Ok(seed) = env::var("SEED") {
|
|
||||||
let seed = seed.parse().expect("invalid `SEED` variable");
|
|
||||||
seed..seed + 1
|
|
||||||
} else {
|
|
||||||
0..iterations
|
|
||||||
};
|
|
||||||
let font_cache = cx.font_cache();
|
|
||||||
|
|
||||||
for seed in seed_range {
|
|
||||||
dbg!(seed);
|
|
||||||
let mut rng = StdRng::seed_from_u64(seed);
|
|
||||||
let settings = Settings {
|
|
||||||
buffer_font_family: font_cache.load_family(&["Helvetica"]).unwrap(),
|
|
||||||
ui_font_family: font_cache.load_family(&["Helvetica"]).unwrap(),
|
|
||||||
buffer_font_size: 12.0,
|
|
||||||
ui_font_size: 12.0,
|
|
||||||
tab_size: rng.gen_range(1..=4),
|
|
||||||
theme: Arc::new(Theme::default()),
|
|
||||||
};
|
|
||||||
|
|
||||||
let buffer = cx.add_model(|cx| {
|
|
||||||
let len = rng.gen_range(0..10);
|
|
||||||
let text = RandomCharIter::new(&mut rng).take(len).collect::<String>();
|
|
||||||
log::info!("Initial buffer text: {:?}", text);
|
|
||||||
Buffer::new(0, text, cx)
|
|
||||||
});
|
|
||||||
let wrap_width = Some(rng.gen_range(20.0..=100.0));
|
|
||||||
let map = cx.add_model(|cx| DisplayMap::new(buffer.clone(), settings, wrap_width, cx));
|
|
||||||
|
|
||||||
for _op_ix in 0..operations {
|
|
||||||
buffer.update(&mut cx, |buffer, cx| buffer.randomly_mutate(&mut rng, cx));
|
|
||||||
let snapshot = map.update(&mut cx, |map, cx| map.snapshot(cx));
|
|
||||||
let expected_buffer_rows = (0..=snapshot.max_point().row())
|
|
||||||
.map(|display_row| {
|
|
||||||
DisplayPoint::new(display_row, 0)
|
|
||||||
.to_buffer_point(&snapshot, Bias::Left)
|
|
||||||
.row
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
for start_display_row in 0..expected_buffer_rows.len() {
|
|
||||||
assert_eq!(
|
|
||||||
snapshot
|
|
||||||
.buffer_rows(start_display_row as u32)
|
|
||||||
.map(|(row, _)| row)
|
|
||||||
.collect::<Vec<_>>(),
|
|
||||||
&expected_buffer_rows[start_display_row..],
|
|
||||||
"invalid buffer_rows({}..)",
|
|
||||||
start_display_row
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_soft_wraps(mut cx: gpui::TestAppContext) {
|
async fn test_soft_wraps(mut cx: gpui::TestAppContext) {
|
||||||
|
|
|
@ -91,8 +91,8 @@ impl TabMap {
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Snapshot {
|
pub struct Snapshot {
|
||||||
fold_snapshot: FoldSnapshot,
|
pub fold_snapshot: FoldSnapshot,
|
||||||
tab_size: usize,
|
pub tab_size: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Snapshot {
|
impl Snapshot {
|
||||||
|
|
|
@ -583,6 +583,31 @@ impl Snapshot {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut expected_buffer_rows = Vec::new();
|
||||||
|
let mut buffer_row = 0;
|
||||||
|
let mut prev_tab_row = 0;
|
||||||
|
for display_row in 0..=self.max_point().row() {
|
||||||
|
let tab_point = self.to_tab_point(WrapPoint::new(display_row, 0));
|
||||||
|
if tab_point.row() != prev_tab_row {
|
||||||
|
let fold_point = self.tab_snapshot.to_fold_point(tab_point, Bias::Left).0;
|
||||||
|
let buffer_point = fold_point.to_buffer_point(&self.tab_snapshot.fold_snapshot);
|
||||||
|
buffer_row = buffer_point.row;
|
||||||
|
prev_tab_row = tab_point.row();
|
||||||
|
}
|
||||||
|
expected_buffer_rows.push(buffer_row);
|
||||||
|
}
|
||||||
|
|
||||||
|
for start_display_row in 0..expected_buffer_rows.len() {
|
||||||
|
assert_eq!(
|
||||||
|
self.buffer_rows(start_display_row as u32)
|
||||||
|
.map(|(row, _)| row)
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
&expected_buffer_rows[start_display_row..],
|
||||||
|
"invalid buffer_rows({}..)",
|
||||||
|
start_display_row
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue