New J2K: Add test with structural compare and cleanup duplicated code in tests
This commit is contained in:
committed by
Ilya Kirillov
parent
ac20e9ba83
commit
b12a91c111
@@ -968,6 +968,10 @@ fun main(args: Array<String>) {
|
||||
model("fileOrElement", extension = "java")
|
||||
}
|
||||
|
||||
testClass<AbstractNewJavaToKotlinConverterStructureSingleFileTest> {
|
||||
model("fileOrElement", extension = "java")
|
||||
}
|
||||
|
||||
testClass<AbstractNewJavaToKotlinConverterNewSingleFileTest> {
|
||||
model("newFileOrElement", extension = "java")
|
||||
}
|
||||
|
||||
@@ -937,6 +937,20 @@ fun main(args: Array<String>) {
|
||||
model("fileOrElement", extension = "java")
|
||||
}
|
||||
}
|
||||
|
||||
testGroup("j2k/tests", "j2k/testData") {
|
||||
testClass<AbstractNewJavaToKotlinConverterSingleFileTest> {
|
||||
model("fileOrElement", extension = "java")
|
||||
}
|
||||
|
||||
testClass<AbstractNewJavaToKotlinConverterStructureSingleFileTest> {
|
||||
model("fileOrElement", extension = "java")
|
||||
}
|
||||
|
||||
testClass<AbstractNewJavaToKotlinConverterNewSingleFileTest> {
|
||||
model("newFileOrElement", extension = "java")
|
||||
}
|
||||
}
|
||||
/* There is no jps in AS
|
||||
....
|
||||
*/
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.j2k
|
||||
|
||||
import com.intellij.openapi.command.WriteCommandAction
|
||||
import com.intellij.openapi.fileEditor.impl.LoadTextUtil
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.psi.PsiJavaFile
|
||||
@@ -79,6 +80,11 @@ abstract class AbstractJavaToKotlinConverterSingleFileTest : AbstractJavaToKotli
|
||||
|
||||
val kotlinPath = javaPath.replace(".java", ".kt")
|
||||
val expectedFile = File(kotlinPath)
|
||||
|
||||
compareResults(expectedFile, actual)
|
||||
}
|
||||
|
||||
open fun compareResults(expectedFile: File, actual: String) {
|
||||
KotlinTestUtils.assertEqualsToFile(expectedFile, actual)
|
||||
}
|
||||
|
||||
|
||||
+1
-24
@@ -16,27 +16,4 @@
|
||||
|
||||
package org.jetbrains.kotlin.j2k
|
||||
|
||||
import com.intellij.openapi.command.CommandProcessor
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.idea.j2k.IdeaNewJavaToKotlinServices
|
||||
import org.jetbrains.kotlin.idea.j2k.J2kPostProcessor
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
|
||||
abstract class AbstractNewJavaToKotlinConverterNewSingleFileTest : AbstractJavaToKotlinConverterSingleFileTest() {
|
||||
|
||||
override fun fileToKotlin(text: String, settings: ConverterSettings, project: Project): String {
|
||||
val file = createJavaFile(text)
|
||||
val factory = KtPsiFactory(project, true)
|
||||
val postProcessor = J2kPostProcessor(true)
|
||||
|
||||
|
||||
return NewJavaToKotlinConverter(project, settings, IdeaNewJavaToKotlinServices).filesToKotlin(listOf(file)).map {
|
||||
factory.createFileWithLightClassSupport("Dummy.kt", it, file)
|
||||
}.map {
|
||||
CommandProcessor.getInstance().runUndoTransparentAction {
|
||||
postProcessor.doAdditionalProcessing(it, null)
|
||||
}
|
||||
it.text
|
||||
}.single()
|
||||
}
|
||||
}
|
||||
abstract class AbstractNewJavaToKotlinConverterNewSingleFileTest : AbstractNewJavaToKotlinConverterSingleFileTest()
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.j2k
|
||||
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import java.io.File
|
||||
|
||||
|
||||
abstract class AbstractNewJavaToKotlinConverterStructureSingleFileTest : AbstractNewJavaToKotlinConverterSingleFileTest() {
|
||||
|
||||
override fun compareResults(expectedFile: File, actual: String) {
|
||||
KotlinTestUtils.assertEqualsToFile(expectedFile, actual) {
|
||||
val file = createKotlinFile(it)
|
||||
file.dumpStructureText()
|
||||
}
|
||||
}
|
||||
}
|
||||
Generated
+12
-17
@@ -1,17 +1,6 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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.
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.j2k;
|
||||
@@ -32,6 +21,10 @@ import java.util.regex.Pattern;
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class NewJavaToKotlinConverterNewSingleFileTestGenerated extends AbstractNewJavaToKotlinConverterNewSingleFileTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInNewFileOrElement() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("j2k/testData/newFileOrElement"), Pattern.compile("^(.+)\\.java$"), TargetBackend.ANY, true);
|
||||
}
|
||||
@@ -40,20 +33,22 @@ public class NewJavaToKotlinConverterNewSingleFileTestGenerated extends Abstract
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class First extends AbstractNewJavaToKotlinConverterNewSingleFileTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInFirst() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("j2k/testData/newFileOrElement/first"), Pattern.compile("^(.+)\\.java$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("First.java")
|
||||
public void testFirst() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/newFileOrElement/first/First.java");
|
||||
doTest(fileName);
|
||||
runTest("j2k/testData/newFileOrElement/first/First.java");
|
||||
}
|
||||
|
||||
@TestMetadata("Modifiers.java")
|
||||
public void testModifiers() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/newFileOrElement/first/Modifiers.java");
|
||||
doTest(fileName);
|
||||
runTest("j2k/testData/newFileOrElement/first/Modifiers.java");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1067
-1505
File diff suppressed because it is too large
Load Diff
Generated
+4751
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.j2k
|
||||
|
||||
import com.intellij.psi.PsiComment
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiElementVisitor
|
||||
import com.intellij.psi.PsiWhiteSpace
|
||||
import com.intellij.psi.impl.source.tree.LeafPsiElement
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
|
||||
internal fun KtFile.dumpStructureText(): String {
|
||||
val sb = StringBuilder()
|
||||
this.accept(object : PsiElementVisitor() {
|
||||
override fun visitElement(element: PsiElement?) {
|
||||
if (element is PsiComment) {
|
||||
return
|
||||
}
|
||||
if (element is PsiWhiteSpace) {
|
||||
sb.append(" ")
|
||||
return
|
||||
}
|
||||
if (element is LeafPsiElement) {
|
||||
sb.append(element.text)
|
||||
return
|
||||
}
|
||||
element?.acceptChildren(this)
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
return sb.toString()
|
||||
}
|
||||
Reference in New Issue
Block a user