macro_rules! assert_doc {
    ($doc: expr, $expected: expr) => { ... };
}
Expand description

This macro makes it easy to make assertions about a document. It is called with two arguments, the first is a reference to an automerge::Automerge, the second is an instance of RealizedObject<ExportableOpId>.

What - I hear you ask - is a RealizedObject? It’s a fully hydrated version of the contents of an automerge document. You don’t need to think about this too much though because you can easily construct one with the map! and list! macros. Here’s an example:

Constructing documents

let mut doc = automerge::AutoCommit::new();
let todos = doc.put_object(automerge::ROOT, "todos", automerge::ObjType::List).unwrap();
let todo = doc.insert_object(todos, 0, automerge::ObjType::Map).unwrap();
let title = doc.put(todo, "title", "water plants").unwrap();

assert_doc!(
    &doc,
    map!{
        "todos" => {
            list![
                { map!{ "title" => { "water plants" } } }
            ]
        }
    }
);

This might look more complicated than you were expecting. Why is the first element in the list wrapped in braces? Because every property in an automerge document can have multiple conflicting values we must capture all of these.


let mut doc1 = automerge::AutoCommit::new();
let mut doc2 = automerge::AutoCommit::new();
doc1.put(automerge::ROOT, "field", "one").unwrap();
doc2.put(automerge::ROOT, "field", "two").unwrap();
doc1.merge(&mut doc2);
assert_doc!(
    doc1.document(),
    map!{
        "field" => {
            "one",
            "two"
        }
    }
);