From b67d402ef36c166f2ee1cec0e60fdae51a93ae04 Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Fri, 25 Nov 2022 09:09:57 -0800 Subject: [PATCH] FormatAssertions: improve parseException2Message --- .../scala/org/scalafmt/util/FormatAssertions.scala | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scalafmt-tests/src/test/scala/org/scalafmt/util/FormatAssertions.scala b/scalafmt-tests/src/test/scala/org/scalafmt/util/FormatAssertions.scala index b1aeb5c8f2..24610425e0 100644 --- a/scalafmt-tests/src/test/scala/org/scalafmt/util/FormatAssertions.scala +++ b/scalafmt-tests/src/test/scala/org/scalafmt/util/FormatAssertions.scala @@ -81,13 +81,15 @@ trait FormatAssertions { def parseException2Message(e: ParseException, obtained: String): String = { val range = 3 - val i = e.pos.startLine - val lines = obtained.linesIterator.toVector + val lines = obtained.linesIterator + lines.drop(e.pos.startLine - range) + val pre = lines.take(range).mkString("\n") + val post = lines.take(range).mkString("\n") val arrow = (" " * (e.pos.startColumn - 2)) + "^" - s"""${lines.slice(i - range, i + 1).mkString("\n")} + s"""$pre |$arrow |${e.getMessage} - |${lines.slice(i + 1, i + range).mkString("\n")} + |$post |$obtained |""".stripMargin }