From 32ecdfede0e096c03e648932a2fa30ed579a0a5e Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Wed, 26 Feb 2014 17:02:21 +0400 Subject: [PATCH] Decompiler: Test that checks consistency between project-based and non-project-based decompilers --- .../DecompiledTextConsistencyTest.kt | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 idea/tests/org/jetbrains/jet/plugin/libraries/DecompiledTextConsistencyTest.kt diff --git a/idea/tests/org/jetbrains/jet/plugin/libraries/DecompiledTextConsistencyTest.kt b/idea/tests/org/jetbrains/jet/plugin/libraries/DecompiledTextConsistencyTest.kt new file mode 100644 index 00000000000..dd0cf7d50fe --- /dev/null +++ b/idea/tests/org/jetbrains/jet/plugin/libraries/DecompiledTextConsistencyTest.kt @@ -0,0 +1,52 @@ +/* + * Copyright 2010-2014 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.jet.plugin.libraries + +import org.jetbrains.jet.plugin.JetLightCodeInsightFixtureTestCase +import com.intellij.testFramework.LightProjectDescriptor +import org.jetbrains.jet.plugin.JetWithJdkAndRuntimeLightProjectDescriptor +import org.jetbrains.jet.lang.resolve.name.FqName +import org.junit.Assert +import org.jetbrains.jet.plugin.JetJdkAndLibraryProjectDescriptor +import org.jetbrains.jet.jvm.compiler.longTest.ResolveDescriptorsFromExternalLibraries +import org.jetbrains.jet.plugin.JetLightProjectDescriptor +import com.intellij.openapi.projectRoots.Sdk +import org.jetbrains.jet.plugin.PluginTestCaseBase +import org.jetbrains.jet.lang.resolve.java.PackageClassUtils + +public class DecompiledTextConsistencyTest : JetLightCodeInsightFixtureTestCase() { + + private val STANDARD_LIBRARY_FQNAME = FqName("kotlin") + + public fun testConsistencyWithJavaDescriptorResolver() { + val packageClassFqName = PackageClassUtils.getPackageClassFqName(STANDARD_LIBRARY_FQNAME) + val kotlinPackageClass = myFixture!!.getJavaFacade()!!.findClass(packageClassFqName.asString())!! + val kotlinPackageFile = kotlinPackageClass.getContainingFile()!!.getVirtualFile()!! + val project = getProject()!! + val projectBasedText = buildDecompiledData(kotlinPackageFile, project, ProjectBasedResolverForDecompiler(project)).getFileText() + val deserializerForDecompiler = DeserializerForDecompiler(kotlinPackageFile.getParent()!!, STANDARD_LIBRARY_FQNAME) + val deserializedText = buildDecompiledData(kotlinPackageFile, project, deserializerForDecompiler).getFileText() + Assert.assertEquals(projectBasedText, deserializedText) + // sanity checks + Assert.assertTrue(projectBasedText.contains("linkedListOf")) + Assert.assertFalse(projectBasedText.contains("ERROR")) + } + + override fun getProjectDescriptor() = object : JetWithJdkAndRuntimeLightProjectDescriptor() { + override fun getSdk() = PluginTestCaseBase.fullJdk() + } +}