@@ -15,23 +15,23 @@ trait JsonMatchers {
1515
1616 private implicit val diffJson : Diff [Json ] = new Diff [Json ] {
1717 def apply (
18- left : Json ,
19- right : Json ,
20- toIgnore : List [_root_.com.softwaremill.diffx. FieldPath ]
18+ left : Json ,
19+ right : Json ,
20+ context : DiffContext
2121 ): DiffResult = {
2222
2323 def diffPrimative [A ](leftA : Option [A ], rightA : Option [A ])(
24- show : A => String
24+ show : A => String
2525 ): Option [DiffResult ] =
2626 diffWith(leftA, rightA) { (leftValue, rightValue) =>
2727 if (leftValue == rightValue)
28- Identical (show(leftValue))
28+ IdenticalValue (show(leftValue))
2929 else
3030 DiffResultValue (show(leftValue), show(rightValue))
3131 }
3232
3333 def diffWith [A ](leftA : Option [A ], rightA : Option [A ])(
34- fn : (A , A ) => DiffResult
34+ fn : (A , A ) => DiffResult
3535 ): Option [DiffResult ] = {
3636 for {
3737 leftValue <- leftA
@@ -46,16 +46,15 @@ trait JsonMatchers {
4646 .orElse(diffPrimative(left.bool, right.bool)(_.asJson.nospaces))
4747 .orElse({
4848 if (left.isNull && right.isNull)
49- Some (Identical (left.asJson.nospaces))
49+ Some (IdenticalValue (left.asJson.nospaces))
5050 else
5151 None
5252 })
5353 .orElse(diffWith(left.array, right.array) { (leftArr, rightArr) =>
5454 val zipped : immutable.Seq [(Json , Json )] = leftArr.zip(rightArr)
55- val diffs : immutable.Seq [DiffResult ] = zipped.map {
56- case (a, b) =>
57- val d : DiffResult = diffJson(a, b)
58- d
55+ val diffs : immutable.Seq [DiffResult ] = zipped.map { case (a, b) =>
56+ val d : DiffResult = diffJson(a, b)
57+ d
5958 }
6059
6160 val missing = leftArr.drop(rightArr.size).map(DiffResultMissing .apply)
@@ -65,49 +64,45 @@ trait JsonMatchers {
6564 val all = (diffs ++ missing ++ additional).toList
6665
6766 if (all.forall(_.isIdentical)) {
68- Identical (all)
67+ IdenticalValue (all)
6968 } else {
7069 DiffResultJsArray (all)
7170 }
7271 })
73- .orElse(diffWith(left.obj, right.obj) {
74- case (leftObj, rightObj) =>
75- val leftMap = leftObj.toMap
76- val m : List [(DiffResult , DiffResult )] = leftObj.toList.map {
77- case (key, leftValue) =>
78- rightObj(key) match {
79- case Some (rightValue) =>
80- val d : DiffResult = diffJson(leftValue, rightValue)
81- Identical (key) -> d
82- case None =>
83- DiffResultMissing (key) -> DiffResultMissing (leftValue)
84- }
72+ .orElse(diffWith(left.obj, right.obj) { case (leftObj, rightObj) =>
73+ val leftMap = leftObj.toMap
74+ val m : List [(DiffResult , DiffResult )] =
75+ leftObj.toList.map { case (key, leftValue) =>
76+ rightObj(key) match {
77+ case Some (rightValue) =>
78+ val d : DiffResult = diffJson(leftValue, rightValue)
79+ IdenticalValue (key) -> d
80+ case None =>
81+ DiffResultMissing (key) -> DiffResultMissing (leftValue)
82+ }
8583 }
8684
87- val rightKeys = rightObj.toMap.keySet
88- val leftKeys = leftMap.keySet
89- val additional : List [(DiffResult , DiffResult )] = rightKeys.toList
90- .filterNot(leftKeys.contains)
91- .flatMap(
92- k =>
93- rightObj(k).map(
94- v => DiffResultAdditional (k) -> DiffResultAdditional (v)
95- )
96- )
97-
98- val all = m ++ additional
99- if (all.forall { case (k, v) => k.isIdentical && v.isIdentical }) {
100- Identical (leftObj)
101- } else {
102- DiffResultJson (all.toMap)
103- }
85+ val rightKeys = rightObj.toMap.keySet
86+ val leftKeys = leftMap.keySet
87+ val additional : List [(DiffResult , DiffResult )] = rightKeys.toList
88+ .filterNot(leftKeys.contains)
89+ .flatMap(k =>
90+ rightObj(k)
91+ .map(v => DiffResultAdditional (k) -> DiffResultAdditional (v))
92+ )
93+
94+ val all = m ++ additional
95+ if (all.forall { case (k, v) => k.isIdentical && v.isIdentical }) {
96+ IdenticalValue (leftObj)
97+ } else {
98+ DiffResultJson (all.toMap)
99+ }
104100 })
105101 .getOrElse(DiffResultValue (left, right))
106102 }
107103 }
108104
109- /**
110- * Checks if the given json objects are equivalent.
105+ /** Checks if the given json objects are equivalent.
111106 */
112107 def matchJson (right : String ): Matcher [String ] =
113108 Matcher [String ] { left =>
@@ -128,7 +123,7 @@ trait JsonMatchers {
128123 )
129124 case (Right (leftJs), Right (rightJs)) =>
130125 val diffResult = Diff .compare(leftJs, rightJs)
131- val s = diffResult.show
126+ val s = diffResult.show()
132127 MatchResult (
133128 matches = diffResult.isIdentical,
134129 rawFailureMessage = " Json did not match.\n " + s,
@@ -159,7 +154,7 @@ trait JsonMatchers {
159154 }
160155
161156 def matchJsonGolden [T : EncodeJson : DecodeJson : ClassTag ](
162- value : T
157+ value : T
163158 ): Matcher [String ] = {
164159 Matcher [String ] { jsonString : String =>
165160 val valueAsJson = value.asJson
0 commit comments