use of org.eclipse.text.edits.CopySourceEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testNestedCopySourceWithInsert.
@Test
public void testNestedCopySourceWithInsert() throws Exception {
CopySourceEdit s1 = new CopySourceEdit(1, 5);
CopySourceEdit s2 = new CopySourceEdit(2, 3);
CopySourceEdit s3 = new CopySourceEdit(3, 1);
InsertEdit i1 = new InsertEdit(4, "x");
s1.addChild(s2);
s2.addChild(s3);
s3.addChild(i1);
CopyTargetEdit t1 = new CopyTargetEdit(9, s1);
CopyTargetEdit t2 = new CopyTargetEdit(8, s2);
CopyTargetEdit t3 = new CopyTargetEdit(7, s3);
fRoot.addChild(s1);
fRoot.addChild(t1);
fRoot.addChild(t2);
fRoot.addChild(t3);
UndoEdit undo = fRoot.apply(fDocument);
assertEquals(s1, 1, 6);
assertEquals(s2, 2, 4);
assertEquals(s3, 3, 2);
assertEquals(i1, 4, 1);
assertEquals(t1, 16, 6);
assertEquals(t2, 11, 4);
assertEquals(t3, 8, 2);
String result = "0123x4563x723x48123x459";
Assert.assertEquals("Buffer content", result, fDocument.get());
doUndoRedo(undo, result);
}
use of org.eclipse.text.edits.CopySourceEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testSwap2InSwap1.
@Test
public void testSwap2InSwap1() throws Exception {
IDocument document = new Document("foo(1, 2), 3");
CopySourceEdit innerRoot = new CopySourceEdit(0, 9);
{
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);
innerRoot.addChild(e1);
innerRoot.addChild(t2);
innerRoot.addChild(e2);
innerRoot.addChild(t1);
}
MultiTextEdit root = new MultiTextEdit();
{
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(2, 1)";
Assert.assertEquals("Buffer content", result, document.get());
}
use of org.eclipse.text.edits.CopySourceEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testNestedCopyTarget.
@Test
public void testNestedCopyTarget() throws Exception {
CopySourceEdit s1 = new CopySourceEdit(1, 2);
CopySourceEdit s2 = new CopySourceEdit(5, 3);
CopyTargetEdit t1 = new CopyTargetEdit(6, s1);
CopyTargetEdit t2 = new CopyTargetEdit(9, s2);
s2.addChild(t1);
fRoot.addChild(s1);
fRoot.addChild(s2);
fRoot.addChild(t2);
UndoEdit undo = fRoot.apply(fDocument);
assertEquals(s1, 1, 2);
assertEquals(s2, 5, 5);
assertEquals(t1, 6, 2);
assertEquals(t2, 11, 5);
String result = "01234512678512679";
Assert.assertEquals("Buffer content", result, fDocument.get());
doUndoRedo(undo, result);
}
use of org.eclipse.text.edits.CopySourceEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testCopy2.
@Test
public void testCopy2() throws Exception {
MultiTextEdit root = new MultiTextEdit();
CopySourceEdit s1 = new CopySourceEdit(5, 2);
CopyTargetEdit t1 = new CopyTargetEdit(8, s1);
CopySourceEdit s2 = new CopySourceEdit(5, 2);
CopyTargetEdit t2 = new CopyTargetEdit(2, s2);
s1.addChild(s2);
root.addChild(s1);
root.addChild(t1);
root.addChild(t2);
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.CopySourceEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method compare.
private static void compare(List<TextEdit> org, List<TextEdit> copy) {
assertTrue("Same length", org.size() == copy.size());
for (Iterator<TextEdit> iter = copy.iterator(); iter.hasNext(); ) {
TextEdit edit = iter.next();
assertTrue("Original is part of copy list", !org.contains(edit));
if (edit instanceof MoveSourceEdit) {
MoveSourceEdit source = (MoveSourceEdit) edit;
assertTrue("Target edit isn't a copy", copy.contains(source.getTargetEdit()));
assertTrue("Traget edit is a original", !org.contains(source.getTargetEdit()));
} else if (edit instanceof MoveTargetEdit) {
MoveTargetEdit target = (MoveTargetEdit) edit;
assertTrue("Source edit isn't a copy", copy.contains(target.getSourceEdit()));
assertTrue("Source edit is a original", !org.contains(target.getSourceEdit()));
} else if (edit instanceof CopySourceEdit) {
CopySourceEdit source = (CopySourceEdit) edit;
assertTrue("Target edit isn't a copy", copy.contains(source.getTargetEdit()));
assertTrue("Traget edit is a original", !org.contains(source.getTargetEdit()));
} else if (edit instanceof CopyTargetEdit) {
CopyTargetEdit target = (CopyTargetEdit) edit;
assertTrue("Source edit isn't a copy", copy.contains(target.getSourceEdit()));
assertTrue("Source edit is a original", !org.contains(target.getSourceEdit()));
}
}
}
Aggregations