[kotlin] Added test

#KTIJ-21826 Fixed

GitOrigin-RevId: a1995292ab3d00919db91e19ab677bd832071556
This commit is contained in:
Vladimir Dolzhenko
2022-05-27 11:42:03 +00:00
committed by intellij-monorepo-bot
parent 41a1376031
commit 9c41fe87f6
3 changed files with 34 additions and 3 deletions
@@ -468,6 +468,11 @@ public class OutOfBlockModificationTestGenerated extends AbstractOutOfBlockModif
runTest("testData/codeInsight/outOfBlock/StringInSuperConstroctorCall.kt");
}
@TestMetadata("Suppression.kt")
public void testSuppression() throws Exception {
runTest("testData/codeInsight/outOfBlock/Suppression.kt");
}
@TestMetadata("Uncomment.kt")
public void testUncomment() throws Exception {
runTest("testData/codeInsight/outOfBlock/Uncomment.kt");
@@ -0,0 +1,19 @@
// WITH_STDLIB
// OUT_OF_CODE_BLOCK: FALSE
// SKIP_ANALYZE_CHECK
// TYPE: '"'
// INSPECTION-CLASS: org.jetbrains.kotlin.idea.inspections.KotlinRedundantDiagnosticSuppressInspection
// NO-INSPECTION-OUTPUT
// inspection message `[GENERIC_ERROR_OR_WARNING:8] Redundant suppression` should not appear, therefore `NO-INSPECTION-OUTPUT`
fun convertToMap(converted: Map<*, *>): Map<String, Any>? {
@Suppress("UNCHECKED_CAST")
return converted as Map<String, Any>?
}
fun main() {
val s = "hello<caret>
when (s) {
"hello" -> println(s)
else -> {}
}
}
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.idea.inspections.AbstractKotlinInspection
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics
import java.io.File
import kotlin.test.assertTrue
object DirectiveBasedActionUtils {
@@ -97,17 +98,23 @@ object DirectiveBasedActionUtils {
/* progress = */ DaemonProgressIndicator(),
)
val directive = "// INSPECTION:"
val expected = InTextDirectivesUtils.findLinesWithPrefixesRemoved(file.text, directive)
val directive = "INSPECTION"
val expected = InTextDirectivesUtils.findLinesWithPrefixesRemoved(file.text, "// $directive:")
.sorted()
.map { "$directive $it" }
val noInspectionOutputDirective = "NO-INSPECTION-OUTPUT"
val noInspectionOutput = InTextDirectivesUtils.isDirectiveDefined(file.text, "// $noInspectionOutputDirective")
val actual = problems
// lineNumber is 0-based
.map { "$directive [${it.highlightType.name}:${it.lineNumber + 1}] $it" }
.sorted()
if (actual.isEmpty() && expected.isEmpty()) return
if (actual.isEmpty() && expected.isEmpty()) {
assertTrue(noInspectionOutput, "`$noInspectionOutputDirective` directive has to be defined if there is nothing to report")
return
}
KotlinLightCodeInsightFixtureTestCaseBase.assertOrderedEquals(
"All actual $name should be mentioned in test data with '$directive' directive. " +