Re-enable multi-byte random character generation

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Antonio Scandurra 2021-12-15 17:51:11 +01:00
parent 5118f27a90
commit 4ab307f0a1
2 changed files with 106 additions and 93 deletions

View File

@ -2276,6 +2276,7 @@ mod tests {
}
assert_eq!(snapshot.text(), expected_text);
log::info!("MultiBuffer text: {:?}", expected_text);
let mut excerpt_starts = excerpt_starts.into_iter();
for (buffer, range, _) in &expected_excerpts {
@ -2293,7 +2294,12 @@ mod tests {
let mut buffer_point = buffer_start_point;
let mut point_utf16 = excerpt_start.lines_utf16;
let mut buffer_point_utf16 = buffer_start_point_utf16;
for byte in buffer.bytes_in_range(buffer_range.clone()).flatten() {
for ch in buffer
.snapshot()
.chunks(buffer_range.clone(), None)
.flat_map(|c| c.text.chars())
{
for _ in 0..ch.len_utf8() {
let left_offset = snapshot.clip_offset(offset, Bias::Left);
let right_offset = snapshot.clip_offset(offset, Bias::Right);
let buffer_left_offset = buffer.clip_offset(buffer_offset, Bias::Left);
@ -2336,6 +2342,31 @@ mod tests {
buffer_point,
);
assert_eq!(
snapshot.point_to_offset(left_point),
left_offset,
"point_to_offset({:?})",
left_point,
);
assert_eq!(
snapshot.offset_to_point(left_offset),
left_point,
"offset_to_point({:?})",
left_offset,
);
offset += 1;
buffer_offset += 1;
if ch == '\n' {
point += Point::new(1, 0);
buffer_point += Point::new(1, 0);
} else {
point += Point::new(0, 1);
buffer_point += Point::new(0, 1);
}
}
for _ in 0..ch.len_utf16() {
let left_point_utf16 = snapshot.clip_point_utf16(point_utf16, Bias::Left);
let right_point_utf16 = snapshot.clip_point_utf16(point_utf16, Bias::Right);
let buffer_left_point_utf16 =
@ -2361,34 +2392,16 @@ mod tests {
buffer_point_utf16,
);
assert_eq!(
snapshot.point_to_offset(left_point),
left_offset,
"point_to_offset({:?})",
left_point,
);
assert_eq!(
snapshot.offset_to_point(left_offset),
left_point,
"offset_to_point({:?})",
left_offset,
);
offset += 1;
buffer_offset += 1;
if *byte == b'\n' {
point += Point::new(1, 0);
if ch == '\n' {
point_utf16 += PointUtf16::new(1, 0);
buffer_point += Point::new(1, 0);
buffer_point_utf16 += PointUtf16::new(1, 0);
} else {
point += Point::new(0, 1);
point_utf16 += PointUtf16::new(0, 1);
buffer_point += Point::new(0, 1);
buffer_point_utf16 += PointUtf16::new(0, 1);
}
}
}
}
for (row, line) in expected_text.split('\n').enumerate() {
assert_eq!(

View File

@ -22,13 +22,13 @@ impl<T: Rng> Iterator for RandomCharIter<T> {
match self.0.gen_range(0..100) {
// whitespace
0..=5 => ['\n'].choose(&mut self.0).copied(),
0..=19 => [' ', '\n', '\t'].choose(&mut self.0).copied(),
// two-byte greek letters
// 20..=32 => char::from_u32(self.0.gen_range(('α' as u32)..('ω' as u32 + 1))),
20..=32 => char::from_u32(self.0.gen_range(('α' as u32)..('ω' as u32 + 1))),
// // three-byte characters
// 33..=45 => ['✋', '✅', '❌', '❎', '⭐'].choose(&mut self.0).copied(),
33..=45 => ['✋', '✅', '❌', '❎', '⭐'].choose(&mut self.0).copied(),
// // four-byte characters
// 46..=58 => ['🍐', '🏀', '🍗', '🎉'].choose(&mut self.0).copied(),
46..=58 => ['🍐', '🏀', '🍗', '🎉'].choose(&mut self.0).copied(),
// ascii letters
_ => Some(self.0.gen_range(b'a'..b'z' + 1).into()),
}