Adjust display column based on infix operator

Fixes #2
This commit is contained in:
Brian Norman
2020-02-08 18:25:11 -06:00
parent 0225417ae7
commit 77a387f06f
2 changed files with 24 additions and 9 deletions
@@ -36,14 +36,6 @@ abstract class PowerAssertGenerator(
private val file: IrFile,
private val fileSource: String
) {
// private fun IrStatementsBuilder<*>.buildAssertThrow(
// callSource: String,
// title: IrExpression,
// subStack: MutableList<IrStackVariable>,
// callIndent: Int = 0
// ) = buildThrow(constructor, buildMessage(title, subStack, callSource, callIndent))
abstract fun IrBuilderWithScope.buildAssertThrow(subStack: List<IrStackVariable>): IrExpression
fun buildAssert(
@@ -107,7 +99,12 @@ abstract class PowerAssertGenerator(
var startColumnNumber = file.info(expression).startColumnNumber
if (expression is IrMemberAccessExpression) {
// TODO Is this the best way to fix indentation of infix operators?
val descriptor = expression.descriptor
if (descriptor is FunctionDescriptor && descriptor.isInfix) {
startColumnNumber += source.indexOf(descriptor.name.asString())
}
// TODO handle equality and comparison better?
startColumnNumber += when (expression.origin) {
IrStatementOrigin.EQEQ, IrStatementOrigin.EQEQEQ -> source.indexOf("==")
IrStatementOrigin.EXCLEQ, IrStatementOrigin.EXCLEQEQ -> source.indexOf("!=")
@@ -19,6 +19,7 @@ package com.bnorm.power
import com.tschuchort.compiletesting.KotlinCompilation
import com.tschuchort.compiletesting.SourceFile
import org.intellij.lang.annotations.Language
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.junit.Test
import java.lang.reflect.InvocationTargetException
import kotlin.test.assertEquals
@@ -265,6 +266,23 @@ assert(text?.length?.minus(2) == 1)
| | 3
| 5
Hello
""".trimIndent()
)
}
@Test
fun infixFunctions() {
assertMessage(
"""
fun main() {
assert(1 shl 1 == 4)
}""",
"""
Assertion failed
assert(1 shl 1 == 4)
| |
| false
2
""".trimIndent()
)
}