use of org.eclipse.text.edits.InsertEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testInsert5.
@Test
public void testInsert5() throws Exception {
TextEdit e1 = new InsertEdit(10, "xx");
fRoot.addChild(e1);
UndoEdit undo = fRoot.apply(fDocument);
Assert.assertEquals("Buffer length", 12, fDocument.getLength());
assertEquals(fRoot, 10, 2);
assertEquals(e1, 10, 2);
Assert.assertEquals("Buffer content", "0123456789xx", fDocument.get());
doUndoRedo(undo, "0123456789xx");
}
use of org.eclipse.text.edits.InsertEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testOverlap6.
@Test
public void testOverlap6() throws Exception {
// [ [] ]
fRoot.addChild(new ReplaceEdit(0, 3, "012"));
boolean exception = false;
try {
fRoot.addChild(new InsertEdit(2, "xx"));
} catch (MalformedTreeException e) {
exception = true;
}
assertTrue(exception);
}
use of org.eclipse.text.edits.InsertEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testDelete3.
@Test
public void testDelete3() throws Exception {
TextEdit e1 = new InsertEdit(3, "x");
TextEdit e2 = new DeleteEdit(3, 1);
fRoot.addChild(e1);
fRoot.addChild(e2);
UndoEdit undo = fRoot.apply(fDocument);
assertEquals(fRoot, 3, 1);
assertEquals(e1, 3, 1);
assertEquals(e2, 4, 0);
Assert.assertEquals("Buffer content", "012x456789", fDocument.get());
doUndoRedo(undo, "012x456789");
}
use of org.eclipse.text.edits.InsertEdit 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.InsertEdit 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