From 13659f631273575c98c5575fb1af4c5736802c29 Mon Sep 17 00:00:00 2001 From: Jacob Wang Date: Tue, 1 Feb 2022 23:17:17 +0000 Subject: [PATCH] fix printing of value differ results --- docs/docs/docs/ConfiguringDiffers.md | 2 +- .../scala/difflicious/DiffResultPrinter.scala | 20 +++++++++---------- .../test/scala/difflicious/DifferSpec.scala | 4 ++-- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/docs/docs/docs/ConfiguringDiffers.md b/docs/docs/docs/ConfiguringDiffers.md index e0e2385..2be2544 100644 --- a/docs/docs/docs/ConfiguringDiffers.md +++ b/docs/docs/docs/ConfiguringDiffers.md @@ -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]]] diff --git a/modules/core/src/main/scala/difflicious/DiffResultPrinter.scala b/modules/core/src/main/scala/difflicious/DiffResultPrinter.scala index 8c34aa3..1b197a0 100644 --- a/modules/core/src/main/scala/difflicious/DiffResultPrinter.scala +++ b/modules/core/src/main/scala/difflicious/DiffResultPrinter.scala @@ -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})" @@ -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) @@ -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) } } } diff --git a/modules/coretest/src/test/scala/difflicious/DifferSpec.scala b/modules/coretest/src/test/scala/difflicious/DifferSpec.scala index 6e5ef01..f44956b 100644 --- a/modules/coretest/src/test/scala/difflicious/DifferSpec.scala +++ b/modules/coretest/src/test/scala/difflicious/DifferSpec.scala @@ -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, ) }