From 9d6982c0ee8c8cfc432e97542376091efc01c121 Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Wed, 19 Jun 2024 16:09:17 +0200 Subject: [PATCH] improvement: Also print nested arrays --- .../src/main/scala-3/mdoc/internal/document/Printing.scala | 4 ++-- .../src/test/scala/tests/worksheets/WorksheetSuite.scala | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/runtime/src/main/scala-3/mdoc/internal/document/Printing.scala b/runtime/src/main/scala-3/mdoc/internal/document/Printing.scala index a8de7dcde..77cae047f 100644 --- a/runtime/src/main/scala-3/mdoc/internal/document/Printing.scala +++ b/runtime/src/main/scala-3/mdoc/internal/document/Printing.scala @@ -14,9 +14,9 @@ object Printing { out.append(nullableToString(value).replace("\n", "")) } - inline private def nullableToString[T](value: T) = { + private def nullableToString[T](value: T): String = { value match - case arr: Array[_] => arr.mkString("Array(", ", ", ")") + case arr: Array[_] => arr.map(nullableToString).mkString("Array(", ", ", ")") case null => "null" case _ => value.toString() } diff --git a/tests/worksheets/src/test/scala/tests/worksheets/WorksheetSuite.scala b/tests/worksheets/src/test/scala/tests/worksheets/WorksheetSuite.scala index 319067ea0..bdfb0b729 100644 --- a/tests/worksheets/src/test/scala/tests/worksheets/WorksheetSuite.scala +++ b/tests/worksheets/src/test/scala/tests/worksheets/WorksheetSuite.scala @@ -76,11 +76,14 @@ class WorksheetSuite extends BaseSuite { """ |val x = Array(1, 2, 3) |val y = Array("a", "b") + |val arrays = Array(Array(1, 2, 3), Array(2, 3, 4)) |""".stripMargin, """| // : Array[Int] = Array... |x: Array[Int] = Array(1, 2, 3) | // : Array[String] = Ar... |y: Array[String] = Array("a", "b") + | // : Array[Array[Int]] ... + |arrays: Array[Array[Int]] = Array(Array(1, 2, 3), Array(2, 3, 4)) |""".stripMargin, compat = Map( Compat.Scala3 -> @@ -88,6 +91,8 @@ class WorksheetSuite extends BaseSuite { |x: Array[Int] = Array(1, 2, 3) | // : Array[String] = Ar... |y: Array[String] = Array(a, b) + | // : Array[Array[Int]] ... + |arrays: Array[Array[Int]] = Array(Array(1, 2, 3), Array(2, 3, 4)) |""".stripMargin ) )