Skip to content

Commit

Permalink
Modify Prettifier.truncateAt to work on case classes
Browse files Browse the repository at this point in the history
  • Loading branch information
mdedetrich committed Aug 4, 2022
1 parent aab0ba6 commit 417bf76
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Expand Up @@ -402,6 +402,14 @@ class PrettifierSpec extends funspec.AnyFunSpec with matchers.should.Matchers {
val prettifier = Prettifier.truncateAt(SizeLimit(2))
prettifier(col) shouldBe "List(1, 2, ...)"
}

case class CaseClazz(data: List[Int])

it("should truncate collection inside of a case class when used with Prettifier.truncateAt") {
val caseClass = CaseClazz(List(1, 2, 3))
val prettifier = Prettifier.truncateAt(SizeLimit(2))
prettifier(caseClass) shouldBe "CaseClazz(List(1, 2, ...))"
}
}
}

2 changes: 2 additions & 0 deletions jvm/scalactic/src/main/scala/org/scalactic/Prettifier.scala
Expand Up @@ -277,6 +277,8 @@ private[scalactic] class TruncatingPrettifier(sizeLimit: SizeLimit) extends Defa
else
theToString
// SKIP-SCALATESTJS,NATIVE-END
case caseClazz: Product =>
s"${caseClazz.productPrefix}(" + caseClazz.productIterator.map(prettify(_, processed + caseClazz)).mkString(", ") + ")"
case anythingElse => anythingElse.toString
}
}
Expand Down

0 comments on commit 417bf76

Please sign in to comment.