Skip to content

Commit

Permalink
Add line ending tests for autocorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
3flex committed Apr 29, 2024
1 parent efd5660 commit 8e94aee
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,5 +286,35 @@ class RunnerSpec {
""".trimIndent()
)
}

@Test
fun `keeps LF line endings after autocorrect`() {
val inputPath = resourceAsPath("/autocorrect/SingleRuleLF.kt")

assertThatThrownBy {
Runner(parseArguments(args + inputPath.toString()), outPrintStream, errPrintStream).execute()
}.isInstanceOf(IssuesFound::class.java)

assertThat(errPrintStream.toString()).isEmpty()
assertThat(outPrintStream.toString())
.contains("${inputPath.absolutePathString()}:3:1: Needless blank line(s) [NoConsecutiveBlankLines]")
.contains("$modificationMessagePrefix${inputPath.absolutePathString()}$modificationMessageSuffix")
assertThat(inputPath).content().isEqualTo("class Test {\n\n}\n")
}

@Test
fun `keeps CRLF line endings after autocorrect`() {
val inputPath = resourceAsPath("/autocorrect/SingleRuleCRLF.kt")

assertThatThrownBy {
Runner(parseArguments(args + inputPath.toString()), outPrintStream, errPrintStream).execute()
}.isInstanceOf(IssuesFound::class.java)

assertThat(errPrintStream.toString()).isEmpty()
assertThat(outPrintStream.toString())
.contains("${inputPath.absolutePathString()}:3:1: Needless blank line(s) [NoConsecutiveBlankLines]")
.contains("$modificationMessagePrefix${inputPath.absolutePathString()}$modificationMessageSuffix")
assertThat(inputPath).content().isEqualTo("class Test {\r\n\r\n}\r\n")
}
}
}
2 changes: 2 additions & 0 deletions detekt-cli/src/test/resources/autocorrect/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SingleRuleLF.kt text eol=lf
SingleRuleCRLF.kt text eol=crlf
9 changes: 9 additions & 0 deletions detekt-cli/src/test/resources/autocorrect/SingleRuleCRLF.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Test {







}
9 changes: 9 additions & 0 deletions detekt-cli/src/test/resources/autocorrect/SingleRuleLF.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Test {







}

0 comments on commit 8e94aee

Please sign in to comment.