Skip to content

Commit

Permalink
improvement: Print array contents instead of toString
Browse files Browse the repository at this point in the history
Martin was adamant that we should always use toString instead of pprint which we use for Scala 2, but for Arrays it is quite useless and it seems REPL is also printing contents.
  • Loading branch information
tgodzik committed Jun 19, 2024
1 parent d47464a commit 138580d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ object Printing {
}

inline private def nullableToString[T](value: T) = {
if (value != null) value.toString else "null"
value match
case arr: Array[_] => arr.mkString("Array(", ", ", ")")
case null => "null"
case _ => value.toString()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,27 @@ class WorksheetSuite extends BaseSuite {
|""".stripMargin
)

checkDecorations(
"arrays",
"""
|val x = Array(1, 2, 3)
|val y = Array("a", "b")
|""".stripMargin,
"""|<val x = Array(1, 2, 3)> // : Array[Int] = Array...
|x: Array[Int] = Array(1, 2, 3)
|<val y = Array("a", "b")> // : Array[String] = Ar...
|y: Array[String] = Array("a", "b")
|""".stripMargin,
compat = Map(
Compat.Scala3 ->
"""|<val x = Array(1, 2, 3)> // : Array[Int] = Array...
|x: Array[Int] = Array(1, 2, 3)
|<val y = Array("a", "b")> // : Array[String] = Ar...
|y: Array[String] = Array(a, b)
|""".stripMargin
)
)

checkDecorations(
"infix",
"""|import scala.language.postfixOps
Expand Down

0 comments on commit 138580d

Please sign in to comment.