use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.
the class DocumentTest method testEmptyDocumentLineCount.
public void testEmptyDocumentLineCount() {
WriteCommandAction.runWriteCommandAction(ourProject, () -> {
DocumentImpl document = new DocumentImpl("");
assertEquals(0, document.getLineCount());
document.insertString(0, "a");
assertEquals(1, document.getLineCount());
document.deleteString(0, 1);
assertEquals(0, document.getLineCount());
});
}
use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.
the class FoldingStressTest method testStress8.
public void testStress8() throws Exception {
DocumentImpl doc = new DocumentImpl("0123456789\n123456789\n23456789");
Editor editor = EditorFactory.getInstance().createEditor(doc);
try {
final FoldingModel model = editor.getFoldingModel();
model.runBatchFoldingOperation(() -> {
addAndCollapseFoldRegion(model, 0, 8, "/*...*/");
addAndCollapseFoldRegion(model, 10, 12, "/*...*/");
});
assertEquals(10, editor.logicalPositionToOffset(new LogicalPosition(0, 10)));
for (int line = 0; line <= 3; line++) {
for (int column = 0; column <= 100; column++) {
LogicalPosition log = new LogicalPosition(line, column);
editor.logicalToVisualPosition(log);
}
}
} finally {
EditorFactory.getInstance().releaseEditor(editor);
}
}
use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.
the class ChangesDiffCalculatorTest method doTest.
private static void doTest(@NotNull String before, @NotNull String current, @NotNull TextRange... expectedRanges) {
DocumentImpl beforeDocument = new DocumentImpl(before);
DocumentImpl currentDocument = new DocumentImpl(current);
List<TextRange> actualRanges = ChangesDiffCalculator.calculateDiff(beforeDocument, currentDocument);
assertEquals(Arrays.asList(expectedRanges), actualRanges);
}
use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.
the class LightPlatformCodeInsightTestCase method checkResultByTextWithoutPSI.
protected static void checkResultByTextWithoutPSI(final String message, @NotNull final Editor editor, @NotNull final String fileText, final boolean ignoreTrailingSpaces, final String filePath) {
ApplicationManager.getApplication().runWriteAction(() -> {
final Document fakeDocument = EditorFactory.getInstance().createDocument(fileText);
if (ignoreTrailingSpaces) {
((DocumentImpl) fakeDocument).stripTrailingSpaces(getProject());
}
EditorTestUtil.CaretAndSelectionState carets = EditorTestUtil.extractCaretAndSelectionMarkers(fakeDocument);
String newFileText = fakeDocument.getText();
String fileText1 = editor.getDocument().getText();
String failMessage = getMessage("Text mismatch", message);
if (filePath != null && !newFileText.equals(fileText1)) {
throw new FileComparisonFailure(failMessage, newFileText, fileText1, filePath);
}
assertEquals(failMessage, newFileText, fileText1);
EditorTestUtil.verifyCaretAndSelectionState(editor, carets, message);
});
}
use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.
the class LightPlatformCodeInsightTestCase method configureFromFileText.
/**
* Same as configureByFile but text is provided directly.
* @param fileName - name of the file.
* @param fileText - data file text.
* @param checkCaret - if true, if will be verified that file contains at least one caret or selection marker
*/
@NotNull
protected static Document configureFromFileText(@NonNls @NotNull final String fileName, @NonNls @NotNull final String fileText, boolean checkCaret) {
return new WriteCommandAction<Document>(null) {
@Override
protected void run(@NotNull Result<Document> result) throws Throwable {
final Document fakeDocument = new DocumentImpl(fileText);
EditorTestUtil.CaretAndSelectionState caretsState = EditorTestUtil.extractCaretAndSelectionMarkers(fakeDocument);
if (checkCaret) {
assertTrue("No caret specified in " + fileName, caretsState.hasExplicitCaret());
}
String newFileText = fakeDocument.getText();
Document document;
try {
document = setupFileEditorAndDocument(fileName, newFileText);
} catch (IOException e) {
throw new RuntimeException(e);
}
EditorTestUtil.setCaretsAndSelection(myEditor, caretsState);
setupEditorForInjectedLanguage();
result.setResult(document);
}
}.execute().getResultObject();
}
Aggregations