Skip to content

Commit

Permalink
Fixed the type == class case.
Browse files Browse the repository at this point in the history
  • Loading branch information
agilesteel committed Dec 1, 2015
1 parent 73c1ff8 commit e7f0b99
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
17 changes: 11 additions & 6 deletions src/main/scala/spells/XRayModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@ trait XrayModule {
typeTag: Option[TypeTag[T]],
final val additionalContent: immutable.Seq[(String, String)] = immutable.Seq.empty
) extends CustomRendering {
private lazy val safeAdditionalContent: immutable.Seq[(String, String)] = Option(additionalContent).getOrElse(immutable.Seq.empty)

final def withAdditionalContent(content: immutable.Seq[(String, String)]): XrayModule#XrayReport[T] =
new XrayReport(value, duration, stackTraceElement, timestamp, description, thread, style, rendering, typeTag, additionalContent ++ Option(content).getOrElse(immutable.Seq.empty))
new XrayReport(value, duration, stackTraceElement, timestamp, description, thread, style, rendering, typeTag, safeAdditionalContent ++ Option(content).getOrElse(immutable.Seq.empty))

override final def rendered(implicit availableWidthInCharacters: CustomRenderingModule#AvailableWidthInCharacters = CustomRendering.Defaults.AvailableWidthInCharacters): String = {
def lines(availableWidthInCharacters: Int): Seq[(String, String)] = {
Expand Down Expand Up @@ -126,18 +128,21 @@ trait XrayModule {
typeTag.fold(Vector(classTuple)) { tag =>
val decodedTypeName = tag.tpe.toString.withDecodedScalaSymbols
val typeTuple = ifNotIgnored("Type", decodedTypeName)
val shouldIgnoreClass = SpellsConfig.xray.report.IgnoredContentKeys.contains("Class")
val shouldNotIgnoreClass = !SpellsConfig.xray.report.IgnoredContentKeys.contains("Class")
val shouldIgnoreType = SpellsConfig.xray.report.IgnoredContentKeys.contains("Type")

if (decodedClassName == decodedTypeName && shouldIgnoreClass) Vector(typeTuple) else Vector(classTuple, typeTuple)
if (shouldIgnoreType && shouldNotIgnoreClass) Vector(classTuple)
else if (decodedClassName == decodedTypeName) Vector(typeTuple)
else Vector(classTuple, typeTuple)
}
}

val liftedAdditionalContent: immutable.Seq[Option[(String, String)]] =
Option(additionalContent).getOrElse(immutable.Seq.empty) collect {
val liftedAdditionalContentIfNotIgnored: immutable.Seq[Option[(String, String)]] =
safeAdditionalContent collect {
case (key, value) => ifNotIgnored(key, value)
}

(metaContent ++ liftedAdditionalContent ++ valueRelatedContent ++ classOrTypeOrBoth).flatten
(metaContent ++ liftedAdditionalContentIfNotIgnored ++ valueRelatedContent ++ classOrTypeOrBoth).flatten
}

contentLines :+ "Value" -> (Option(value).fold("null") {
Expand Down
5 changes: 3 additions & 2 deletions src/test/scala/spells/configuration/ConfigurationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,14 @@ class ConfigurationTests extends UnitTestConfiguration {
lazy val thread = Thread.currentThread
lazy val theTypeTag = Some(typeTag[java.lang.String])
lazy val `class` = "java.lang.String"
lazy val `type` = "java.lang.String"
}

import StolenFromXrayReportRenderingTests._
val renderedReport = createReport().rendered

renderedReport should include(`class`)
// renderedReport should not include s"| ${`type`}"
renderedReport should include("Class | " + `class`)
renderedReport should not include ("Type | " + `type`)
}
}

Expand Down
16 changes: 13 additions & 3 deletions src/test/scala/spells/user/XrayReportRenderingTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package spells.user

import java.text.SimpleDateFormat
import java.util.{ Date, Calendar }
import scala.collection._
import scala.concurrent.duration._
import scala.reflect.runtime.universe._

Expand Down Expand Up @@ -219,11 +220,18 @@ class XrayReportRenderingTests extends spells.UnitTestConfiguration {

val multipleAdditions =
report.withAdditionalContent(List("Key1" -> "Value1"))
.withAdditionalContent(List("Key2" -> "Value2")).rendered
.withAdditionalContent(List("Key2" -> "Value2"))
.rendered

multipleAdditions should include("Key1 | Value1")
multipleAdditions should include("Key2 | Value2")
}

test("Manually passed in additional content") {
XrayReportRenderingTests.createReport(additionalContent = null)
.withAdditionalContent(List("Key" -> "Value"))
.rendered should include("Key | Value")
}
}

object XrayReportRenderingTests {
Expand All @@ -234,7 +242,8 @@ object XrayReportRenderingTests {
timestamp: Calendar = timestamp,
description: String = description,
rendering: T => spells.CustomRenderingModule#CustomRendering = CustomRendering.Defaults.Any,
typeTag: Option[TypeTag[T]] = theTypeTag
typeTag: Option[TypeTag[T]] = theTypeTag,
additionalContent: immutable.Seq[(String, String)] = immutable.Seq.empty
): XrayReport[T] =
new XrayReport[T](
value = reportValue,
Expand All @@ -244,7 +253,8 @@ object XrayReportRenderingTests {
description = description,
thread = Thread.currentThread,
rendering = rendering,
typeTag = typeTag
typeTag = typeTag,
additionalContent = additionalContent
)

private lazy val reportValue = new `Encoded + Whatever`
Expand Down

0 comments on commit e7f0b99

Please sign in to comment.