JS: add decompiled text generated tests
This commit is contained in:
@@ -61,6 +61,7 @@ import org.jetbrains.kotlin.idea.debugger.AbstractSmartStepIntoTest
|
||||
import org.jetbrains.kotlin.idea.debugger.evaluate.*
|
||||
import org.jetbrains.kotlin.idea.decompiler.navigation.AbstractNavigateToLibrarySourceTest
|
||||
import org.jetbrains.kotlin.idea.decompiler.stubBuilder.AbstractClsStubBuilderTest
|
||||
import org.jetbrains.kotlin.idea.decompiler.textBuilder.AbstractDecompiledTextFromJsMetadataTest
|
||||
import org.jetbrains.kotlin.idea.decompiler.textBuilder.AbstractDecompiledTextTest
|
||||
import org.jetbrains.kotlin.idea.editor.quickDoc.AbstractJetQuickDocProviderTest
|
||||
import org.jetbrains.kotlin.idea.folding.AbstractKotlinFoldingTest
|
||||
@@ -594,6 +595,10 @@ fun main(args: Array<String>) {
|
||||
model("decompiler/decompiledText", pattern = """^([^\.]+)$""")
|
||||
}
|
||||
|
||||
testClass(javaClass<AbstractDecompiledTextFromJsMetadataTest>()) {
|
||||
model("decompiler/decompiledText", pattern = """^([^\.]+)$""", targetBackend = TargetBackend.JS)
|
||||
}
|
||||
|
||||
testClass(javaClass<AbstractClsStubBuilderTest>()) {
|
||||
model("decompiler/stubBuilder", extension = null, recursive = false)
|
||||
}
|
||||
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.decompiler.textBuilder
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.PsiErrorElement
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.PsiManager
|
||||
import com.intellij.psi.PsiRecursiveElementVisitor
|
||||
import com.intellij.testFramework.LightProjectDescriptor
|
||||
import com.intellij.testFramework.UsefulTestCase
|
||||
import org.jetbrains.kotlin.idea.test.JdkAndMockLibraryProjectDescriptor
|
||||
import org.jetbrains.kotlin.idea.test.JetLightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.kotlin.idea.test.JetLightProjectDescriptor
|
||||
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext
|
||||
import kotlin.test.fail
|
||||
|
||||
public abstract class AbstractDecompiledTextBaseTest(private val isJsLibrary: Boolean = false) : JetLightCodeInsightFixtureTestCase() {
|
||||
protected val TEST_DATA_PATH: String = PluginTestCaseBase.getTestDataPathBase() + "/decompiler/decompiledText"
|
||||
|
||||
protected val TEST_PACKAGE: String = "test"
|
||||
|
||||
protected abstract fun getFileToDecompile(): VirtualFile
|
||||
|
||||
protected abstract fun checkPsiFile(psiFile: PsiFile)
|
||||
|
||||
public fun doTest(path: String) {
|
||||
val fileToDecompile = getFileToDecompile()
|
||||
val psiFile = PsiManager.getInstance(getProject()).findFile(fileToDecompile)!!
|
||||
checkPsiFile(psiFile)
|
||||
UsefulTestCase.assertSameLinesWithFile(path.substring(0, path.length() - 1) + ".expected.kt", psiFile.getText())
|
||||
checkThatFileWasParsedCorrectly(psiFile)
|
||||
}
|
||||
|
||||
override fun getProjectDescriptor(): LightProjectDescriptor {
|
||||
if (isAllFilesPresentInTest()) {
|
||||
return JetLightProjectDescriptor.INSTANCE
|
||||
}
|
||||
return JdkAndMockLibraryProjectDescriptor(TEST_DATA_PATH + "/" + getTestName(false), false, isJsLibrary)
|
||||
}
|
||||
|
||||
private fun checkThatFileWasParsedCorrectly(clsFile: PsiFile) {
|
||||
clsFile.accept(object : PsiRecursiveElementVisitor() {
|
||||
override fun visitErrorElement(element: PsiErrorElement) {
|
||||
fail("Decompiled file should not contain error elements!\n${element.getElementTextWithContext()}")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.decompiler.textBuilder
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.PsiFile
|
||||
import org.jetbrains.kotlin.idea.decompiler.KotlinJavascriptMetaFile
|
||||
import org.jetbrains.kotlin.idea.js.KotlinJavaScriptLibraryManager
|
||||
import org.jetbrains.kotlin.idea.test.ModuleKind
|
||||
import org.jetbrains.kotlin.idea.test.configureAs
|
||||
import org.jetbrains.kotlin.idea.vfilefinder.JsVirtualFileFinder
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
public abstract class AbstractDecompiledTextFromJsMetadataTest : AbstractDecompiledTextBaseTest(true) {
|
||||
|
||||
protected override fun getFileToDecompile(): VirtualFile {
|
||||
val className = getTestName(false)
|
||||
val virtualFileFinder = JsVirtualFileFinder.SERVICE.getInstance(getProject())
|
||||
val classId = ClassId(FqName(TEST_PACKAGE), FqName(className), false)
|
||||
return virtualFileFinder.findVirtualFileWithHeader(classId)!!
|
||||
}
|
||||
|
||||
protected override fun checkPsiFile(psiFile: PsiFile) =
|
||||
assertTrue(psiFile is KotlinJavascriptMetaFile, "Expecting decompiled kotlin javascript file, was: " + psiFile.javaClass)
|
||||
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
myModule!!.configureAs(ModuleKind.KOTLIN_JAVASCRIPT)
|
||||
KotlinJavaScriptLibraryManager.getInstance(getProject()).syncUpdateProjectLibrary()
|
||||
}
|
||||
}
|
||||
+8
-37
@@ -16,46 +16,17 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.decompiler.textBuilder
|
||||
|
||||
import com.intellij.psi.PsiManager
|
||||
import com.intellij.testFramework.LightProjectDescriptor
|
||||
import org.jetbrains.kotlin.idea.test.JdkAndMockLibraryProjectDescriptor
|
||||
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
|
||||
import com.intellij.testFramework.UsefulTestCase.*
|
||||
import org.junit.Assert.*
|
||||
import org.jetbrains.kotlin.idea.test.JetLightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.kotlin.idea.test.JetLightProjectDescriptor
|
||||
import org.jetbrains.kotlin.idea.decompiler.navigation.NavigateToDecompiledLibraryTest
|
||||
import com.intellij.psi.PsiRecursiveElementVisitor
|
||||
import com.intellij.psi.PsiErrorElement
|
||||
import org.jetbrains.kotlin.psi.JetPsiUtil
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.PsiFile
|
||||
import org.jetbrains.kotlin.idea.decompiler.JetClsFile
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext
|
||||
import org.jetbrains.kotlin.idea.decompiler.navigation.NavigateToDecompiledLibraryTest
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
public abstract class AbstractDecompiledTextTest() : JetLightCodeInsightFixtureTestCase() {
|
||||
public abstract class AbstractDecompiledTextTest() : AbstractDecompiledTextBaseTest() {
|
||||
|
||||
private val TEST_DATA_PATH = PluginTestCaseBase.getTestDataPathBase() + "/decompiler/decompiledText"
|
||||
protected override fun getFileToDecompile(): VirtualFile =
|
||||
NavigateToDecompiledLibraryTest.getClassFile(TEST_PACKAGE, getTestName(false), myModule!!)
|
||||
|
||||
public fun doTest(path: String) {
|
||||
val classFile = NavigateToDecompiledLibraryTest.getClassFile("test", getTestName(false), myModule!!)
|
||||
val clsFile = PsiManager.getInstance(getProject()!!).findFile(classFile)
|
||||
assertTrue("Expecting decompiled kotlin file, was: " + clsFile!!.javaClass, clsFile is JetClsFile)
|
||||
assertSameLinesWithFile(path.substring(0, path.length - 1) + ".expected.kt", clsFile.getText())
|
||||
checkThatFileWasParsedCorrectly(clsFile)
|
||||
}
|
||||
|
||||
override fun getProjectDescriptor(): LightProjectDescriptor {
|
||||
if (isAllFilesPresentInTest()) {
|
||||
return JetLightProjectDescriptor.INSTANCE
|
||||
}
|
||||
return JdkAndMockLibraryProjectDescriptor(TEST_DATA_PATH + "/" + getTestName(false), false)
|
||||
}
|
||||
|
||||
private fun checkThatFileWasParsedCorrectly(clsFile: PsiFile) {
|
||||
clsFile.accept(object : PsiRecursiveElementVisitor() {
|
||||
override fun visitErrorElement(element: PsiErrorElement) {
|
||||
fail("Decompiled file should not contain error elements!\n${element.getElementTextWithContext()}")
|
||||
}
|
||||
})
|
||||
}
|
||||
protected override fun checkPsiFile(psiFile: PsiFile) =
|
||||
assertTrue(psiFile is JetClsFile, "Expecting decompiled kotlin file, was: " + psiFile.javaClass)
|
||||
}
|
||||
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.decompiler.textBuilder;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.kotlin.test.JetTestUtils;
|
||||
import org.jetbrains.kotlin.test.TestMetadata;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("idea/testData/decompiler/decompiledText")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class DecompiledTextFromJsMetadataTestGenerated extends AbstractDecompiledTextFromJsMetadataTest {
|
||||
@TestMetadata("DependencyOnNestedClasses")
|
||||
public void ignoredDependencyOnNestedClasses() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/DependencyOnNestedClasses/");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("FlexibleTypes")
|
||||
public void ignoredFlexibleTypes() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/FlexibleTypes/");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NestedClasses")
|
||||
public void ignoredNestedClasses() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/NestedClasses/");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SecondaryConstructors")
|
||||
public void ignoredSecondaryConstructors() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/SecondaryConstructors/");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInDecompiledText() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/decompiler/decompiledText"), Pattern.compile("^([^\\.]+)$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("Annotations")
|
||||
public void testAnnotations() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/Annotations/");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("AnnotationsOnPrimaryCtr")
|
||||
public void testAnnotationsOnPrimaryCtr() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/AnnotationsOnPrimaryCtr/");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ClassWithClassObject")
|
||||
public void testClassWithClassObject() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/ClassWithClassObject/");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("Enum")
|
||||
public void testEnum() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/Enum/");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("FunctionTypes")
|
||||
public void testFunctionTypes() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/FunctionTypes/");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("Object")
|
||||
public void testObject() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/Object/");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SimpleClass")
|
||||
public void testSimpleClass() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/SimpleClass/");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("TestPackage")
|
||||
public void testTestPackage() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/TestPackage/");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user