Browse Source

added tests for dot qualified expressions

pull/1768/head
thelumiereguy 3 years ago
parent
commit
66a8a055e1
  1. 107
      idea-plugin/src/test/kotlin/org/jetbrains/compose/intentions/utils/get_root_psi_element/GetRootPsiElementTest.kt

107
idea-plugin/src/test/kotlin/org/jetbrains/compose/intentions/utils/get_root_psi_element/GetRootPsiElementTest.kt

@ -20,7 +20,7 @@ class GetRootPsiElementTest : LightJavaCodeInsightFixtureTestCase() {
private val getRootElement = GetRootPsiElement()
@Test
fun `when a name reference expression is selected , but root is a property , the property should be returned as root element`() {
fun `when a name reference expression is selected , but root is a property , the property should be returned`() {
val ktPsiFactory = KtPsiFactory(project)
@Language("Kotlin")
@ -88,7 +88,7 @@ class GetRootPsiElementTest : LightJavaCodeInsightFixtureTestCase() {
// v
Box() {
} // Name Reference Expression
}
}
""".trimIndent().trim()
@ -134,7 +134,7 @@ class GetRootPsiElementTest : LightJavaCodeInsightFixtureTestCase() {
}
@Test
fun `when a name reference expression is selected, with a delegated property with dot qualified expression as root, property should be returned`() {
fun `when a name reference expression with dot reference expression is selected, with a delegated property as root, property should be returned`() {
val ktPsiFactory = KtPsiFactory(project)
@Language("Kotlin")
@ -162,7 +162,6 @@ class GetRootPsiElementTest : LightJavaCodeInsightFixtureTestCase() {
val referenceExpression = dotQualifiedExpression.lastChild.firstChild as KtNameReferenceExpression
TestCase.assertEquals("animateFloat", referenceExpression.text)
TestCase.assertEquals(
@ -172,7 +171,7 @@ class GetRootPsiElementTest : LightJavaCodeInsightFixtureTestCase() {
}
@Test
fun `when a name reference expression is selected, with a property and dot qualified expression as root, property should be returned`() {
fun `when a name reference expression with dot reference expression is selected, with a property and dot qualified expression as root, property should be returned`() {
val ktPsiFactory = KtPsiFactory(project)
@Language("Kotlin")
@ -207,4 +206,102 @@ class GetRootPsiElementTest : LightJavaCodeInsightFixtureTestCase() {
getRootElement.invoke(referenceExpression)
)
}
@Test
fun `when a dot qualified expression is selected, with a delegated property as root, property should be returned`() {
val ktPsiFactory = KtPsiFactory(project)
@Language("Kotlin")
val template = """
val repeatingAnimation = rememberInfiniteTransition()
val offset by repeatingAnimation.animateFloat(
0f,
-20f,
infiniteRepeatable(
repeatMode = RepeatMode.Reverse,
animation = tween(
durationMillis = 1000,
easing = LinearEasing
)
)
)
""".trimIndent().trim()
val file = ktPsiFactory.createFile(template)
val property = file.lastChild as KtProperty
val dotQualifiedExpression = property.lastChild.lastChild as KtDotQualifiedExpression
TestCase.assertEquals(
"""
repeatingAnimation.animateFloat(
0f,
-20f,
infiniteRepeatable(
repeatMode = RepeatMode.Reverse,
animation = tween(
durationMillis = 1000,
easing = LinearEasing
)
)
)
""".trimIndent().trim(), dotQualifiedExpression.text
)
TestCase.assertEquals(
property,
getRootElement.invoke(dotQualifiedExpression)
)
}
@Test
fun `when a dot qualified expression is selected, with a property as root, property should be returned`() {
val ktPsiFactory = KtPsiFactory(project)
@Language("Kotlin")
val template = """
val repeatingAnimation = rememberInfiniteTransition()
val offset = repeatingAnimation.animateFloat(
0f,
-20f,
infiniteRepeatable(
repeatMode = RepeatMode.Reverse,
animation = tween(
durationMillis = 1000,
easing = LinearEasing
)
)
)
""".trimIndent().trim()
val file = ktPsiFactory.createFile(template)
val property = file.lastChild as KtProperty
val dotQualifiedExpression = property.lastChild as KtDotQualifiedExpression
TestCase.assertEquals(
"""
repeatingAnimation.animateFloat(
0f,
-20f,
infiniteRepeatable(
repeatMode = RepeatMode.Reverse,
animation = tween(
durationMillis = 1000,
easing = LinearEasing
)
)
)
""".trimIndent().trim(), dotQualifiedExpression.text
)
TestCase.assertEquals(
property,
getRootElement.invoke(dotQualifiedExpression)
)
}
}

Loading…
Cancel
Save