Skip to content

Commit

Permalink
Added case when parent = null
Browse files Browse the repository at this point in the history
  • Loading branch information
Anna Potriasaeva authored and onewhl committed Jul 27, 2023
1 parent 22b8f68 commit d003bee
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private fun getParentText(element: PsiElement, isParentTypeFunction: Boolean): S
* If false, the parent element is expected to be a class or any other non-function type.
* @return True if the PsiFile contains an expression with the given text and the specified parent, false otherwise.
*/
fun PsiFile.hasExpressionWithParent(expression: String, parent: String, isParentTypeFunction: Boolean): Boolean =
fun PsiFile.hasExpressionWithParent(expression: String, parent: String?, isParentTypeFunction: Boolean): Boolean =
ApplicationManager.getApplication().runReadAction<Boolean> {
val expressions: MutableCollection<PsiElement> =
extractElementsOfTypes(KtDotQualifiedExpression::class.java, KtCallExpression::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ open class BaseIjTestClass : BasePlatformTestCase() {

fun hasMethod(methodName: String): Boolean = myFixture.file.hasMethod(methodName)

fun hasExpressionWithParent(expression: String, parent: String, isParentTypeFunction: Boolean = false): Boolean =
fun hasExpressionWithParent(expression: String, parent: String?, isParentTypeFunction: Boolean = false): Boolean =
myFixture.file.hasExpressionWithParent(expression, parent, isParentTypeFunction)
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ class BaseIjTestClassTests : BaseIjTestClass() {
}
""".trimIndent()
myFixture.configureByText("Task.kt", example)
var expression = "productPrice.sum()"
var parent = "productPrice.sum() / productPrice.count()"
var expression: String = "productPrice.sum()"
var parent: String? = "productPrice.sum() / productPrice.count()"
assert(hasExpressionWithParent(expression, parent)) {
"There must exist an expression $expression with parent $parent"
}
Expand All @@ -212,5 +212,10 @@ class BaseIjTestClassTests : BaseIjTestClass() {
expression = "Int.MAX_VALUE"
parent = "val CONSTANT = Int.MAX_VALUE"
assertFalse(hasExpressionWithParent(expression, parent))
expression = "Int.MAX_VALUE"
parent = null
assert(hasExpressionWithParent(expression, parent, true)) {
"There must exist an expression $expression with parent $parent"
}
}
}

0 comments on commit d003bee

Please sign in to comment.