Test for KT-22527

This commit is contained in:
Mikhail Glukhikh
2018-04-19 13:29:49 +03:00
parent 29c16f9561
commit f179b2ba13
5 changed files with 138 additions and 4 deletions
@@ -0,0 +1,40 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.uast.test.kotlin
import org.jetbrains.uast.UElement
import org.jetbrains.uast.UExpression
import org.jetbrains.uast.UFile
import org.jetbrains.uast.evaluation.uValueOf
import org.jetbrains.uast.visitor.UastVisitor
abstract class AbstractKotlinExpressionValueTest : AbstractKotlinUastTest() {
override fun check(testName: String, file: UFile) {
var valuesFound = 0
file.accept(object : UastVisitor {
override fun visitElement(node: UElement): Boolean {
for (comment in node.comments) {
val text = comment.text.removePrefix("/* ").removeSuffix(" */")
val parts = text.split(" = ")
if (parts.size != 2) continue
when (parts[0]) {
"constant" -> {
val expectedValue = parts[1]
val actualValue =
(node as? UExpression)?.uValueOf()?.toConstant()?.toString()
?: "cannot evaluate $node of ${node.javaClass}"
assertEquals(expectedValue, actualValue)
valuesFound++
}
}
}
return false
}
})
assertTrue("No values found, add some /* constant = ... */ to the input file", valuesFound > 0)
}
}
@@ -0,0 +1,13 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.uast.test.kotlin
import org.junit.Test
class KotlinExpressionValueTest : AbstractKotlinExpressionValueTest() {
@Test
fun testDelegate() = doTest("Delegate")
}
@@ -4,11 +4,18 @@ import org.junit.Test
class KotlinUastValuesTest : AbstractKotlinValuesTest() {
@Test fun testAssertion() = doTest("Assertion")
@Test
fun testAssertion() = doTest("Assertion")
@Test fun testIn() = doTest("In")
@Test
fun testDelegate() = doTest("Delegate")
@Test fun testLocalDeclarations() = doTest("LocalDeclarations")
@Test
fun testIn() = doTest("In")
@Test fun testSimple() = doTest("Simple")
@Test
fun testLocalDeclarations() = doTest("LocalDeclarations")
@Test
fun testSimple() = doTest("Simple")
}