Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prettifier Implementation Enhancements #2156

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 11 additions & 11 deletions jvm/scalactic/src/main/scala/org/scalactic/Prettifier.scala
Expand Up @@ -101,7 +101,7 @@ import scala.util.Success
* <li>`org.scalactic.Bad` to: `Bad("3")`</li>
* <li>`org.scalactic.One` to: `One("3")`</li>
* <li>`org.scalactic.Many` to: `Many("1", "2", "3")`</li>
* <li>`scala.collection.GenTraversable` to: `List("1", "2", "3")`</li>
* <li>`scala.collection.Iterable` to: `List("1", "2", "3")`</li>
* <li>`java.util.Collection` to: `["1", "2", "3"]`</li>
* <li>`java.util.Map` to: `{1="one", 2="two", 3="three"}`</li>
* </ul>
Expand Down Expand Up @@ -224,31 +224,31 @@ private[scalactic] class TruncatingPrettifier(sizeLimit: SizeLimit) extends Defa
override protected def prettifyCollection(o: Any, processed: Set[Any]): String = {
o match {
case many: Many[_] =>
val (taken, truncated) = if (many.size > sizeLimit.value) (many.toIterator.take(sizeLimit.value), true) else (many.toIterator, false)
val (taken, truncated) = if (!many.hasDefiniteSize || many.size > sizeLimit.value) (many.toIterator.take(sizeLimit.value), true) else (many.toIterator, false)
"Many(" + taken.map(prettify(_, processed + many)).mkString(", ") + dotDotDotIfTruncated(truncated) + ")"
case anArray: Array[_] =>
val (taken, truncated) = if (anArray.size > sizeLimit.value) (anArray.take(sizeLimit.value), true) else (anArray, false)
val (taken, truncated) = if (!anArray.hasDefiniteSize || anArray.size > sizeLimit.value) (anArray.take(sizeLimit.value), true) else (anArray, false)
"Array(" + taken.map(prettify(_, processed + anArray)).mkString(", ") + dotDotDotIfTruncated(truncated) + ")"
case aWrappedArray: WrappedArray[_] =>
val (taken, truncated) = if (aWrappedArray.size > sizeLimit.value) (aWrappedArray.take(sizeLimit.value), true) else (aWrappedArray, false)
val (taken, truncated) = if (!aWrappedArray.hasDefiniteSize || aWrappedArray.size > sizeLimit.value) (aWrappedArray.take(sizeLimit.value), true) else (aWrappedArray, false)
"Array(" + taken.map(prettify(_, processed + aWrappedArray)).mkString(", ") + dotDotDotIfTruncated(truncated) + ")"
case a if ArrayHelper.isArrayOps(a) =>
val anArrayOps = ArrayHelper.asArrayOps(a)//
val (taken, truncated) = if (anArrayOps.size > sizeLimit.value) (anArrayOps.iterator.take(sizeLimit.value), true) else (anArrayOps.iterator, false)
"Array(" + taken.map(prettify(_, processed + anArrayOps)).mkString(", ") + dotDotDotIfTruncated(truncated) + ")"
case aGenMap: scala.collection.GenMap[_, _] =>
val (taken, truncated) = if (aGenMap.size > sizeLimit.value) (aGenMap.toIterator.take(sizeLimit.value), true) else (aGenMap.toIterator, false)
val (taken, truncated) = if (!aGenMap.hasDefiniteSize || aGenMap.size > sizeLimit.value) (aGenMap.toIterator.take(sizeLimit.value), true) else (aGenMap.toIterator, false)
ColCompatHelper.className(aGenMap) + "(" +
(taken.map { case (key, value) => // toIterator is needed for consistent ordering
prettify(key, processed + aGenMap) + " -> " + prettify(value, processed + aGenMap)
}).mkString(", ") + dotDotDotIfTruncated(truncated) + ")"
case aGenTraversable: GenTraversable[_] =>
val (taken, truncated) = if (aGenTraversable.size > sizeLimit.value) (aGenTraversable.take(sizeLimit.value), true) else (aGenTraversable, false)
val className = aGenTraversable.getClass.getName
case aIterable: Iterable[_] =>
val (taken, truncated) = if (!aIterable.hasDefiniteSize || aIterable.size > sizeLimit.value) (aIterable.take(sizeLimit.value), true) else (aIterable, false)
val className = aIterable.getClass.getName
if (className.startsWith("scala.xml.NodeSeq$") || className == "scala.xml.NodeBuffer" || className == "scala.xml.Elem")
aGenTraversable.mkString
aIterable.mkString
else
ColCompatHelper.className(aGenTraversable) + "(" + taken.toIterator.map(prettify(_, processed + aGenTraversable)).mkString(", ") + dotDotDotIfTruncated(truncated) + ")" // toIterator is needed for consistent ordering
ColCompatHelper.className(aIterable) + "(" + taken.toIterator.map(prettify(_, processed + aIterable)).mkString(", ") + dotDotDotIfTruncated(truncated) + ")" // toIterator is needed for consistent ordering
// SKIP-SCALATESTJS-START
case javaCol: java.util.Collection[_] =>
// By default java collection follows http://download.java.net/jdk7/archive/b123/docs/api/java/util/AbstractCollection.html#toString()
Expand Down Expand Up @@ -322,7 +322,7 @@ object Prettifier {
* <li>`org.scalactic.Bad` to: `Bad("3")`</li>
* <li>`org.scalactic.One` to: `One("3")`</li>
* <li>`org.scalactic.Many` to: `Many("1", "2", "3")`</li>
* <li>`scala.collection.GenTraversable` to: `List("1", "2", "3")`</li>
* <li>`scala.collection.Iterable` to: `List("1", "2", "3")`</li>
* <li>`java.util.Collection` to: `["1", "2", "3"]`</li>
* <li>`java.util.Map` to: `{1="one", 2="two", 3="three"}`</li>
* </ul>
Expand Down