add KotlinJavaScriptStubConsistencyTest
This commit is contained in:
+11
-21
@@ -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<FqName> = 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
|
||||
}
|
||||
|
||||
+48
@@ -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<FqName> = 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
|
||||
}
|
||||
+55
@@ -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<FqName>
|
||||
|
||||
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())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user