Introduce utility method for working with multifile tests
This commit is contained in:
@@ -16,4 +16,22 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.test.util
|
package org.jetbrains.jet.test.util
|
||||||
|
|
||||||
fun String.removeTrailingWhitespacesFromEachLine() = split('\n') map { it.trimTrailing() } makeString ("\n")
|
import com.intellij.testFramework.fixtures.CodeInsightTestFixture
|
||||||
|
import com.intellij.openapi.util.io.FileUtil
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
public fun String.removeTrailingWhitespacesFromEachLine(): String = split('\n') map { it.trimTrailing() } makeString ("\n")
|
||||||
|
|
||||||
|
public fun CodeInsightTestFixture.configureWithExtraFile(path: String, extraNamePart: String = ".Data") {
|
||||||
|
val noExtensionPath = FileUtil.getNameWithoutExtension(path)
|
||||||
|
val extraPath = array("kt", "java").stream()
|
||||||
|
.map { ext -> "$noExtensionPath$extraNamePart.$ext" }
|
||||||
|
.firstOrNull { extraPath -> File(extraPath).exists() }
|
||||||
|
|
||||||
|
if (extraPath != null) {
|
||||||
|
configureByFiles(path, extraPath)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
configureByFile(path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2013 JetBrains s.r.o.
|
* Copyright 2010-2014 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -23,30 +23,19 @@ import org.jetbrains.jet.plugin.PluginTestCaseBase
|
|||||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||||
import org.testng.Assert
|
import org.testng.Assert
|
||||||
import com.intellij.openapi.util.io.FileUtil
|
import com.intellij.openapi.util.io.FileUtil
|
||||||
|
import org.jetbrains.jet.test.util.configureWithExtraFile
|
||||||
|
|
||||||
public abstract class AbstractCompletionWeigherTest() : LightCodeInsightFixtureTestCase() {
|
public abstract class AbstractCompletionWeigherTest() : LightCodeInsightFixtureTestCase() {
|
||||||
fun doTest(path: String) {
|
fun doTest(path: String) {
|
||||||
val fixture = myFixture!!
|
myFixture.configureWithExtraFile(path)
|
||||||
|
|
||||||
val testFile = File(path)
|
val text = myFixture.getEditor().getDocument().getText()
|
||||||
|
|
||||||
val dataFileName = FileUtil.getNameWithoutExtension(testFile) + ".Data.kt"
|
|
||||||
val dataFile = File(testFile.getParent(), dataFileName)
|
|
||||||
|
|
||||||
if (dataFile.exists()) {
|
|
||||||
fixture.configureByFiles(path, FileUtil.toSystemIndependentName(dataFile.getPath()))
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
fixture.configureByFile(path)
|
|
||||||
}
|
|
||||||
|
|
||||||
val text = fixture.getEditor()!!.getDocument().getText()
|
|
||||||
|
|
||||||
val items = InTextDirectivesUtils.findArrayWithPrefixes(text, "// ORDER:")
|
val items = InTextDirectivesUtils.findArrayWithPrefixes(text, "// ORDER:")
|
||||||
Assert.assertTrue(!items.isEmpty(), """Some items should be defined with "// ORDER:" directive""")
|
Assert.assertTrue(!items.isEmpty(), """Some items should be defined with "// ORDER:" directive""")
|
||||||
|
|
||||||
fixture.complete(CompletionType.BASIC, InTextDirectivesUtils.getPrefixedInt(text, "// INVOCATION_COUNT:") ?: 1)
|
myFixture.complete(CompletionType.BASIC, InTextDirectivesUtils.getPrefixedInt(text, "// INVOCATION_COUNT:") ?: 1)
|
||||||
fixture.assertPreferredCompletionItems(InTextDirectivesUtils.getPrefixedInt(text, "// SELECTED:") ?: 0, *items)
|
myFixture.assertPreferredCompletionItems(InTextDirectivesUtils.getPrefixedInt(text, "// SELECTED:") ?: 0, *items)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override fun getTestDataPath() : String? {
|
protected override fun getTestDataPath() : String? {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2013 JetBrains s.r.o.
|
* Copyright 2010-2014 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -34,6 +34,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.InTextDirectivesUtils;
|
import org.jetbrains.jet.InTextDirectivesUtils;
|
||||||
import org.jetbrains.jet.plugin.ProjectDescriptorWithStdlibSources;
|
import org.jetbrains.jet.plugin.ProjectDescriptorWithStdlibSources;
|
||||||
|
import org.jetbrains.jet.test.util.UtilPackage;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -41,7 +42,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public abstract class AbstractJetQuickDocProviderTest extends LightCodeInsightFixtureTestCase {
|
public abstract class AbstractJetQuickDocProviderTest extends LightCodeInsightFixtureTestCase {
|
||||||
public void doTest(@NotNull String path) throws Exception {
|
public void doTest(@NotNull String path) throws Exception {
|
||||||
myFixture.configureByFiles(ArrayUtil.toStringArray(getTestFiles(path)));
|
UtilPackage.configureWithExtraFile(myFixture, path, "_Data");
|
||||||
|
|
||||||
PsiElement element = myFixture.getFile().findElementAt(myFixture.getEditor().getCaretModel().getOffset());
|
PsiElement element = myFixture.getFile().findElementAt(myFixture.getEditor().getCaretModel().getOffset());
|
||||||
assertNotNull("Can't find element at caret in file: " + path, element);
|
assertNotNull("Can't find element at caret in file: " + path, element);
|
||||||
@@ -85,29 +86,4 @@ public abstract class AbstractJetQuickDocProviderTest extends LightCodeInsightFi
|
|||||||
protected LightProjectDescriptor getProjectDescriptor() {
|
protected LightProjectDescriptor getProjectDescriptor() {
|
||||||
return ProjectDescriptorWithStdlibSources.INSTANCE;
|
return ProjectDescriptorWithStdlibSources.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private static Collection<String> getTestFiles(@NotNull String path) {
|
|
||||||
File testFile = new File(path);
|
|
||||||
String testFileName = FileUtil.getNameWithoutExtension(testFile);
|
|
||||||
|
|
||||||
List<String> filePaths = Lists.newArrayList();
|
|
||||||
|
|
||||||
filePaths.add(path);
|
|
||||||
|
|
||||||
filePaths.add(checkDataFileWithSuffix(testFile, testFileName, "_Data.kt"));
|
|
||||||
filePaths.add(checkDataFileWithSuffix(testFile, testFileName, "_Data.java"));
|
|
||||||
|
|
||||||
return Collections2.filter(filePaths, Predicates.notNull());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String checkDataFileWithSuffix(File testFile, String testFileName, String dataFileSuffix) {
|
|
||||||
String ktDataFileName = testFileName + dataFileSuffix;
|
|
||||||
File ktDataFile = new File(testFile.getParent(), ktDataFileName);
|
|
||||||
if (ktDataFile.exists()) {
|
|
||||||
return FileUtil.normalize(ktDataFile.getPath());
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2013 JetBrains s.r.o.
|
* Copyright 2010-2014 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -30,6 +30,7 @@ import junit.framework.Assert;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.InTextDirectivesUtils;
|
import org.jetbrains.jet.InTextDirectivesUtils;
|
||||||
import org.jetbrains.jet.plugin.JetWithJdkAndRuntimeLightProjectDescriptor;
|
import org.jetbrains.jet.plugin.JetWithJdkAndRuntimeLightProjectDescriptor;
|
||||||
|
import org.jetbrains.jet.test.util.UtilPackage;
|
||||||
import org.jetbrains.jet.testing.ReferenceUtils;
|
import org.jetbrains.jet.testing.ReferenceUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -65,14 +66,7 @@ public abstract class AbstractReferenceResolveTest extends LightPlatformCodeInsi
|
|||||||
|
|
||||||
protected void doTest(String path) {
|
protected void doTest(String path) {
|
||||||
assert path.endsWith(".kt") : path;
|
assert path.endsWith(".kt") : path;
|
||||||
String extraFile = path.replace(".kt", ".Data.kt");
|
UtilPackage.configureWithExtraFile(myFixture, path, ".Data");
|
||||||
if (new File(extraFile).exists()) {
|
|
||||||
myFixture.configureByFiles(path, extraFile);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
myFixture.configureByFile(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
performChecks();
|
performChecks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user