Refactoring: extract common code to functions
This commit is contained in:
@@ -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<hint text=": List<String>" /> = listOf("a") }""")
|
||||
checkLocalVariable("""fun foo() { val a<hint text=": List<String>" /> = listOf("a") }""")
|
||||
}
|
||||
|
||||
fun testDestructuringType() {
|
||||
HintType.LOCAL_VARIABLE_HINT.option.set(true)
|
||||
check("""fun foo() { val (i<hint text=": Int" />, s<hint text=": String" />) = 1 to "" }""")
|
||||
checkLocalVariable("""fun foo() { val (i<hint text=": Int" />, s<hint text=": String" />) = 1 to "" }""")
|
||||
}
|
||||
|
||||
fun testPropertyType() {
|
||||
HintType.PROPERTY_HINT.option.set(true)
|
||||
check("""val a<hint text=": List<String>" /> = listOf("a")""")
|
||||
checkPropertyHint("""val a<hint text=": List<String>" /> = 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<T>; val a = Bar<String>()""")
|
||||
checkPropertyHint("""class Bar<T>; val a = Bar<String>()""")
|
||||
}
|
||||
|
||||
fun testConstructorWithoutExplicitTypeParametersType() {
|
||||
HintType.PROPERTY_HINT.option.set(true)
|
||||
check("""class Bar<T>(val t: T); val a<hint text=": Bar<String>" /> = Bar(<hint text="t:" />"")""")
|
||||
checkPropertyHint("""class Bar<T>(val t: T); val a<hint text=": Bar<String>" /> = Bar(<hint text="t:" />"")""")
|
||||
}
|
||||
|
||||
fun testLoopParameter() {
|
||||
HintType.LOCAL_VARIABLE_HINT.option.set(true)
|
||||
check("""fun foo() { for (x<hint text=": String" /> in listOf("a")) { } }""")
|
||||
checkLocalVariable("""fun foo() { for (x<hint text=": String" /> 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<hint text=": ArrayList<Int>" /> = arrayListOf(1)""")
|
||||
checkPropertyHint("""val x<hint text=": ArrayList<Int>" /> = arrayListOf(1)""")
|
||||
}
|
||||
|
||||
fun testAnonymousObject() {
|
||||
HintType.FUNCTION_HINT.option.set(true)
|
||||
check("""val o = object : Iterable<Int> {
|
||||
override fun iterator()<hint text=": Iterator<Int>" /> = object : Iterator<Int> {
|
||||
override fun next()<hint text=": Int" /> = 1
|
||||
override fun hasNext()<hint text=": Boolean" /> = true
|
||||
}
|
||||
}""")
|
||||
checkFunctionHint(
|
||||
"""
|
||||
val o = object : Iterable<Int> {
|
||||
override fun iterator()<hint text=": Iterator<Int>" /> = object : Iterator<Int> {
|
||||
override fun next()<hint text=": Int" /> = 1
|
||||
override fun hasNext()<hint text=": Boolean" /> = 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<String>) {
|
||||
checkLocalVariable(
|
||||
"""
|
||||
fun main(args: Array<String>) {
|
||||
val (a: String, b: String, c: String) = x()
|
||||
}
|
||||
|
||||
fun x() :Triple<String, String,String> {
|
||||
return Triple(<hint text="first:" />"A", <hint text="second:" />"B", <hint text="third:" />"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<hint text=": Set<Entry<Int, String>>" /> = mapOf(1 to "1").entries"""
|
||||
)
|
||||
}
|
||||
|
||||
fun testNestedClassWithoutImport() {
|
||||
HintType.PROPERTY_HINT.option.set(true)
|
||||
check(
|
||||
checkPropertyHint(
|
||||
"""val entries<hint text=": Set<Map.Entry<Int, String>>" /> = mapOf(1 to "1").entries"""
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user