Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Commit

Permalink
Do not crash on empty KDoc.
Browse files Browse the repository at this point in the history
Fixes #5
  • Loading branch information
hovinen committed Nov 2, 2020
1 parent 57affe8 commit 4970d60
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ internal class KDocScanner(private val kotlinScanner: KotlinScanner) : NodeScann

private fun String.trimOneWhitespace(): String =
if (startsWith(' ') && endsWith(' ')) {
substring(1, length - 1)
substring(1, Integer.max(length - 1, 1))
} else {
this
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3839,6 +3839,25 @@ class KotlinFormatterTest {
)
}

@Test
fun `accepts empty KDoc`() {
val subject = KotlinFormatter(maxLineLength = 40)

val result = subject.format(
"""
/** */
class MyClass
""".trimIndent()
)

assertThat(result).isEqualTo(
"""
/** */
class MyClass
""".trimIndent()
)
}

@Test
fun `maintains a line break between KDoc and object declaration`() {
val subject = KotlinFormatter(maxLineLength = 40)
Expand Down

0 comments on commit 4970d60

Please sign in to comment.