From 7978e0895eb21541cb4df41961e6492e156ba0da Mon Sep 17 00:00:00 2001 From: Michael Nedzelsky Date: Fri, 17 Apr 2015 14:02:45 +0300 Subject: [PATCH] add KotlinJavaScriptStubConsistencyTest --- .../stubBuilder/ClsStubConsistencyTest.kt | 32 ++++------- .../KotlinJavaScriptStubConsistencyTest.kt | 48 ++++++++++++++++ .../stubBuilder/StubConsistencyBaseTest.kt | 55 +++++++++++++++++++ 3 files changed, 114 insertions(+), 21 deletions(-) create mode 100644 idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/KotlinJavaScriptStubConsistencyTest.kt create mode 100644 idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/StubConsistencyBaseTest.kt diff --git a/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/ClsStubConsistencyTest.kt b/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/ClsStubConsistencyTest.kt index f2f45070310..882c9d2965f 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/ClsStubConsistencyTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/ClsStubConsistencyTest.kt @@ -16,35 +16,25 @@ package org.jetbrains.kotlin.idea.decompiler.stubBuilder -import com.intellij.util.indexing.FileContentImpl +import com.intellij.openapi.vfs.VirtualFile import org.jetbrains.kotlin.idea.decompiler.textBuilder.buildDecompiledText -import org.jetbrains.kotlin.idea.test.JetLightCodeInsightFixtureTestCase import org.jetbrains.kotlin.idea.test.JetWithJdkAndRuntimeLightProjectDescriptor import org.jetbrains.kotlin.load.kotlin.JvmVirtualFileFinder -import org.jetbrains.kotlin.load.kotlin.PackageClassUtils +import org.jetbrains.kotlin.load.kotlin.VirtualFileFinder import org.jetbrains.kotlin.name.FqName -import org.jetbrains.kotlin.psi.JetPsiFactory -import org.jetbrains.kotlin.psi.stubs.elements.JetFileStubBuilder -import org.junit.Assert +import kotlin.properties.Delegates -public class ClsStubConsistencyTest : JetLightCodeInsightFixtureTestCase() { +public class ClsStubConsistencyTest : StubConsistencyBaseTest() { - private val STANDARD_LIBRARY_FQNAME = FqName("kotlin") + override val packages: List = listOf(FqName("kotlin")) - public fun testConsistencyForKotlinPackage() { - val project = getProject() - val virtualFileFinder = JvmVirtualFileFinder.SERVICE.getInstance(getProject()) - val kotlinPackageFile = virtualFileFinder.findVirtualFileWithHeader(PackageClassUtils.getPackageClassId(STANDARD_LIBRARY_FQNAME))!! - - val decompiledText = buildDecompiledText(kotlinPackageFile).text - val clsStub = KotlinClsStubBuilder().buildFileStub(FileContentImpl.createByFile(kotlinPackageFile))!! - - val fileWithDecompiledText = JetPsiFactory(project).createFile(decompiledText) - val stubTreeFromDecompiledText = JetFileStubBuilder().buildStubTree(fileWithDecompiledText) - - val expectedText = stubTreeFromDecompiledText.serializeToString() - Assert.assertEquals(expectedText, clsStub.serializeToString()) + override val virtualFileFinder: VirtualFileFinder by Delegates.lazy() { + JvmVirtualFileFinder.SERVICE.getInstance(getProject()) } + override fun createStubBuilder() = KotlinClsStubBuilder() + + override fun getDecompiledText(packageFile: VirtualFile): String = buildDecompiledText(packageFile).text + override fun getProjectDescriptor() = JetWithJdkAndRuntimeLightProjectDescriptor.INSTANCE } diff --git a/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/KotlinJavaScriptStubConsistencyTest.kt b/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/KotlinJavaScriptStubConsistencyTest.kt new file mode 100644 index 00000000000..714f77616c4 --- /dev/null +++ b/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/KotlinJavaScriptStubConsistencyTest.kt @@ -0,0 +1,48 @@ +/* + * 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.stubBuilder + +import com.intellij.openapi.vfs.VirtualFile +import org.jetbrains.kotlin.idea.decompiler.textBuilder.buildDecompiledTextFromJsMetadata +import org.jetbrains.kotlin.idea.js.KotlinJavaScriptLibraryManager +import org.jetbrains.kotlin.idea.test.KotlinStdJSProjectDescriptor +import org.jetbrains.kotlin.idea.vfilefinder.JsVirtualFileFinder +import org.jetbrains.kotlin.load.kotlin.VirtualFileFinder +import org.jetbrains.kotlin.name.FqName +import kotlin.properties.Delegates + +public class KotlinJavaScriptStubConsistencyTest : StubConsistencyBaseTest() { + + override val packages: List = listOf( + "java.util", "jquery", "jquery.ui", "kotlin", "kotlin.browser", "kotlin.dom", "kotlin.js" + ).map { FqName(it) } + + override fun setUp() { + super.setUp() + KotlinJavaScriptLibraryManager.getInstance(getProject()).syncUpdateProjectLibrary() + } + + override val virtualFileFinder: VirtualFileFinder by Delegates.lazy() { + JsVirtualFileFinder.SERVICE.getInstance(getProject()) + } + + override fun createStubBuilder() = KotlinJavaScriptStubBuilder() + + override fun getDecompiledText(packageFile: VirtualFile): String = buildDecompiledTextFromJsMetadata(packageFile).text + + override fun getProjectDescriptor() = KotlinStdJSProjectDescriptor.instance +} diff --git a/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/StubConsistencyBaseTest.kt b/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/StubConsistencyBaseTest.kt new file mode 100644 index 00000000000..fef579eab6c --- /dev/null +++ b/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/StubConsistencyBaseTest.kt @@ -0,0 +1,55 @@ +/* + * 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.stubBuilder + +import com.intellij.openapi.vfs.VirtualFile +import com.intellij.psi.compiled.ClsStubBuilder +import com.intellij.util.indexing.FileContentImpl +import org.jetbrains.kotlin.idea.test.JetLightCodeInsightFixtureTestCase +import org.jetbrains.kotlin.load.kotlin.PackageClassUtils +import org.jetbrains.kotlin.load.kotlin.VirtualFileFinder +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.psi.JetPsiFactory +import org.jetbrains.kotlin.psi.stubs.elements.JetFileStubBuilder +import org.junit.Assert + +public abstract class StubConsistencyBaseTest : JetLightCodeInsightFixtureTestCase() { + + protected abstract val packages: List + + protected abstract val virtualFileFinder: VirtualFileFinder + + protected abstract fun createStubBuilder(): ClsStubBuilder + + protected abstract fun getDecompiledText(packageFile: VirtualFile): String + + public fun testConsistency() { + packages.forEach { doTest(it) } + } + + private fun doTest(packageFqName: FqName) { + val project = getProject() + val packageFile = virtualFileFinder.findVirtualFileWithHeader(PackageClassUtils.getPackageClassId(packageFqName))!! + val decompiledText = getDecompiledText(packageFile) + val fileWithDecompiledText = JetPsiFactory(project).createFile(decompiledText) + val stubTreeFromDecompiledText = JetFileStubBuilder().buildStubTree(fileWithDecompiledText) + val expectedText = stubTreeFromDecompiledText.serializeToString() + + val fileStub = createStubBuilder().buildFileStub(FileContentImpl.createByFile(packageFile))!! + Assert.assertEquals(expectedText, fileStub.serializeToString()) + } +} \ No newline at end of file