use of org.eclipse.text.edits.TextEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testCopy1.
@Test
public void testCopy1() throws Exception {
MultiTextEdit root = new MultiTextEdit();
TextEdit e1 = new InsertEdit(2, "yy");
TextEdit e2 = new ReplaceEdit(2, 3, "3456");
root.addChild(e1);
root.addChild(e2);
List<TextEdit> org = flatten(root);
TextEditCopier copier = new TextEditCopier(root);
List<TextEdit> copy = flatten(copier.perform());
compare(org, copy);
}
use of org.eclipse.text.edits.TextEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testInsert1.
@Test
public void testInsert1() throws Exception {
// [][ ]
TextEdit e1 = new InsertEdit(2, "yy");
TextEdit e2 = new ReplaceEdit(2, 3, "3456");
fRoot.addChild(e1);
fRoot.addChild(e2);
UndoEdit undo = fRoot.apply(fDocument);
assertEquals(fRoot, 2, 6);
assertEquals(e1, 2, 2);
assertEquals(e2, 4, 4);
Assert.assertEquals("Buffer content", "01yy345656789", fDocument.get());
doUndoRedo(undo, "01yy345656789");
}
use of org.eclipse.text.edits.TextEdit 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.TextEdit 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.TextEdit 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());
}
Aggregations