JetResolveTest -> JetLiteFixture
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
package org.jetbrains.jet.resolve;
|
||||
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
@@ -48,17 +46,7 @@ public class ExpectedResolveData {
|
||||
// this.nameToType = nameToType;
|
||||
}
|
||||
|
||||
public void extractData(final Document document) {
|
||||
new WriteCommandAction.Simple(null) {
|
||||
public void run() {
|
||||
doExtractData(document);
|
||||
}
|
||||
}.execute().throwException();
|
||||
}
|
||||
|
||||
private void doExtractData(Document document) {
|
||||
String text = document.getText();
|
||||
|
||||
public String extractData(String text) {
|
||||
Pattern pattern = Pattern.compile("(~[^~]+~)|(`[^`]+`)");
|
||||
while (true) {
|
||||
Matcher matcher = pattern.matcher(text);
|
||||
@@ -84,11 +72,11 @@ public class ExpectedResolveData {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
document.replaceString(start, matcher.end(), "");
|
||||
text = document.getText();
|
||||
text = text.substring(0, start) + text.substring(matcher.end());
|
||||
}
|
||||
|
||||
System.out.println(text);
|
||||
return text;
|
||||
}
|
||||
|
||||
public void checkResult(JetFile file) {
|
||||
|
||||
@@ -1,108 +1,29 @@
|
||||
package org.jetbrains.jet.resolve;
|
||||
|
||||
import com.intellij.codeHighlighting.Pass;
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzerSettings;
|
||||
import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
||||
import com.intellij.injected.editor.EditorWindow;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.vfs.VirtualFileFilter;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
|
||||
import com.intellij.testFramework.FileTreeAccessFilter;
|
||||
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetLiteFixture;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public abstract class ExtensibleResolveTestCase extends LightCodeInsightTestCase {
|
||||
private final FileTreeAccessFilter myJavaFilesFilter = new FileTreeAccessFilter();
|
||||
public abstract class ExtensibleResolveTestCase extends JetLiteFixture {
|
||||
private ExpectedResolveData expectedResolveData;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
expectedResolveData = getExpectedResolveData();
|
||||
((DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(getProject())).prepareForTest();
|
||||
DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(false);
|
||||
}
|
||||
|
||||
protected abstract ExpectedResolveData getExpectedResolveData();
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
((DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(getProject())).cleanupAfterTest(false); // has to cleanup by hand since light project does not get disposed any time soon
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void runTest() throws Throwable {
|
||||
final Throwable[] throwable = {null};
|
||||
CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
doRunTest();
|
||||
} catch (Throwable t) {
|
||||
throwable[0] = t;
|
||||
}
|
||||
}
|
||||
}, "", null);
|
||||
if (throwable[0] != null) {
|
||||
throw throwable[0];
|
||||
}
|
||||
}
|
||||
|
||||
protected void doTest(@NonNls String filePath, boolean checkWarnings, boolean checkInfos) throws Exception {
|
||||
configureByFile(filePath);
|
||||
doTestConfiguredFile(checkWarnings, checkInfos);
|
||||
}
|
||||
|
||||
protected void doTestConfiguredFile(boolean checkWarnings, boolean checkInfos) {
|
||||
getJavaFacade().setAssertOnFileLoadingFilter(VirtualFileFilter.NONE);
|
||||
|
||||
// ExpectedHighlightingData expectedData = new ExpectedHighlightingData(getEditor().getDocument(), checkWarnings, checkInfos);
|
||||
expectedResolveData.extractData(getEditor().getDocument());
|
||||
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
getFile().getText(); //to load text
|
||||
myJavaFilesFilter.allowTreeAccessForFile(getVFile());
|
||||
getJavaFacade().setAssertOnFileLoadingFilter(myJavaFilesFilter); // check repository work
|
||||
|
||||
Collection<HighlightInfo> infos = doHighlighting();
|
||||
|
||||
getJavaFacade().setAssertOnFileLoadingFilter(VirtualFileFilter.NONE);
|
||||
|
||||
expectedResolveData.checkResult((JetFile) getFile());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected List<HighlightInfo> doHighlighting() {
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
|
||||
int[] toIgnore = doFolding() ? ArrayUtil.EMPTY_INT_ARRAY : new int[]{Pass.UPDATE_FOLDING};
|
||||
Editor editor = getEditor();
|
||||
PsiFile file = getFile();
|
||||
if (editor instanceof EditorWindow) {
|
||||
editor = ((EditorWindow) editor).getDelegate();
|
||||
file = InjectedLanguageUtil.getTopLevelFile(file);
|
||||
}
|
||||
|
||||
return CodeInsightTestFixtureImpl.instantiateAndRun(file, editor, toIgnore, false);
|
||||
}
|
||||
|
||||
protected boolean doFolding() {
|
||||
return false;
|
||||
protected void doTest(@NonNls String filePath) throws Exception {
|
||||
String text = loadFile(filePath);
|
||||
text = expectedResolveData.extractData(text);
|
||||
JetFile jetFile = createPsiFile(new File(filePath).getName(), text);
|
||||
expectedResolveData.checkResult(jetFile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ public class JetResolveTest extends ExtensibleResolveTestCase {
|
||||
|
||||
@Override
|
||||
protected void runTest() throws Throwable {
|
||||
doTest(path, true, false);
|
||||
doTest(path);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
|
||||
Reference in New Issue
Block a user