Add testing suite for chunk bitmaps
This commit is contained in:
parent
81bb5c2d27
commit
aa39f979b9
7 changed files with 473 additions and 1 deletions
|
@ -7726,6 +7726,8 @@ impl<'a> Iterator for MultiBufferChunks<'a> {
|
|||
chunk.text.split_at(diff_transform_end - self.range.start);
|
||||
self.range.start = diff_transform_end;
|
||||
chunk.text = after;
|
||||
// FIXME: We should be handling bitmap for tabs and chars here
|
||||
// Because we do a split at operation the bitmaps will be off
|
||||
Some(Chunk {
|
||||
text: before,
|
||||
..chunk.clone()
|
||||
|
|
|
@ -7,6 +7,7 @@ use parking_lot::RwLock;
|
|||
use rand::prelude::*;
|
||||
use settings::SettingsStore;
|
||||
use std::env;
|
||||
use util::RandomCharIter;
|
||||
use util::test::sample_text;
|
||||
|
||||
#[ctor::ctor]
|
||||
|
@ -3717,3 +3718,83 @@ fn test_new_empty_buffers_title_can_be_set(cx: &mut App) {
|
|||
});
|
||||
assert_eq!(multibuffer.read(cx).title(cx), "Hey");
|
||||
}
|
||||
|
||||
#[gpui::test(iterations = 100)]
|
||||
fn test_random_chunk_bitmaps(cx: &mut App, mut rng: StdRng) {
|
||||
// Generate random multibuffer using existing test infrastructure
|
||||
let multibuffer = if rng.r#gen() {
|
||||
let len = rng.gen_range(0..10000);
|
||||
let text = RandomCharIter::new(&mut rng).take(len).collect::<String>();
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx));
|
||||
cx.new(|cx| MultiBuffer::singleton(buffer, cx))
|
||||
} else {
|
||||
MultiBuffer::build_random(&mut rng, cx)
|
||||
};
|
||||
|
||||
let snapshot = multibuffer.read(cx).snapshot(cx);
|
||||
|
||||
// Get all chunks and verify their bitmaps
|
||||
let chunks = snapshot.chunks(0..snapshot.len(), false);
|
||||
|
||||
for chunk in chunks {
|
||||
let chunk_text = chunk.text;
|
||||
let chars_bitmap = chunk.chars;
|
||||
let tabs_bitmap = chunk.tabs;
|
||||
|
||||
// Check empty chunks have empty bitmaps
|
||||
if chunk_text.is_empty() {
|
||||
assert_eq!(
|
||||
chars_bitmap, 0,
|
||||
"Empty chunk should have empty chars bitmap"
|
||||
);
|
||||
assert_eq!(tabs_bitmap, 0, "Empty chunk should have empty tabs bitmap");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Verify that chunk text doesn't exceed 128 bytes
|
||||
assert!(
|
||||
chunk_text.len() <= 128,
|
||||
"Chunk text length {} exceeds 128 bytes",
|
||||
chunk_text.len()
|
||||
);
|
||||
|
||||
// Verify chars bitmap
|
||||
let char_indices = chunk_text
|
||||
.char_indices()
|
||||
.map(|(i, _)| i)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
for byte_idx in 0..chunk_text.len() {
|
||||
let should_have_bit = char_indices.contains(&byte_idx);
|
||||
let has_bit = chars_bitmap & (1 << byte_idx) != 0;
|
||||
|
||||
if has_bit != should_have_bit {
|
||||
eprintln!("Chunk text bytes: {:?}", chunk_text.as_bytes());
|
||||
eprintln!("Char indices: {:?}", char_indices);
|
||||
eprintln!("Chars bitmap: {:#b}", chars_bitmap);
|
||||
}
|
||||
|
||||
assert_eq!(
|
||||
has_bit, should_have_bit,
|
||||
"Chars bitmap mismatch at byte index {} in chunk {:?}. Expected bit: {}, Got bit: {}",
|
||||
byte_idx, chunk_text, should_have_bit, has_bit
|
||||
);
|
||||
}
|
||||
|
||||
// Verify tabs bitmap
|
||||
for (byte_idx, byte) in chunk_text.bytes().enumerate() {
|
||||
let is_tab = byte == b'\t';
|
||||
let has_bit = tabs_bitmap & (1 << byte_idx) != 0;
|
||||
|
||||
if has_bit != is_tab {
|
||||
eprintln!("Chunk text bytes: {:?}", chunk_text.as_bytes());
|
||||
eprintln!("Tabs bitmap: {:#b}", tabs_bitmap);
|
||||
assert_eq!(
|
||||
has_bit, is_tab,
|
||||
"Tabs bitmap mismatch at byte index {} in chunk {:?}. Byte: {:?}, Expected bit: {}, Got bit: {}",
|
||||
byte_idx, chunk_text, byte as char, is_tab, has_bit
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue