diff --git a/lib/src/main/java/org/automerge/PatchAction.java b/lib/src/main/java/org/automerge/PatchAction.java index d29aae4..3607ddc 100644 --- a/lib/src/main/java/org/automerge/PatchAction.java +++ b/lib/src/main/java/org/automerge/PatchAction.java @@ -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) { diff --git a/lib/src/test/java/org/automerge/TestPatches.java b/lib/src/test/java/org/automerge/TestPatches.java index f365438..75f938f 100644 --- a/lib/src/test/java/org/automerge/TestPatches.java +++ b/lib/src/test/java/org/automerge/TestPatches.java @@ -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()) { @@ -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 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()) { @@ -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 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(); diff --git a/rust/src/patches.rs b/rust/src/patches.rs index 581821e..815bdbb 100644 --- a/rust/src/patches.rs +++ b/rust/src/patches.rs @@ -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()], )? } };