use of org.eclipse.text.edits.ReplaceEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testMoveTree2.
@Test
public void testMoveTree2() {
TextEdit root = new MultiTextEdit();
TextEdit e1 = new ReplaceEdit(3, 1, "");
root.addChild(e1);
TextEdit e2 = new ReplaceEdit(5, 2, "");
root.addChild(e2);
root.moveTree(-3);
Assert.assertEquals(0, root.getOffset());
Assert.assertEquals(4, root.getLength());
Assert.assertEquals(0, e1.getOffset());
Assert.assertEquals(1, e1.getLength());
Assert.assertEquals(2, e2.getOffset());
Assert.assertEquals(2, e2.getLength());
}
use of org.eclipse.text.edits.ReplaceEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testSwap1.
@Test
public void testSwap1() throws Exception {
IDocument document = new Document("foo(1, 2), 3");
MultiTextEdit root = new MultiTextEdit();
{
CopySourceEdit innerRoot = new CopySourceEdit(0, 9);
TextEdit e1 = new ReplaceEdit(0, 9, "");
e1.addChild(innerRoot);
CopyTargetEdit t1 = new CopyTargetEdit(11, innerRoot);
TextEdit e2 = new ReplaceEdit(11, 1, "");
CopySourceEdit s2 = new CopySourceEdit(11, 1);
e2.addChild(s2);
CopyTargetEdit t2 = new CopyTargetEdit(0, s2);
root.addChild(e1);
root.addChild(t2);
root.addChild(e2);
root.addChild(t1);
}
root.apply(document);
String result = "3, foo(1, 2)";
Assert.assertEquals("Buffer content", result, document.get());
}
use of org.eclipse.text.edits.ReplaceEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testSwap2.
@Test
public void testSwap2() throws Exception {
IDocument document = new Document("foo(1, 2), 3");
MultiTextEdit root = new MultiTextEdit();
{
TextEdit e1 = new ReplaceEdit(4, 1, "");
CopySourceEdit s1 = new CopySourceEdit(4, 1);
e1.addChild(s1);
CopyTargetEdit t1 = new CopyTargetEdit(7, s1);
TextEdit e2 = new ReplaceEdit(7, 1, "");
CopySourceEdit s2 = new CopySourceEdit(7, 1);
e2.addChild(s2);
CopyTargetEdit t2 = new CopyTargetEdit(4, s2);
root.addChild(e1);
root.addChild(t2);
root.addChild(e2);
root.addChild(t1);
}
root.apply(document);
String result = "foo(2, 1), 3";
Assert.assertEquals("Buffer content", result, document.get());
}
use of org.eclipse.text.edits.ReplaceEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testDeleteWithChildren.
@Test
public void testDeleteWithChildren() throws Exception {
TextEdit e1 = new DeleteEdit(2, 6);
MultiTextEdit e2 = new MultiTextEdit(3, 3);
e1.addChild(e2);
TextEdit e3 = new ReplaceEdit(3, 1, "xx");
TextEdit e4 = new ReplaceEdit(5, 1, "yy");
e2.addChild(e3);
e2.addChild(e4);
fRoot.addChild(e1);
UndoEdit undo = fRoot.apply(fDocument);
Assert.assertEquals("Buffer content", "0189", fDocument.get());
assertEquals(fRoot, 2, 0);
assertEquals(e1, 2, 0);
assertTrue(e2.isDeleted());
assertTrue(e3.isDeleted());
assertTrue(e4.isDeleted());
doUndoRedo(undo, "0189");
}
use of org.eclipse.text.edits.ReplaceEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testSourceTranformationMultipleCovers.
// Regression test for 108672 [quick fix] Exception when applying Convert to enhanced for loop
@Test
public void testSourceTranformationMultipleCovers() throws Exception {
MoveSourceEdit ms = new MoveSourceEdit(2, 4);
MoveTargetEdit mt = new MoveTargetEdit(9, ms);
fRoot.addChild(ms);
fRoot.addChild(mt);
RangeMarker r1 = new RangeMarker(3, 0);
ms.addChild(r1);
RangeMarker r2 = new RangeMarker(3, 0);
ms.addChild(r2);
RangeMarker r3 = new RangeMarker(4, 2);
ms.addChild(r3);
ms.setSourceModifier(new ISourceModifier() {
@Override
public ISourceModifier copy() {
return this;
}
@Override
public ReplaceEdit[] getModifications(String source) {
return new ReplaceEdit[] { new ReplaceEdit(0, 2, "aa") };
}
});
fRoot.apply(fDocument);
String result = "01678aa459";
Assert.assertEquals("Buffer content", result, fDocument.get());
assertTrue(r1.isDeleted());
assertTrue(r2.isDeleted());
assertEquals(r3, 7, 2);
}
Aggregations