[Tests] Introduce replacing source transformer

This commit is contained in:
Evgeniy.Zhelenskiy
2021-12-07 02:48:30 +03:00
parent 38ff3f5a24
commit cb4ec932d7
18 changed files with 80 additions and 42 deletions
@@ -51,7 +51,7 @@ class GlobalMetadataInfoHandler(
infos += codeMetaInfos
}
fun compareAllMetaDataInfos(expectedTransformer: ((String) -> String)?) {
fun compareAllMetaDataInfos() {
// TODO: adapt to multiple testdata files
val moduleStructure = testServices.moduleStructure
val builder = StringBuilder()
@@ -66,18 +66,15 @@ class GlobalMetadataInfoHandler(
codeMetaInfos,
testServices.sourceFileProvider.getContentOfSourceFile(file)
)
builder.append(fileBuilder.stripAdditionalEmptyLines(file))
val reverseTransformers = testServices.sourceFileProvider.preprocessors.filterIsInstance<ReversibleSourceFilePreprocessor>()
val initialFileContent = fileBuilder.stripAdditionalEmptyLines(file).toString()
val actualFileContent =
reverseTransformers.foldRight(initialFileContent) { transformer, source -> transformer.revert(file, source) }
builder.append(actualFileContent)
}
}
val actualText = builder.toString()
val expectedFile = moduleStructure.originalTestDataFiles.single()
if (expectedTransformer != null) {
val expectedContent = expectedFile.readText().let(expectedTransformer)
val message = "Actual data differs from transformed content of file $expectedFile"
testServices.assertions.assertEquals(expectedContent, actualText) { message }
} else {
testServices.assertions.assertEqualsToFile(expectedFile, actualText)
}
testServices.assertions.assertEqualsToFile(moduleStructure.originalTestDataFiles.single(), actualText)
}
private fun StringBuilder.stripAdditionalEmptyLines(file: TestFile): CharSequence {