Skip to content

Commit

Permalink
Fix scalameta#211, handle test case on last line in the source file
Browse files Browse the repository at this point in the history
  • Loading branch information
Olafur Pall Geirsson committed Oct 19, 2020
1 parent b4628a1 commit 213c689
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ docstrings = JavaDoc
project.git=true
project.excludeFilters = [
".*scala-3"
"LinesSuite.scala"
]
14 changes: 7 additions & 7 deletions munit/shared/src/main/scala/munit/internal/console/Lines.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ class Lines extends Serializable {
)
val slice = lines.slice(location.line - 2, location.line + 1)
val out = new StringBuilder()
if (slice.length == 3) {
if (slice.length >= 2) {
val width = (location.line + 1).toString().length()
def format(n: Int): String = {
val number = n.toString() + ":"
val padding = " " * (width - number.length() + 1)
number + padding
s"$n:".padTo(width, ' ')
}
val isMultilineMessage = message.contains('\n')
out
Expand All @@ -51,9 +49,11 @@ class Lines extends Serializable {
.append(format(location.line))
.append(slice(1))
.append(AnsiColors.Reset)
.append('\n')
.append(format(location.line + 1))
.append(slice(2))
if (slice.length >= 3)
out
.append('\n')
.append(format(location.line + 1))
.append(slice(2))
if (isMultilineMessage) {
out.append('\n').append(message)
}
Expand Down
10 changes: 9 additions & 1 deletion tests/shared/src/test/scala/munit/LinesSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,12 @@ class LinesSuite extends FunSuite {
assertNoDiff(obtained, expected)
}
}
}

val line = Location.generate.line + 7
val endOfFileExpected =
s"""|LinesSuite.scala:${line} issue-211
|${line - 1}: // hello!
|${line}: check("end-of-file", "issue-211", Location.generate, endOfFileExpected ) }
|""".stripMargin
// hello!
check("end-of-file", "issue-211", Location.generate, endOfFileExpected ) }

0 comments on commit 213c689

Please sign in to comment.