Merge branch 'bugfixes'
This commit is contained in:
commit
339e18a6ad
4 changed files with 48 additions and 3 deletions
automerge-frontend
|
@ -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) => {
|
||||
|
|
|
@ -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> {
|
||||
|
|
|
@ -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(
|
||||
|
|
38
automerge-frontend/tests/test_mutation.rs
Normal file
38
automerge-frontend/tests/test_mutation.rs
Normal 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();
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue