Add basic FIR -> IR converter with a set of text tests
Tests duplicate IrTextTestCaseGenerated #KT-24065 Fixed
This commit is contained in:
@@ -12,6 +12,7 @@ dependencies {
|
||||
testCompile(project(":compiler:backend"))
|
||||
testCompile(project(":compiler:fir:tree"))
|
||||
testCompile(project(":compiler:fir:psi2fir"))
|
||||
testCompile(project(":compiler:fir:fir2ir"))
|
||||
testCompile(project(":compiler:fir:cones"))
|
||||
testCompile(project(":compiler:fir:resolve"))
|
||||
testCompile(project(":compiler:fir:java"))
|
||||
|
||||
@@ -83,7 +83,7 @@ abstract class AbstractIrGeneratorTestCase : CodegenTestCase() {
|
||||
|
||||
protected abstract fun doTest(wholeFile: File, testFiles: List<TestFile>)
|
||||
|
||||
protected fun generateIrModule(ignoreErrors: Boolean = false): IrModuleFragment {
|
||||
protected open fun generateIrModule(ignoreErrors: Boolean = false): IrModuleFragment {
|
||||
assert(myFiles != null) { "myFiles not initialized" }
|
||||
assert(myEnvironment != null) { "myEnvironment not initialized" }
|
||||
return doGenerateIrModule(Psi2IrTranslator(myEnvironment.configuration.languageVersionSettings, Psi2IrConfiguration(ignoreErrors)))
|
||||
|
||||
@@ -285,6 +285,29 @@ abstract class AbstractIrTextTestCase : AbstractIrGeneratorTestCase() {
|
||||
|
||||
internal class IrTreeFileLabel(val expectedTextFile: File, val lineNumber: Int)
|
||||
|
||||
protected open fun getExpectedTextFileName(testFile: TestFile, name: String = testFile.name): String = name.replace(".kt", ".txt")
|
||||
|
||||
private fun parseExpectations(dir: File, testFile: TestFile): Expectations {
|
||||
val regexps =
|
||||
testFile.content.matchLinesWith(EXPECTED_OCCURRENCES_PATTERN) {
|
||||
RegexpInText(it.groupValues[1], it.groupValues[2].trim())
|
||||
}
|
||||
|
||||
var treeFiles =
|
||||
testFile.content.matchLinesWith(IR_FILE_TXT_PATTERN) {
|
||||
val fileName = it.groupValues[1].trim()
|
||||
val file = createExpectedTextFile(testFile, dir, getExpectedTextFileName(testFile, fileName))
|
||||
IrTreeFileLabel(file, 0)
|
||||
}
|
||||
|
||||
if (treeFiles.isEmpty()) {
|
||||
val file = createExpectedTextFile(testFile, dir, getExpectedTextFileName(testFile))
|
||||
treeFiles = listOf(IrTreeFileLabel(file, 0))
|
||||
}
|
||||
|
||||
return Expectations(regexps, treeFiles)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val EXPECTED_OCCURRENCES_PATTERN = Regex("""^\s*//\s*(\d+)\s*(.*)$""")
|
||||
private val IR_FILE_TXT_PATTERN = Regex("""// IR_FILE: (.*)$""")
|
||||
@@ -301,27 +324,6 @@ abstract class AbstractIrTextTestCase : AbstractIrGeneratorTestCase() {
|
||||
|
||||
internal fun TestFile.isExternalFile() =
|
||||
EXTERNAL_FILE_PATTERN.containsMatchIn(content)
|
||||
|
||||
internal fun parseExpectations(dir: File, testFile: TestFile): Expectations {
|
||||
val regexps =
|
||||
testFile.content.matchLinesWith(EXPECTED_OCCURRENCES_PATTERN) {
|
||||
RegexpInText(it.groupValues[1], it.groupValues[2].trim())
|
||||
}
|
||||
|
||||
var treeFiles =
|
||||
testFile.content.matchLinesWith(IR_FILE_TXT_PATTERN) {
|
||||
val fileName = it.groupValues[1].trim()
|
||||
val file = createExpectedTextFile(testFile, dir, fileName)
|
||||
IrTreeFileLabel(file, 0)
|
||||
}
|
||||
|
||||
if (treeFiles.isEmpty()) {
|
||||
val file = createExpectedTextFile(testFile, dir, testFile.name.replace(".kt", ".txt"))
|
||||
treeFiles = listOf(IrTreeFileLabel(file, 0))
|
||||
}
|
||||
|
||||
return Expectations(regexps, treeFiles)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user