Inline KotlinLiteFixture#loadFile, refactor surroundings
This commit is contained in:
@@ -29,15 +29,16 @@ import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil;
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind;
|
||||
import org.jetbrains.kotlin.test.KotlinLiteFixture;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class CheckerTestUtilTest extends KotlinLiteFixture {
|
||||
|
||||
public CheckerTestUtilTest() {
|
||||
super("diagnostics/checkerTestUtil");
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return KotlinTestUtils.getTestDataPathBase() + "/diagnostics/checkerTestUtil";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,10 +46,9 @@ public class CheckerTestUtilTest extends KotlinLiteFixture {
|
||||
return createEnvironmentWithMockJdk(ConfigurationKind.ALL);
|
||||
}
|
||||
|
||||
|
||||
protected void doTest(TheTest theTest) throws Exception {
|
||||
prepareForTest("test");
|
||||
theTest.test(getFile());
|
||||
String text = KotlinTestUtils.doLoadFile(getTestDataPath(), "test.kt");
|
||||
theTest.test(createCheckAndReturnPsiFile("test", null, text));
|
||||
}
|
||||
|
||||
public void testEquals() throws Exception {
|
||||
@@ -132,7 +132,7 @@ public class CheckerTestUtilTest extends KotlinLiteFixture {
|
||||
AbstractDiagnosticsTest test = new AbstractDiagnosticsTest() {
|
||||
{setUp();}
|
||||
};
|
||||
test.doTest(myFullDataPath + File.separatorChar + "test_with_diagnostic.kt");
|
||||
test.doTest(getTestDataPath() + File.separatorChar + "test_with_diagnostic.kt");
|
||||
}
|
||||
|
||||
private static abstract class TheTest {
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.psi;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration;
|
||||
@@ -25,6 +26,7 @@ import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.resolve.ImportPath;
|
||||
import org.jetbrains.kotlin.test.KotlinLiteFixture;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.io.File;
|
||||
@@ -34,6 +36,16 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class KtPsiUtilTest extends KotlinLiteFixture {
|
||||
@NotNull
|
||||
private KtFile loadPsiFile(@NotNull String name) {
|
||||
try {
|
||||
return createPsiFile(name, null, KotlinTestUtils.doLoadFile(getTestDataPath(), name));
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void testUnquotedIdentifier() {
|
||||
Assert.assertEquals("", KtPsiUtil.unquoteIdentifier(""));
|
||||
Assert.assertEquals("a2", KtPsiUtil.unquoteIdentifier("a2"));
|
||||
|
||||
+2
-2
@@ -58,7 +58,7 @@ abstract class AbstractConstraintSystemTest() : KotlinLiteFixture() {
|
||||
override fun tearDown() {
|
||||
_typeResolver = null
|
||||
_testDeclarations = null
|
||||
super<KotlinLiteFixture>.tearDown()
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
override fun getTestDataPath(): String {
|
||||
@@ -68,7 +68,7 @@ abstract class AbstractConstraintSystemTest() : KotlinLiteFixture() {
|
||||
private fun analyzeDeclarations(): ConstraintSystemTestData {
|
||||
val fileName = "declarations.kt"
|
||||
|
||||
val psiFile = createPsiFile(null, fileName, loadFile(fileName))!!
|
||||
val psiFile = createPsiFile(null, fileName, KotlinTestUtils.doLoadFile(testDataPath, fileName))!!
|
||||
val bindingContext = JvmResolveUtil.analyzeOneFileWithJavaIntegrationAndCheckForErrors(psiFile).bindingContext
|
||||
return ConstraintSystemTestData(bindingContext, project, typeResolver)
|
||||
}
|
||||
|
||||
@@ -21,51 +21,17 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.testFramework.LightVirtualFile;
|
||||
import com.intellij.testFramework.TestDataFile;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.resolve.lazy.KotlinTestWithEnvironment;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class KotlinLiteFixture extends KotlinTestWithEnvironment {
|
||||
@NonNls
|
||||
protected final String myFullDataPath;
|
||||
private KtFile myFile;
|
||||
|
||||
public KotlinLiteFixture(@NonNls String dataPath) {
|
||||
myFullDataPath = getTestDataPath() + "/" + dataPath;
|
||||
}
|
||||
|
||||
public KotlinLiteFixture() {
|
||||
myFullDataPath = getTestDataPath();
|
||||
}
|
||||
|
||||
protected KtFile getFile() {
|
||||
return myFile;
|
||||
}
|
||||
|
||||
protected String getTestDataPath() {
|
||||
return KotlinTestUtils.getTestDataPathBase();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
myFile = null;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
protected String loadFile(@NonNls @TestDataFile String name) throws IOException {
|
||||
return KotlinTestUtils.doLoadFile(myFullDataPath, name);
|
||||
}
|
||||
|
||||
protected KtFile createPsiFile(@Nullable String testName, @Nullable String fileName, String text) {
|
||||
if (fileName == null) {
|
||||
Assert.assertNotNull(testName);
|
||||
@@ -74,37 +40,21 @@ public abstract class KotlinLiteFixture extends KotlinTestWithEnvironment {
|
||||
return KotlinTestUtils.createFile(fileName, text, getProject());
|
||||
}
|
||||
|
||||
protected KtFile loadPsiFile(String name) {
|
||||
try {
|
||||
return createPsiFile(name, null, loadFile(name));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void ensureParsed(PsiFile file) {
|
||||
private static void ensureParsed(PsiFile file) {
|
||||
file.accept(new PsiElementVisitor() {
|
||||
@Override
|
||||
public void visitElement(PsiElement element) {
|
||||
public void visitElement(@NotNull PsiElement element) {
|
||||
element.acceptChildren(this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void prepareForTest(String name) throws IOException {
|
||||
String text = loadFile(name + ".kt");
|
||||
createAndCheckPsiFile(name, text);
|
||||
}
|
||||
|
||||
protected void createAndCheckPsiFile(String name, String text) {
|
||||
myFile = createCheckAndReturnPsiFile(name, null, text);
|
||||
}
|
||||
|
||||
protected KtFile createCheckAndReturnPsiFile(String testName, String fileName, String text) {
|
||||
KtFile myFile = createPsiFile(testName, fileName, text);
|
||||
ensureParsed(myFile);
|
||||
assertEquals("light virtual file text mismatch", text, ((LightVirtualFile) myFile.getVirtualFile()).getContent().toString());
|
||||
assertEquals("virtual file text mismatch", text, LoadTextUtil.loadText(myFile.getVirtualFile()));
|
||||
//noinspection ConstantConditions
|
||||
assertEquals("doc text mismatch", text, myFile.getViewProvider().getDocument().getText());
|
||||
assertEquals("psi text mismatch", text, myFile.getText());
|
||||
return myFile;
|
||||
|
||||
@@ -51,17 +51,11 @@ import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
public class KotlinTypeCheckerTest extends KotlinLiteFixture {
|
||||
|
||||
private KotlinBuiltIns builtIns;
|
||||
private LexicalScope scopeWithImports;
|
||||
private TypeResolver typeResolver;
|
||||
private ExpressionTypingServices expressionTypingServices;
|
||||
|
||||
|
||||
public KotlinTypeCheckerTest() {
|
||||
super("");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected KotlinCoreEnvironment createEnvironment() {
|
||||
return createEnvironmentWithMockJdk(ConfigurationKind.ALL);
|
||||
@@ -71,7 +65,6 @@ public class KotlinTypeCheckerTest extends KotlinLiteFixture {
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
|
||||
ModuleDescriptorImpl module = KotlinTestUtils.createEmptyModule();
|
||||
builtIns = module.getBuiltIns();
|
||||
ContainerForTests container = InjectionKt.createContainerForTests(getProject(), module);
|
||||
|
||||
@@ -88,7 +88,7 @@ public abstract class AbstractDiagnosticMessageTest extends KotlinLiteFixture {
|
||||
final Set<DiagnosticFactory<?>> diagnosticFactories = getDiagnosticFactories(directives);
|
||||
MessageType messageType = getMessageTypeDirective(directives);
|
||||
|
||||
KtFile psiFile = createPsiFile(null, fileName, loadFile(fileName));
|
||||
KtFile psiFile = createPsiFile(null, fileName, KotlinTestUtils.doLoadFile(getTestDataPath(), fileName));
|
||||
AnalysisResult analysisResult = analyze(psiFile);
|
||||
BindingContext bindingContext = analysisResult.getBindingContext();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user