use of org.eclipse.text.edits.TextEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testMoveUpWithInnerMark.
@Test
public void testMoveUpWithInnerMark() throws Exception {
MoveSourceEdit s1 = new MoveSourceEdit(7, 2);
MoveTargetEdit t1 = new MoveTargetEdit(2, s1);
TextEdit m = new ReplaceEdit(4, 1, "yy");
fRoot.addChild(t1);
fRoot.addChild(m);
fRoot.addChild(s1);
UndoEdit undo = fRoot.apply(fDocument);
Assert.assertEquals("Buffer content", "017823yy569", fDocument.get());
assertEquals(s1, 10, 0);
assertEquals(t1, 2, 2);
assertEquals(m, 6, 2);
doUndoRedo(undo, "017823yy569");
}
use of org.eclipse.text.edits.TextEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testMoveWithTargetDelete.
@Test
public void testMoveWithTargetDelete() throws Exception {
MoveSourceEdit s1 = new MoveSourceEdit(2, 3);
MoveTargetEdit t1 = new MoveTargetEdit(7, s1);
TextEdit e2 = new DeleteEdit(6, 2);
e2.addChild(t1);
fRoot.addChild(s1);
fRoot.addChild(e2);
UndoEdit undo = fRoot.apply(fDocument);
Assert.assertEquals("Buffer content", "01589", fDocument.get());
assertEquals(s1, 2, 0);
assertTrue(t1.isDeleted());
assertEquals(e2, 3, 0);
doUndoRedo(undo, "01589");
}
use of org.eclipse.text.edits.TextEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testComparator.
@Test
public void testComparator() throws Exception {
DeleteEdit d1 = new DeleteEdit(1, 3);
Accessor accessor = new Accessor(d1, TextEdit.class);
@SuppressWarnings("unchecked") Comparator<TextEdit> comparator = (Comparator<TextEdit>) accessor.get("INSERTION_COMPARATOR");
TextEdit edit1 = new InsertEdit(1, "test");
TextEdit edit2 = new InsertEdit(1, "test");
TextEdit edit3 = new InsertEdit(57, "test3");
assertTrue(edit1.equals(edit1));
Assert.assertEquals(0, comparator.compare(edit1, edit1));
Assert.assertEquals(0, comparator.compare(edit1, edit2));
Assert.assertEquals(0, comparator.compare(edit2, edit1));
assertTrue(comparator.compare(edit1, edit3) == -comparator.compare(edit3, edit1));
}
use of org.eclipse.text.edits.TextEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testMoveTree3.
@Test
public void testMoveTree3() {
boolean exception = false;
try {
TextEdit root = new ReplaceEdit(0, 1, "");
root.moveTree(-1);
} catch (Exception e) {
exception = true;
}
assertTrue(exception);
}
use of org.eclipse.text.edits.TextEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testTreeUpdate1.
@Test
public void testTreeUpdate1() throws Exception {
MultiTextEdit m1 = new MultiTextEdit();
TextEdit e1 = new InsertEdit(2, "aa");
TextEdit e2 = new InsertEdit(4, "bb");
m1.addChild(e1);
m1.addChild(e2);
MultiTextEdit m2 = new MultiTextEdit();
TextEdit e3 = new InsertEdit(6, "cc");
TextEdit e4 = new InsertEdit(8, "dd");
m2.addChild(e3);
m2.addChild(e4);
fRoot.addChild(m1);
fRoot.addChild(m2);
assertEquals(m1, 2, 2);
assertEquals(m2, 6, 2);
UndoEdit undo = fRoot.apply(fDocument);
Assert.assertEquals("Buffer content", "01aa23bb45cc67dd89", fDocument.get());
assertEquals(e1, 2, 2);
assertEquals(e2, 6, 2);
assertEquals(e3, 10, 2);
assertEquals(e4, 14, 2);
assertEquals(m1, 2, 6);
assertEquals(m2, 10, 6);
assertEquals(fRoot, 2, 14);
doUndoRedo(undo, "01aa23bb45cc67dd89");
}
Aggregations