@@ -125,6 +125,81 @@ public void updateAndDeleteDifferentNodesAppliesBoth() {
125125 assertEquals ("Both operations should be applied" , 2 , appliedOps .size ());
126126 }
127127
128+ /**
129+ * Per XQuery Update Facility 1.0 section 3.2.2:
130+ * Insert operations are applied before delete operations.
131+ * An INSERT_BEFORE targeting a node that will be deleted should NOT be skipped.
132+ * The inserted content becomes a sibling and persists after the delete.
133+ */
134+ @ Test
135+ public void insertBeforeDeletedNodeIsNotSkipped () {
136+ final List <String > appliedOps = new ArrayList <>();
137+ final StructuredItem targetItem = new ArrayObject (new QNm [] { new QNm ("name" ) },
138+ new Sequence [] { new Str ("test" ) });
139+
140+ final UpdateList updateList = new UpdateList ();
141+
142+ // Add an INSERT_BEFORE operation targeting a node
143+ updateList .append (new TestUpdateOp (OpType .INSERT_BEFORE , targetItem , () -> appliedOps .add ("INSERT_BEFORE" )));
144+
145+ // Add a DELETE operation for the same target
146+ updateList .append (new TestUpdateOp (OpType .DELETE , targetItem , () -> appliedOps .add ("DELETE" )));
147+
148+ // Apply updates
149+ updateList .apply ();
150+
151+ // Both should be applied - INSERT_BEFORE creates a sibling, then DELETE removes the target
152+ assertEquals ("Both INSERT_BEFORE and DELETE should be applied" , List .of ("INSERT_BEFORE" , "DELETE" ), appliedOps );
153+ }
154+
155+ /**
156+ * INSERT_INTO targeting a deleted node should also be applied.
157+ */
158+ @ Test
159+ public void insertIntoDeletedNodeIsNotSkipped () {
160+ final List <String > appliedOps = new ArrayList <>();
161+ final StructuredItem targetItem = new ArrayObject (new QNm [] { new QNm ("name" ) },
162+ new Sequence [] { new Str ("test" ) });
163+
164+ final UpdateList updateList = new UpdateList ();
165+
166+ // Add an INSERT_INTO operation
167+ updateList .append (new TestUpdateOp (OpType .INSERT_INTO , targetItem , () -> appliedOps .add ("INSERT_INTO" )));
168+
169+ // Add a DELETE operation for the same target
170+ updateList .append (new TestUpdateOp (OpType .DELETE , targetItem , () -> appliedOps .add ("DELETE" )));
171+
172+ // Apply updates
173+ updateList .apply ();
174+
175+ // Both should be applied
176+ assertEquals ("Both INSERT_INTO and DELETE should be applied" , List .of ("INSERT_INTO" , "DELETE" ), appliedOps );
177+ }
178+
179+ /**
180+ * INSERT_AFTER targeting a deleted node should also be applied.
181+ */
182+ @ Test
183+ public void insertAfterDeletedNodeIsNotSkipped () {
184+ final List <String > appliedOps = new ArrayList <>();
185+ final StructuredItem targetItem = new ArrayObject (new QNm [] { new QNm ("name" ) },
186+ new Sequence [] { new Str ("test" ) });
187+
188+ final UpdateList updateList = new UpdateList ();
189+
190+ // Add an INSERT_AFTER operation
191+ updateList .append (new TestUpdateOp (OpType .INSERT_AFTER , targetItem , () -> appliedOps .add ("INSERT_AFTER" )));
192+
193+ // Add a DELETE operation for the same target
194+ updateList .append (new TestUpdateOp (OpType .DELETE , targetItem , () -> appliedOps .add ("DELETE" )));
195+
196+ // Apply updates
197+ updateList .apply ();
198+
199+ // Both should be applied
200+ assertEquals ("Both INSERT_AFTER and DELETE should be applied" , List .of ("INSERT_AFTER" , "DELETE" ), appliedOps );
201+ }
202+
128203 /**
129204 * Simple test implementation of UpdateOp for testing purposes.
130205 */
0 commit comments