Set up flow for mutating clients via explicit operation values

This commit is contained in:
Max Brunsfeld 2023-01-04 15:16:06 -08:00
parent ce8dd5a286
commit f243633f3e
3 changed files with 656 additions and 498 deletions

View File

@ -24,7 +24,7 @@ use std::{
cell::{Ref, RefCell, RefMut},
env,
ops::{Deref, DerefMut},
path::{Path, PathBuf},
path::Path,
sync::{
atomic::{AtomicBool, AtomicUsize, Ordering::SeqCst},
Arc,
@ -332,7 +332,6 @@ struct TestClientState {
local_projects: Vec<ModelHandle<Project>>,
remote_projects: Vec<ModelHandle<Project>>,
buffers: HashMap<ModelHandle<Project>, HashSet<ModelHandle<language::Buffer>>>,
next_root_dir_id: usize,
}
impl Deref for TestClient {
@ -483,15 +482,6 @@ impl TestClient {
)
})
}
fn create_new_root_dir(&self) -> PathBuf {
format!(
"/{}-root-{}",
self.username,
util::post_inc(&mut self.state.borrow_mut().next_root_dir_id)
)
.into()
}
}
impl Drop for TestClient {

File diff suppressed because it is too large Load Diff

View File

@ -1429,12 +1429,11 @@ impl Buffer {
start..end
}
#[allow(clippy::type_complexity)]
pub fn randomly_edit<T>(
&mut self,
pub fn get_random_edits<T>(
&self,
rng: &mut T,
edit_count: usize,
) -> (Vec<(Range<usize>, Arc<str>)>, Operation)
) -> Vec<(Range<usize>, Arc<str>)>
where
T: rand::Rng,
{
@ -1453,8 +1452,21 @@ impl Buffer {
edits.push((range, new_text.into()));
}
edits
}
#[allow(clippy::type_complexity)]
pub fn randomly_edit<T>(
&mut self,
rng: &mut T,
edit_count: usize,
) -> (Vec<(Range<usize>, Arc<str>)>, Operation)
where
T: rand::Rng,
{
let mut edits = self.get_random_edits(rng, edit_count);
log::info!("mutating buffer {} with {:?}", self.replica_id, edits);
let op = self.edit(edits.iter().cloned());
if let Operation::Edit(edit) = &op {
assert_eq!(edits.len(), edit.new_text.len());