Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/src/main/java/org/automerge/PatchAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public org.automerge.Mark[] getMarks() {
}

/** A property which was already in the document is now conflicted */
public static class FlagConflict {
public static class FlagConflict extends PatchAction {
private final Prop property;

protected FlagConflict(Prop property) {
Expand Down
60 changes: 58 additions & 2 deletions lib/src/test/java/org/automerge/TestPatches.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public void testSpliceText() {
}

@Test
public void testFlagConflictMap() {
public void testConflictedPutInMap() {
Document doc1 = new Document("bbbb".getBytes());
Document doc2 = new Document("aaaa".getBytes());
try (Transaction tx = doc1.startTransaction()) {
Expand All @@ -271,7 +271,31 @@ public void testFlagConflictMap() {
}

@Test
public void testFlagConflictList() {
public void testFlagConflictMap() {
Document doc1 = new Document("bbbb".getBytes());
Document doc2 = new Document("aaaa".getBytes());
try (Transaction tx = doc1.startTransaction()) {
tx.set(ObjectId.ROOT, "key", "value_1");
tx.commit();
}
try (Transaction tx = doc2.startTransaction()) {
tx.set(ObjectId.ROOT, "key", "value_2");
tx.commit();
}
PatchLog patchLog = new PatchLog();
doc1.merge(doc2, patchLog);
List<Patch> patches = doc1.makePatches(patchLog);

Assertions.assertEquals(patches.size(), 1);
Patch patch = patches.get(0);
Assertions.assertEquals(patch.getObj(), ObjectId.ROOT);
Assertions.assertEquals(patch.getPath(), emptyPath());

PatchAction.FlagConflict action = (PatchAction.FlagConflict) patch.getAction();
}

@Test
public void testConflictedPutInList() {
Document doc1 = new Document("bbbb".getBytes());
ObjectId list;
try (Transaction tx = doc1.startTransaction()) {
Expand Down Expand Up @@ -303,6 +327,38 @@ public void testFlagConflictList() {
Assertions.assertTrue(action.isConflict());
}

@Test
public void testFlagConflictList() {
Document doc1 = new Document("bbbb".getBytes());
ObjectId list;
try (Transaction tx = doc1.startTransaction()) {
list = tx.set(ObjectId.ROOT, "list", ObjectType.LIST);
tx.insert(list, 0, NewValue.NULL);
tx.commit();
}

Document doc2 = doc1.fork("aaaa".getBytes());
try (Transaction tx = doc1.startTransaction()) {
tx.set(list, 0, "value_2");
tx.commit();
}
try (Transaction tx = doc2.startTransaction()) {
tx.set(list, 0, "value_1");
tx.commit();
}

PatchLog patchLog = new PatchLog();
doc1.merge(doc2, patchLog);
List<Patch> patches = doc1.makePatches(patchLog);

Assertions.assertEquals(patches.size(), 1);
Patch patch = patches.get(0);
Assertions.assertEquals(patch.getObj(), list);
Assertions.assertEquals(patch.getPath(), PathBuilder.root("list").build());

PatchAction.FlagConflict action = (PatchAction.FlagConflict) patch.getAction();
}

@Test
public void testIncrementInMap() {
Document doc = new Document();
Expand Down
4 changes: 2 additions & 2 deletions rust/src/patches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ fn to_jni_patch<'a>(
let jprop = prop_to_java(env, &prop)?;
env.new_object(
FLAG_CONFLICT_CLASS,
format!("(L{PROP_CLASS};J)V"),
&[(&jprop).into(), 0.into()],
format!("(L{PROP_CLASS};)V"),
&[(&jprop).into()],
)?
}
};
Expand Down
Loading