Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Signatures.kt:buildFunctionSignature (#4961)
* Fix Signatures.kt:buildFunctionSignature 'buildFunctionSignature' fails when function body has KDoc. * Simplify tests * Skip comments
- Loading branch information
1 parent
5170077
commit 2b068e0
Showing
2 changed files
with
57 additions
and
15 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
47 changes: 47 additions & 0 deletions
47
detekt-api/src/test/kotlin/io/gitlab/arturbosch/detekt/api/internal/SignaturesSpec.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,47 @@ | ||
package io.gitlab.arturbosch.detekt.api.internal | ||
|
||
import io.github.detekt.test.utils.compileContentForTest | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.assertj.core.api.Assertions.assertThatThrownBy | ||
import org.jetbrains.kotlin.psi.KtNamedFunction | ||
import org.junit.jupiter.api.Test | ||
|
||
class SignaturesSpec { | ||
@Test | ||
fun `function with type reference`() { | ||
val result = compileContentForTest("fun data(): Int = 0") | ||
.findChildByClass(KtNamedFunction::class.java)!! | ||
.buildFullSignature() | ||
|
||
assertThat(result).isEqualTo("Test.kt\$fun data(): Int") | ||
} | ||
|
||
@Test | ||
fun `function without type reference`() { | ||
val result = compileContentForTest("fun data() = 0") | ||
.findChildByClass(KtNamedFunction::class.java)!! | ||
.buildFullSignature() | ||
|
||
assertThat(result).isEqualTo("Test.kt\$fun data()") | ||
} | ||
|
||
@Test | ||
fun `function with comments`() { | ||
val result = compileContentForTest("/* comments */ fun data() = 0") | ||
.findChildByClass(KtNamedFunction::class.java)!! | ||
.buildFullSignature() | ||
|
||
assertThat(result).isEqualTo("Test.kt\$fun data()") | ||
} | ||
|
||
@Test | ||
fun `function throws exception`() { | ||
assertThatThrownBy { | ||
compileContentForTest("{ fun data() = 0 }") | ||
.findChildByClass(KtNamedFunction::class.java)!! | ||
.buildFullSignature() | ||
} | ||
.isInstanceOf(IllegalArgumentException::class.java) | ||
.hasMessageContaining("Error building function signature") | ||
} | ||
} |