From 66a8a055e12e0024f0f5e1839d017a6f38e674a8 Mon Sep 17 00:00:00 2001 From: thelumiereguy Date: Sun, 30 Jan 2022 22:50:57 +0530 Subject: [PATCH] added tests for dot qualified expressions --- .../GetRootPsiElementTest.kt | 107 +++++++++++++++++- 1 file changed, 102 insertions(+), 5 deletions(-) diff --git a/idea-plugin/src/test/kotlin/org/jetbrains/compose/intentions/utils/get_root_psi_element/GetRootPsiElementTest.kt b/idea-plugin/src/test/kotlin/org/jetbrains/compose/intentions/utils/get_root_psi_element/GetRootPsiElementTest.kt index 20375e18f9..7bb034109c 100644 --- a/idea-plugin/src/test/kotlin/org/jetbrains/compose/intentions/utils/get_root_psi_element/GetRootPsiElementTest.kt +++ b/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) + ) + } }