automerge/automerge-frontend/tests/test_mutation.rs
Andrew Jeffery fc45ff09a3
Allow change to return value from users closure (#84)
* Allow change to return value from users closure

* Add closure_result field to OptimisticChangeResult
2021-04-15 10:49:04 +01:00

42 lines
1.2 KiB
Rust

use automerge_frontend::{Frontend, InvalidChangeRequest, LocalChange, Path, Value};
#[test]
fn test_delete_index_in_mutation() {
let mut frontend = Frontend::new();
let _cr = frontend
.change::<_, _, InvalidChangeRequest>(None, |doc| {
doc.add_change(LocalChange::set(
Path::root().key("vals"),
Value::Sequence(Vec::new()),
))?;
Ok(())
})
.unwrap();
frontend
.change::<_, _, InvalidChangeRequest>(None, |doc| {
doc.add_change(LocalChange::insert(
Path::root().key("vals").index(0),
"0".into(),
))?;
Ok(())
})
.unwrap();
frontend
.change::<_, _, InvalidChangeRequest>(None, |doc| {
doc.add_change(LocalChange::insert(
Path::root().key("vals").index(1),
"1".into(),
))?;
Ok(())
})
.unwrap();
frontend
.change::<_, _, InvalidChangeRequest>(None, |doc| {
doc.add_change(LocalChange::delete(Path::root().key("vals").index(1)))?;
Ok(())
})
.unwrap();
}