Skip to content

Commit

Permalink
Merge pull request #21 from jatcwang/fix_value_differ_print
Browse files Browse the repository at this point in the history
Fix printing of value differ results
  • Loading branch information
jatcwang authored Feb 2, 2022
2 parents eb74eb1 + 13659f6 commit 4aa81d0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/docs/docs/ConfiguringDiffers.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ val differWithSubTypesFieldIgnored = sealedTraitDiffer.ignoreAt(_.each.subType[S
## Replace differs

You can completely replace the underlying differ at a path using `replace`. This is useful when you want to reuse an existing
Differ you have extensively configured.
Differ you already have.

```scala mdoc:silent
val mapDiffer: Differ[Map[String, List[Person]]] = Differ[Map[String, List[Person]]]
Expand Down
20 changes: 9 additions & 11 deletions modules/core/src/main/scala/difflicious/DiffResultPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@ object DiffResultPrinter {
case r: DiffResult.RecordResult => {
val indentForFields = Str("\n" ++ indentLevel.asSpacesPlus1)
val fieldsStr = r.fields
.map {
case (fieldName, vRes) =>
Str(fieldName) ++ ": " ++ consoleOutput(
vRes,
indentLevel = indentLevel + 1,
) ++ ","
.map { case (fieldName, vRes) =>
Str(fieldName) ++ ": " ++ consoleOutput(
vRes,
indentLevel = indentLevel + 1,
) ++ ","
}
.foldLeft(Str("")) { case (accum, nextStr) => accum ++ indentForFields ++ nextStr }
val allStr = Str(s"${r.typeName.short}(") ++ fieldsStr ++ s"\n${indentLevel.asSpaces})"
Expand All @@ -61,9 +60,8 @@ object DiffResultPrinter {
keyStr ++ " -> " ++ valueStr ++ ","
}
}
.foldLeft(Str("")) {
case (accum, nextStr) =>
accum ++ indentPlusStr ++ nextStr
.foldLeft(Str("")) { case (accum, nextStr) =>
accum ++ indentPlusStr ++ nextStr
}
val allStr = Str(r.typeName.short ++ "(") ++ keyValStr ++ s"\n${indentLevel.asSpaces})"
colorOnMatchType(allStr, r.pairType)
Expand Down Expand Up @@ -92,8 +90,8 @@ object DiffResultPrinter {
obtainedStr.overlay(colorObtained) ++ " -> " ++ expectedStr.overlay(colorExpected)
}
}
case ValueResult.ObtainedOnly(obtained, _) => fansi.Str(obtained)
case ValueResult.ExpectedOnly(expected, _) => fansi.Str(expected)
case ValueResult.ObtainedOnly(obtained, _) => fansi.Str(obtained).overlay(colorObtained)
case ValueResult.ExpectedOnly(expected, _) => fansi.Str(expected).overlay(colorExpected)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions modules/coretest/src/test/scala/difflicious/DifferSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class DifferSpec extends ScalaCheckSuite with ScalaVersionDependentTests {
"c" -> EqClass(3),
),
s"""Map(
| $R"b"$X -> EqClass(2),
| $R"b"$X -> ${R}EqClass(2)${X},
| "a" -> EqClass(1),
| $G"c"$X -> EqClass(3),
| $G"c"$X -> ${G}EqClass(3)${X},
|)""".stripMargin,
)
}
Expand Down

0 comments on commit 4aa81d0

Please sign in to comment.