mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
moving xml-tests to community: getting rid of ultimate dependencies
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
package com.intellij.psi;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.psi.impl.DebugUtil;
|
||||
import com.intellij.psi.impl.source.SourceTreeToPsiMap;
|
||||
import com.intellij.psi.text.BlockSupport;
|
||||
import com.intellij.testFramework.PsiTestCase;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
/**
|
||||
* @author maxim
|
||||
*/
|
||||
public abstract class AbstractReparseTestCase extends PsiTestCase {
|
||||
protected FileType myFileType;
|
||||
protected PsiFile myDummyFile;
|
||||
private int myInsertOffset;
|
||||
|
||||
protected void setFileType(final FileType fileType) {
|
||||
myFileType = fileType;
|
||||
}
|
||||
|
||||
protected void insert(@NonNls final String s) throws IncorrectOperationException {
|
||||
CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String oldText = myDummyFile.getText();
|
||||
String expectedNewText = oldText.substring(0, myInsertOffset) + s + oldText.substring(myInsertOffset);
|
||||
|
||||
try {
|
||||
doReparse(s, expectedNewText, 0);
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
myInsertOffset += s.length();
|
||||
}
|
||||
});
|
||||
}
|
||||
}, "asd", null);
|
||||
}
|
||||
|
||||
protected void moveEditPointLeft(int count) {
|
||||
myInsertOffset -= count;
|
||||
}
|
||||
|
||||
protected void moveEditPointRight(int count) {
|
||||
myInsertOffset += count;
|
||||
}
|
||||
|
||||
protected void setEditPoint(int pos) {
|
||||
myInsertOffset = pos;
|
||||
}
|
||||
|
||||
protected void remove(int count) throws IncorrectOperationException {
|
||||
String oldText = myDummyFile.getText();
|
||||
String expectedNewText = oldText.substring(0, myInsertOffset-count) + oldText.substring(myInsertOffset);
|
||||
|
||||
doReparse("", expectedNewText, count);
|
||||
myInsertOffset -= count;
|
||||
}
|
||||
|
||||
protected void doReparse(final String s, final String expectedNewText, final int length) throws IncorrectOperationException {
|
||||
CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
BlockSupport blockSupport = ServiceManager.getService(myProject, BlockSupport.class);
|
||||
try {
|
||||
blockSupport.reparseRange(myDummyFile, myInsertOffset - length, myInsertOffset, s);
|
||||
String foundStructure = DebugUtil.treeToString(SourceTreeToPsiMap.psiElementToTree(myDummyFile), false);
|
||||
final PsiFile psiFile = createDummyFile(getName() + "." + myFileType.getDefaultExtension(), expectedNewText);
|
||||
String expectedStructure = DebugUtil.treeToString(SourceTreeToPsiMap.psiElementToTree(psiFile), false);
|
||||
if (!expectedStructure.equals(foundStructure)) {
|
||||
System.out.println("expected: ");
|
||||
System.out.println(expectedStructure);
|
||||
System.out.println("found: ");
|
||||
System.out.println(foundStructure);
|
||||
assertEquals(expectedStructure, foundStructure);
|
||||
}
|
||||
|
||||
assertEquals("Reparse tree should be equal to the document",expectedNewText,myDummyFile.getText());
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}, "asd", null);
|
||||
}
|
||||
|
||||
protected void prepareFile(@NonNls String prefix, @NonNls String suffix) throws IncorrectOperationException {
|
||||
myDummyFile = createDummyFile(getName() + "." + myFileType.getDefaultExtension(), prefix + suffix);
|
||||
myInsertOffset = prefix.length();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user