Skip to content

Commit

Permalink
tests for message
Browse files Browse the repository at this point in the history
  • Loading branch information
hbmartin committed Oct 10, 2020
1 parent 40efe36 commit 3dc6355
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ class ClassOrdering(config: Config = Config.empty) : Rule(config) {
}
}

private fun generateMessage(misorderedPair: Pair<KtDeclaration, KtDeclaration>): String {
return "${misorderedPair.first.name} (${misorderedPair.first.printableDeclaration}) should not come before " +
"${misorderedPair.second.name} (${misorderedPair.second.printableDeclaration})"
private fun generateMessage(misordered: Pair<KtDeclaration, KtDeclaration>): String {
return "${misordered.first.name} (${misordered.first.printableDeclaration}) should not come before " +
"${misordered.second.name} (${misordered.second.printableDeclaration})"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ class ClassOrderingSpec : Spek({
}
""".trimIndent()

assertThat(subject.compileAndLint(code)).hasSize(1)
val findings = subject.compileAndLint(code)
assertThat(findings).hasSize(1)
assertThat(findings[0].message).isEqualTo("OutOfOrder (secondary constructor) " +
"should not come before null (class initializer)")
}

it("reports when secondary constructor is out of order") {
Expand All @@ -96,7 +99,10 @@ class ClassOrderingSpec : Spek({
}
""".trimIndent()

assertThat(subject.compileAndLint(code)).hasSize(1)
val findings = subject.compileAndLint(code)
assertThat(findings).hasSize(1)
assertThat(findings[0].message).isEqualTo("OutOfOrder (secondary constructor) " +
"should not come before y (property)")
}

it("reports when method is out of order") {
Expand All @@ -118,7 +124,9 @@ class ClassOrderingSpec : Spek({
}
""".trimIndent()

assertThat(subject.compileAndLint(code)).hasSize(1)
val findings = subject.compileAndLint(code)
assertThat(findings).hasSize(1)
assertThat(findings[0].message).isEqualTo("returnX (function) should not come before y (property)")
}

it("reports when companion object is out of order") {
Expand All @@ -140,7 +148,9 @@ class ClassOrderingSpec : Spek({
}
""".trimIndent()

assertThat(subject.compileAndLint(code)).hasSize(1)
val findings = subject.compileAndLint(code)
assertThat(findings).hasSize(1)
assertThat(findings[0].message).isEqualTo("Companion (companion) should not come before returnX (function)")
}

it("does not report nested class order") {
Expand Down

0 comments on commit 3dc6355

Please sign in to comment.