use of org.eclipse.jface.text.Position in project eclipse.platform.text by eclipse.
the class LineConversionTest method testConvertToCharacter.
public void testConvertToCharacter() throws Exception {
SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), fFile);
ITextFileBuffer fb = FileBuffers.getTextFileBufferManager().getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
IDocument doc = fb.getDocument();
Position p1 = new Position(2, 1);
Position p2 = PositionTracker.convertToCharacterPosition(p1, doc);
// assertEquals(LINE_THREE, doc.get(p2.getOffset(), p2.getLength()));
assertEquals(p1, PositionTracker.convertToLinePosition(p2, doc));
p1 = new Position(0, 1);
p2 = PositionTracker.convertToCharacterPosition(p1, doc);
assertEquals(LINE_ONE, doc.get(p2.getOffset(), p2.getLength()));
assertEquals(p1, PositionTracker.convertToLinePosition(p2, doc));
p1 = new Position(1, 1);
p2 = PositionTracker.convertToCharacterPosition(p1, doc);
assertEquals(LINE_TWO, doc.get(p2.getOffset(), p2.getLength()));
assertEquals(p1, PositionTracker.convertToLinePosition(p2, doc));
p1 = new Position(0, 0);
p2 = PositionTracker.convertToCharacterPosition(p1, doc);
assertEquals("", doc.get(p2.getOffset(), p2.getLength()));
assertEquals(p1, PositionTracker.convertToLinePosition(p2, doc));
}
use of org.eclipse.jface.text.Position in project eclipse.platform.text by eclipse.
the class DocumentUndoManagerTest method doChange.
private void doChange(IDocument document, int count) {
try {
String before = document.get();
if (DEBUG)
System.out.println(before);
Position[] positions = new Position[count];
String[] strings = new String[count];
for (int i = 0; i < count; i++) {
final Position position = createRandomPositionPoisson(document.getLength());
final String string = createRandomStringPoisson();
document.replace(position.getOffset(), position.getLength(), string);
positions[i] = position;
strings[i] = string;
}
if (DEBUG) {
System.out.print("{ ");
for (int i = 0; i < count; i++) {
System.out.print(positions[i].getOffset());
System.out.print(", ");
System.out.print(positions[i].getLength());
System.out.print(", ");
}
System.out.println(" }");
System.out.print("{ ");
for (int i = 0; i < count; i++) {
System.out.print("\"");
System.out.print(strings[i]);
System.out.print("\", ");
}
System.out.println(" }");
}
} catch (BadLocationException e) {
assertTrue(false);
}
}
use of org.eclipse.jface.text.Position in project eclipse.platform.text by eclipse.
the class ExclusivePositionUpdaterTest method setUp.
@Before
public void setUp() throws Exception {
fUpdater = new DefaultPositionUpdater(CATEGORY);
fDoc = new Document("ccccccccccccccccccccccccccccccccccccccccccccc");
fPos = new Position(5, 5);
// 01234[fPo]0123456789
fDoc.addPositionUpdater(fUpdater);
fDoc.addPositionCategory(CATEGORY);
fDoc.addPosition(CATEGORY, fPos);
}
use of org.eclipse.jface.text.Position in project eclipse.platform.text by eclipse.
the class PositionUpdatingCornerCasesTest method testInsert.
@Test
public void testInsert() throws Exception {
fDocument = new Document("x-x-x-x-x-x-x-x-x-x-x");
fDocument.addPosition(new Position(0, 0));
fDocument.addPosition(new Position(0, 1));
fDocument.addPosition(new Position(5, 0));
fDocument.addPosition(new Position(5, 3));
fDocument.replace(0, 0, "yy");
Position[] positions = new Position[] { new Position(2, 1), new Position(2, 0), new Position(7, 3), new Position(7, 0) };
checkPositions(positions);
}
use of org.eclipse.jface.text.Position in project eclipse.platform.text by eclipse.
the class PositionUpdatingCornerCasesTest method testInsert2.
@Test
public void testInsert2() throws Exception {
fDocument = new Document("x-x-x-x-x-x-x-x-x-x-x");
fDocument.addPosition(new Position(0, 0));
fDocument.addPosition(new Position(0, 1));
fDocument.addPosition(new Position(4, 1));
fDocument.addPosition(new Position(5, 0));
fDocument.addPosition(new Position(5, 3));
fDocument.addPosition(new Position(10, 0));
fDocument.addPosition(new Position(10, 2));
fDocument.replace(5, 0, "yy");
Position[] positions = new Position[] { new Position(0, 1), new Position(0, 0), new Position(4, 1), new Position(7, 3), new Position(7, 0), new Position(12, 2), new Position(12, 0) };
checkPositions(positions);
}
Aggregations