Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ending line and column to Location.kt (#5032)
* Add ending line and column to Location.kt * Revert changes to detekt-api.api * Add tests for Location.kt * Add new line to comply with format Co-authored-by: schalkms <30376729+schalkms@users.noreply.github.com>
- Loading branch information
1 parent
b6448e3
commit 6638b2f
Showing
3 changed files
with
70 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
detekt-api/src/test/kotlin/io/gitlab/arturbosch/detekt/api/LocationSpec.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.gitlab.arturbosch.detekt.api | ||
|
||
import io.github.detekt.test.utils.compileContentForTest | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.jetbrains.kotlin.psi.KtNamedFunction | ||
import org.junit.jupiter.api.Test | ||
|
||
class LocationSpec { | ||
|
||
@Test | ||
fun `start and end positions of block`() { | ||
val code = """ | ||
fun data(): Int { | ||
return 0 | ||
} | ||
""".trimIndent() | ||
val psiElement = compileContentForTest(code).findChildByClass(KtNamedFunction::class.java)!! | ||
val location = Location.from(psiElement) | ||
|
||
assertThat("${location.source} - ${location.endSource}").isEqualTo("1:1 - 3:2") | ||
} | ||
|
||
@Test | ||
fun `start and end positions of fun keyword`() { | ||
val code = """ | ||
fun data(): Int { | ||
return 0 | ||
} | ||
""".trimIndent() | ||
val psiElement = compileContentForTest(code).findChildByClass(KtNamedFunction::class.java)!! | ||
val location = Location.from(psiElement.funKeyword!!) | ||
|
||
assertThat("${location.source} - ${location.endSource}").isEqualTo("1:1 - 1:4") | ||
} | ||
} |