Reparse lambda expression after removing parameter comma (KT-21497)
Without the parameter it can become block. #KT-21497 Fixed
This commit is contained in:
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.editor
|
||||
import com.intellij.psi.PsiDocumentManager
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import com.intellij.testFramework.EditorTestUtil
|
||||
import com.intellij.testFramework.EditorTestUtil.*
|
||||
import com.intellij.testFramework.LightPlatformTestCase
|
||||
import com.intellij.testFramework.LightProjectDescriptor
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCaseBase
|
||||
@@ -27,14 +28,24 @@ import org.junit.Assert
|
||||
|
||||
class LazyElementTypeTest : KotlinLightCodeInsightFixtureTestCaseBase() {
|
||||
fun testSplitArrow() = reparse("val t = { a: Int -<caret>> }", ' ')
|
||||
fun testDeleteArrow() = reparse("val t = { a: Int -><caret> }", EditorTestUtil.BACKSPACE_FAKE_CHAR)
|
||||
fun testDeleteArrow() = reparse("val t = { a: Int -><caret> }", BACKSPACE_FAKE_CHAR)
|
||||
|
||||
fun testReformatNearArrow() = noReparse("val t = { a: Int<caret>-> }", ' ')
|
||||
fun testChangeAfterArrow() = noReparse("val t = { a: Int -> <caret> }", 'a')
|
||||
fun testDeleteIrrelevantArrow() = noReparse("val t = { a: Int -> (1..3).filter { b -><caret> b > 2 } }", EditorTestUtil.BACKSPACE_FAKE_CHAR)
|
||||
fun testDeleteIrrelevantArrow() = noReparse("val t = { a: Int -> (1..3).filter { b -><caret> b > 2 } }", BACKSPACE_FAKE_CHAR)
|
||||
fun testReformatNearLambdaStart() = noReparse("val t = {<caret>a: Int -> }", ' ')
|
||||
fun testNoArrow() = noReparse("val t = { <caret> }", 'a')
|
||||
|
||||
fun testAfterRemovingParameterComma() = reparse(inIf("{t,<caret>}"), BACKSPACE_FAKE_CHAR)
|
||||
fun testAfterRemovingNoParameterComma() = noReparse(inIf("{,<caret>}"), BACKSPACE_FAKE_CHAR)
|
||||
fun testAfterRemovingNotLastParameterComma() = noReparse(inIf("{a, b,<caret>}"), BACKSPACE_FAKE_CHAR)
|
||||
fun testAfterRemovingSecondParameter() = noReparse(inIf("{a,b<caret>}"), BACKSPACE_FAKE_CHAR)
|
||||
fun testAfterFirstParameterRenamed() = noReparse(inIf("{a<caret>,}"), 'b')
|
||||
|
||||
fun testAfterRemovingFirstParameterWithOther() = reparse(inIf("{a<caret>,b}"), BACKSPACE_FAKE_CHAR)
|
||||
fun testAfterRemovingFirstParameter() = reparse(inIf("{a<caret>,}"), BACKSPACE_FAKE_CHAR)
|
||||
fun testAfterTypeComma() = reparse(inIf("{a<caret>}"), ',')
|
||||
|
||||
fun reparse(text: String, char: Char): Unit = doTest(text, char, true)
|
||||
fun noReparse(text: String, char: Char): Unit = doTest(text, char, false)
|
||||
|
||||
@@ -43,7 +54,7 @@ class LazyElementTypeTest : KotlinLightCodeInsightFixtureTestCaseBase() {
|
||||
|
||||
val lambdaExpressionBefore = PsiTreeUtil.findChildOfType(file, KtLambdaExpression::class.java)
|
||||
|
||||
EditorTestUtil.performTypingAction(myFixture.editor, char)
|
||||
performTypingAction(myFixture.editor, char)
|
||||
PsiDocumentManager.getInstance(LightPlatformTestCase.getProject()).commitDocument(myFixture.getDocument(file))
|
||||
|
||||
val lambdaExpressionAfter = PsiTreeUtil.findChildOfType(file, KtLambdaExpression::class.java)
|
||||
@@ -53,5 +64,7 @@ class LazyElementTypeTest : KotlinLightCodeInsightFixtureTestCaseBase() {
|
||||
Assert.assertEquals("Lazy element behaviour was unexpected", reparse, actualReparse)
|
||||
}
|
||||
|
||||
private fun inIf(lambda: String) = "val t: Unit = if (true) $lambda else {}"
|
||||
|
||||
override fun getProjectDescriptor() = LightProjectDescriptor.EMPTY_PROJECT_DESCRIPTOR
|
||||
}
|
||||
Reference in New Issue
Block a user