Files
openide/jvm/jvm-analysis-kotlin-tests/testSrc/com/intellij/codeInspection/tests/kotlin/KotlinCallMatcherTest.kt
Bart van Helvert ba513a4d88 [jvm] Rename shared.testFramework to internal.TestFramework
To better highlight that this test framework is for internal usage only. #IDEA-334017

GitOrigin-RevId: c491de2411cdffd6eee3e97a6273982560572f4b
2023-10-11 23:39:50 +00:00

55 lines
2.0 KiB
Kotlin

package com.intellij.codeInspection.tests.kotlin
import com.intellij.jvm.analysis.internal.testFramework.CallMatcherTestBase
import com.intellij.jvm.analysis.testFramework.JvmLanguage
import com.siyeh.ig.callMatcher.CallMatcher
class KotlinCallMatcherTest : CallMatcherTestBase() {
fun testInstanceMethodCall() {
checkMatchCall(JvmLanguage.KOTLIN, CallMatcher.instanceCall("Foo", "bar").parameterCount(0), """
class Foo { fun bar() { } }
fun main() { Foo().bar() }
""".trimIndent())
}
fun testMultipleArgumentsCall() {
checkMatchCall(JvmLanguage.KOTLIN, CallMatcher.instanceCall("Foo", "bar").parameterCount(3), """
class Foo { fun bar(x: Int, y: Int, z: Int) { } }
fun main() { Foo().bar(0, 0, 0) }
""".trimIndent())
}
fun testMultipleArgumentsCallDefaultArg() {
checkMatchCall(JvmLanguage.KOTLIN, CallMatcher.instanceCall("Foo", "bar").parameterCount(3), """
class Foo { fun bar(x: Int, y: Int, z: Int = 0) { } }
fun main() { Foo().bar(0, 0) }
""".trimIndent())
}
fun testMultipleArgumentTypes() {
checkMatchCall(JvmLanguage.KOTLIN, CallMatcher.instanceCall("Foo", "bar").parameterTypes("int", "long", "double"), """
class Foo { fun bar(x: Int, y: Long, z: Double) { } }
fun main() { Foo().bar(0, 0L, 0.0) }
""".trimIndent())
}
fun testInstanceMethodReference() {
checkMatchCallableReference(JvmLanguage.KOTLIN, CallMatcher.instanceCall("java.lang.String", "plus").parameterCount(1), """
class Foo { fun bar(arg: String.(String) -> String) { } }
class Main { fun main() { Foo().bar(String::plus) } }
""".trimIndent())
}
fun testMethodReferenceArgumentTypes() {
checkMatchCallableReference(JvmLanguage.KOTLIN, CallMatcher.instanceCall("java.lang.String", "plus").parameterTypes("java.lang.Object"), """
class Foo { fun bar(arg: String.(String) -> String) { } }
class Main { fun main() { Foo().bar(String::plus) } }
""".trimIndent())
}
}