diff --git a/mdoc/src/main/scala-3/mdoc/internal/markdown/CodePrinter.scala b/mdoc/src/main/scala-3/mdoc/internal/markdown/CodePrinter.scala index b199579a8..b2bd5f124 100644 --- a/mdoc/src/main/scala-3/mdoc/internal/markdown/CodePrinter.scala +++ b/mdoc/src/main/scala-3/mdoc/internal/markdown/CodePrinter.scala @@ -9,11 +9,13 @@ class CodePrinter(ps: PrintStream, baseIndent: Int = 0, baseNest: Int = 0) { def append(s: String) = {ps.append(s); this } - def println(s: String) = {ps.print(indent + s + "\n"); this} + def println(s: String) = { + ps.print(indent + s + "\n"); this + } def definition(header: String)(cb: CodePrinter => Unit): CodePrinter = { - val newCB = new CodePrinter(ps, baseIndent + 1, baseNest) - + val newCB = new CodePrinter(ps, baseIndent + 1, nestCount) + this.println(header + " {") cb(newCB) this.println("}") diff --git a/mdoc/src/main/scala-3/mdoc/internal/markdown/Instrumenter.scala b/mdoc/src/main/scala-3/mdoc/internal/markdown/Instrumenter.scala index 4ba1c5c8f..db90e3098 100644 --- a/mdoc/src/main/scala-3/mdoc/internal/markdown/Instrumenter.scala +++ b/mdoc/src/main/scala-3/mdoc/internal/markdown/Instrumenter.scala @@ -78,7 +78,8 @@ class Instrumenter( } } - sb.println("\n$doc.endStatement();") + sb.println("\n") // newline for posterity + sb.println("$doc.endStatement();") case Nil => } diff --git a/tests/tests/src/main/scala/tests/BaseSuite.scala b/tests/tests/src/main/scala/tests/BaseSuite.scala index ee2b2b038..9bad6e891 100644 --- a/tests/tests/src/main/scala/tests/BaseSuite.scala +++ b/tests/tests/src/main/scala/tests/BaseSuite.scala @@ -11,11 +11,15 @@ class BaseSuite extends FunSuite { loc: Location ): Unit = { super.assertNoDiff( - Compat(obtained, Map.empty, postProcessObtained), - Compat(expected, Map.empty, postProcessExpected), + Compat(processOutput(obtained), Map.empty, postProcessObtained), + Compat(processOutput(expected), Map.empty, postProcessExpected), clue ) } + + private def processOutput(raw: String) = + raw.replaceAll("\t", " ") + object OnlyScala213 extends munit.Tag("OnlyScala213") object OnlyScala3 extends munit.Tag("OnlyScala3") object SkipScala3 extends munit.Tag("SkipScala3") diff --git a/tests/unit/src/test/scala/tests/markdown/CrashSuite.scala b/tests/unit/src/test/scala/tests/markdown/CrashSuite.scala index 1078622da..c41a0ba86 100644 --- a/tests/unit/src/test/scala/tests/markdown/CrashSuite.scala +++ b/tests/unit/src/test/scala/tests/markdown/CrashSuite.scala @@ -236,6 +236,40 @@ class CrashSuite extends BaseMarkdownSuite { ) ) + check( + "significant-indentation".tag(OnlyScala3), + """ + |```scala mdoc:nest + |println("what!") + |``` + | + |```scala mdoc:crash + |def hello(x: Int) = + | if x != 0 then + | println(x) + | x / 0 + |hello(5) + |``` + |""".stripMargin, + """ + |```scala + |println("what!") + |// what! + |``` + | + |```scala + |def hello(x: Int) = + | if x != 0 then + | println(x) + | x / 0 + |hello(5) + |// java.lang.ArithmeticException: / by zero + |// at repl.MdocSession$App.hello$1(significant-indentation.md:19) + |// at repl.MdocSession$App.$init$$$anonfun$1(significant-indentation.md:20) + |// at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18) + |```""".stripMargin + ) + check( "multiple-statements", """