Merge branch 'bugfixes'

This commit is contained in:
Alex Good 2020-05-26 16:17:45 +01:00
commit 339e18a6ad
4 changed files with 48 additions and 3 deletions

View file

@ -272,7 +272,7 @@ impl<'a> ChangeContext<'a> {
&object_id,
original_objects,
updated,
|| Object::Sequence(object_id.clone(), Vec::new(), SequenceType::List),
|| Object::Sequence(object_id.clone(), Vec::new(), SequenceType::Text),
);
match &mut *obj.borrow_mut() {
Object::Sequence(_, ref mut elems, SequenceType::Text) => {

View file

@ -361,6 +361,13 @@ impl Frontend {
_ => None,
})
}
pub fn get_value(&self, path: &Path) -> Option<Value> {
self.state
.as_ref()
.and_then(|s| s.get_object(path))
.map(|o| o.value())
}
}
fn system_time() -> Option<i64> {

View file

@ -421,7 +421,7 @@ impl<'a, 'b> MutableDocument for MutationTracker<'a, 'b> {
object_id: oid.clone(),
obj_type: *seq_type,
edits: vec![amp::DiffEdit::Remove { index: *i }],
props: hashmap! {*i => HashMap::new()},
props: HashMap::new(),
})
} else {
return Err(AutomergeFrontendError::NoSuchPathError(change.path));
@ -480,7 +480,7 @@ impl<'a, 'b> MutableDocument for MutationTracker<'a, 'b> {
Err(AutomergeFrontendError::InvalidChangeRequest)
}
Object::Sequence(oid, vals, seq_type) => {
if vals.len() > index + 1 {
if *index > vals.len() {
return Err(AutomergeFrontendError::InvalidChangeRequest);
}
let (ops, diff) = value_to_op_requests(

View file

@ -0,0 +1,38 @@
use automerge_frontend::{Frontend, Value, LocalChange, Path};
use automerge_protocol as amp;
#[test]
fn test_delete_index_in_mutation() {
let mut frontend = Frontend::new();
let _cr = frontend.change(None, |doc| {
doc.add_change(LocalChange::set(
Path::root().key("vals"),
Value::Sequence(Vec::new(), amp::SequenceType::List),
))?;
Ok(())
}).unwrap();
frontend.change(None, |doc| {
doc.add_change(LocalChange::insert(
Path::root().key("vals").index(0),
Value::Primitive("0".into()),
))?;
Ok(())
}).unwrap();
frontend.change(None, |doc| {
doc.add_change(LocalChange::insert(
Path::root().key("vals").index(1),
Value::Primitive("1".into()),
))?;
Ok(())
}).unwrap();
frontend.change(None, |doc| {
doc.add_change(LocalChange::delete(
Path::root().key("vals").index(1),
))?;
Ok(())
}).unwrap();
}