diff --git a/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/InlayTypeHintsTest.kt b/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/InlayTypeHintsTest.kt index a1fd3887a1b..66329bc81ad 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/InlayTypeHintsTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/InlayTypeHintsTest.kt @@ -16,112 +16,115 @@ class InlayTypeHintsTest : KotlinLightCodeInsightFixtureTestCase() { myFixture.testInlays() } + fun check(text: String, hintType: HintType) { + hintType.option.set(true) + check(text) + } + + private fun checkLocalVariable(text: String) = check(text, HintType.LOCAL_VARIABLE_HINT) + private fun checkPropertyHint(text: String) = check(text, HintType.PROPERTY_HINT) + private fun checkFunctionHint(text: String) = check(text, HintType.FUNCTION_HINT) + fun testLocalVariableType() { - HintType.LOCAL_VARIABLE_HINT.option.set(true) - check("""fun foo() { val a = listOf("a") }""") + checkLocalVariable("""fun foo() { val a = listOf("a") }""") } fun testDestructuringType() { - HintType.LOCAL_VARIABLE_HINT.option.set(true) - check("""fun foo() { val (i, s) = 1 to "" }""") + checkLocalVariable("""fun foo() { val (i, s) = 1 to "" }""") } fun testPropertyType() { - HintType.PROPERTY_HINT.option.set(true) - check("""val a = listOf("a")""") + checkPropertyHint("""val a = listOf("a")""") } fun testConstInitializerType() { - HintType.PROPERTY_HINT.option.set(true) - check("""val a = 1""") + checkPropertyHint("""val a = 1""") } fun testUnaryConstInitializerType() { - HintType.PROPERTY_HINT.option.set(true) - check("""val a = -1; val b = +1""") + checkPropertyHint("""val a = -1; val b = +1""") } fun testConstructorWithoutTypeParametersType() { - HintType.PROPERTY_HINT.option.set(true) - check("""val a = Any()""") + checkPropertyHint("""val a = Any()""") } fun testConstructorWithExplicitTypeParametersType() { - HintType.PROPERTY_HINT.option.set(true) - check("""class Bar; val a = Bar()""") + checkPropertyHint("""class Bar; val a = Bar()""") } fun testConstructorWithoutExplicitTypeParametersType() { - HintType.PROPERTY_HINT.option.set(true) - check("""class Bar(val t: T); val a = Bar("")""") + checkPropertyHint("""class Bar(val t: T); val a = Bar("")""") } fun testLoopParameter() { - HintType.LOCAL_VARIABLE_HINT.option.set(true) - check("""fun foo() { for (x in listOf("a")) { } }""") + checkLocalVariable("""fun foo() { for (x in listOf("a")) { } }""") } fun testLoopParameterWithExplicitType() { - HintType.LOCAL_VARIABLE_HINT.option.set(true) - check("""fun foo() { for (x: String in listOf("a")) { } }""") + checkLocalVariable("""fun foo() { for (x: String in listOf("a")) { } }""") } fun testErrorType() { - HintType.PROPERTY_HINT.option.set(true) - check("""val x = arrayListOf<>()""") + checkPropertyHint("""val x = arrayListOf<>()""") } fun testExpandedTypeAlias() { - HintType.PROPERTY_HINT.option.set(true) - check("""val x = arrayListOf(1)""") + checkPropertyHint("""val x = arrayListOf(1)""") } fun testAnonymousObject() { - HintType.FUNCTION_HINT.option.set(true) - check("""val o = object : Iterable { - override fun iterator() = object : Iterator { - override fun next() = 1 - override fun hasNext() = true - } - }""") + checkFunctionHint( + """ + val o = object : Iterable { + override fun iterator() = object : Iterator { + override fun next() = 1 + override fun hasNext() = true + } + } + """.trimIndent() + ) } fun testAnonymousObjectNoBaseType() { - HintType.LOCAL_VARIABLE_HINT.option.set(true) - check("""fun foo() { + checkLocalVariable( + """ + fun foo() { val o = object { val x: Int = 0 } - }""") + } + """.trimIndent() + ) } fun testDestructuring() { - HintType.LOCAL_VARIABLE_HINT.option.set(true) - check("""fun main(args: Array) { + checkLocalVariable( + """ + fun main(args: Array) { val (a: String, b: String, c: String) = x() } fun x() :Triple { return Triple("A", "B", "C") - }""") + } + """.trimIndent() + ) } fun testSAMConstructor() { - HintType.PROPERTY_HINT.option.set(true) - check("""val x = Runnable { }""") + checkPropertyHint("""val x = Runnable { }""") } fun testNestedClassImports() { - HintType.PROPERTY_HINT.option.set(true) - check( + checkPropertyHint( """import kotlin.collections.Map.Entry val entries = mapOf(1 to "1").entries""" ) } fun testNestedClassWithoutImport() { - HintType.PROPERTY_HINT.option.set(true) - check( + checkPropertyHint( """val entries = mapOf(1 to "1").entries""" ) }