Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit 57cf2d8

Browse files
committed
Fix tuple instances and tests
1 parent 5b2472b commit 57cf2d8

File tree

4 files changed

+39
-118
lines changed

4 files changed

+39
-118
lines changed

core/src/main/scala/com/softwaremill/diffx/TupleInstances.scala

Lines changed: 20 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ trait TupleInstances {
99
context: DiffContext
1010
): DiffResult = {
1111
val results = List("_1" -> d1.apply(left._1, right._1), "_2" -> d2.apply(left._2, right._2)).toMap
12-
if (results.values.forall(_.isIdentical)) {
13-
IdenticalValue(left)
14-
} else {
15-
DiffResultObject("Tuple2", results)
16-
}
12+
DiffResultObject("Tuple2", results)
1713
}
1814
}
1915

@@ -29,11 +25,7 @@ trait TupleInstances {
2925
"_2" -> d2.apply(left._2, right._2),
3026
"_3" -> d3.apply(left._3, right._3)
3127
).toMap
32-
if (results.values.forall(_.isIdentical)) {
33-
IdenticalValue(left)
34-
} else {
35-
DiffResultObject("Tuple3", results)
36-
}
28+
DiffResultObject("Tuple3", results)
3729
}
3830
}
3931

@@ -54,11 +46,7 @@ trait TupleInstances {
5446
"_3" -> d3.apply(left._3, right._3),
5547
"_4" -> d4.apply(left._4, right._4)
5648
).toMap
57-
if (results.values.forall(_.isIdentical)) {
58-
IdenticalValue(left)
59-
} else {
60-
DiffResultObject("Tuple4", results)
61-
}
49+
DiffResultObject("Tuple4", results)
6250
}
6351
}
6452

@@ -81,11 +69,7 @@ trait TupleInstances {
8169
"_4" -> d4.apply(left._4, right._4),
8270
"_5" -> d5.apply(left._5, right._5)
8371
).toMap
84-
if (results.values.forall(_.isIdentical)) {
85-
IdenticalValue(left)
86-
} else {
87-
DiffResultObject("Tuple5", results)
88-
}
72+
DiffResultObject("Tuple5", results)
8973
}
9074
}
9175

@@ -110,11 +94,7 @@ trait TupleInstances {
11094
"_5" -> d5.apply(left._5, right._5),
11195
"_6" -> d6.apply(left._6, right._6)
11296
).toMap
113-
if (results.values.forall(_.isIdentical)) {
114-
IdenticalValue(left)
115-
} else {
116-
DiffResultObject("Tuple6", results)
117-
}
97+
DiffResultObject("Tuple6", results)
11898
}
11999
}
120100

@@ -141,11 +121,7 @@ trait TupleInstances {
141121
"_6" -> d6.apply(left._6, right._6),
142122
"_7" -> d7.apply(left._7, right._7)
143123
).toMap
144-
if (results.values.forall(_.isIdentical)) {
145-
IdenticalValue(left)
146-
} else {
147-
DiffResultObject("Tuple7", results)
148-
}
124+
DiffResultObject("Tuple7", results)
149125
}
150126
}
151127

@@ -174,11 +150,7 @@ trait TupleInstances {
174150
"_7" -> d7.apply(left._7, right._7),
175151
"_8" -> d8.apply(left._8, right._8)
176152
).toMap
177-
if (results.values.forall(_.isIdentical)) {
178-
IdenticalValue(left)
179-
} else {
180-
DiffResultObject("Tuple8", results)
181-
}
153+
DiffResultObject("Tuple8", results)
182154
}
183155
}
184156

@@ -209,11 +181,7 @@ trait TupleInstances {
209181
"_8" -> d8.apply(left._8, right._8),
210182
"_9" -> d9.apply(left._9, right._9)
211183
).toMap
212-
if (results.values.forall(_.isIdentical)) {
213-
IdenticalValue(left)
214-
} else {
215-
DiffResultObject("Tuple9", results)
216-
}
184+
DiffResultObject("Tuple9", results)
217185
}
218186
}
219187

@@ -247,11 +215,7 @@ trait TupleInstances {
247215
"_9" -> d9.apply(left._9, right._9),
248216
"_10" -> d10.apply(left._10, right._10)
249217
).toMap
250-
if (results.values.forall(_.isIdentical)) {
251-
IdenticalValue(left)
252-
} else {
253-
DiffResultObject("Tuple10", results)
254-
}
218+
DiffResultObject("Tuple10", results)
255219
}
256220
}
257221

@@ -287,11 +251,7 @@ trait TupleInstances {
287251
"_10" -> d10.apply(left._10, right._10),
288252
"_11" -> d11.apply(left._11, right._11)
289253
).toMap
290-
if (results.values.forall(_.isIdentical)) {
291-
IdenticalValue(left)
292-
} else {
293-
DiffResultObject("Tuple11", results)
294-
}
254+
DiffResultObject("Tuple11", results)
295255
}
296256
}
297257

@@ -329,11 +289,7 @@ trait TupleInstances {
329289
"_11" -> d11.apply(left._11, right._11),
330290
"_12" -> d12.apply(left._12, right._12)
331291
).toMap
332-
if (results.values.forall(_.isIdentical)) {
333-
IdenticalValue(left)
334-
} else {
335-
DiffResultObject("Tuple12", results)
336-
}
292+
DiffResultObject("Tuple12", results)
337293
}
338294
}
339295

@@ -419,11 +375,7 @@ trait TupleInstances {
419375
"_13" -> d13.apply(left._13, right._13),
420376
"_14" -> d14.apply(left._14, right._14)
421377
).toMap
422-
if (results.values.forall(_.isIdentical)) {
423-
IdenticalValue(left)
424-
} else {
425-
DiffResultObject("Tuple14", results)
426-
}
378+
DiffResultObject("Tuple14", results)
427379
}
428380
}
429381

@@ -467,11 +419,7 @@ trait TupleInstances {
467419
"_14" -> d14.apply(left._14, right._14),
468420
"_15" -> d15.apply(left._15, right._15)
469421
).toMap
470-
if (results.values.forall(_.isIdentical)) {
471-
IdenticalValue(left)
472-
} else {
473-
DiffResultObject("Tuple15", results)
474-
}
422+
DiffResultObject("Tuple15", results)
475423
}
476424
}
477425

@@ -517,11 +465,7 @@ trait TupleInstances {
517465
"_15" -> d15.apply(left._15, right._15),
518466
"_16" -> d16.apply(left._16, right._16)
519467
).toMap
520-
if (results.values.forall(_.isIdentical)) {
521-
IdenticalValue(left)
522-
} else {
523-
DiffResultObject("Tuple16", results)
524-
}
468+
DiffResultObject("Tuple16", results)
525469
}
526470
}
527471

@@ -569,11 +513,7 @@ trait TupleInstances {
569513
"_16" -> d16.apply(left._16, right._16),
570514
"_17" -> d17.apply(left._17, right._17)
571515
).toMap
572-
if (results.values.forall(_.isIdentical)) {
573-
IdenticalValue(left)
574-
} else {
575-
DiffResultObject("Tuple17", results)
576-
}
516+
DiffResultObject("Tuple17", results)
577517
}
578518
}
579519

@@ -623,11 +563,7 @@ trait TupleInstances {
623563
"_17" -> d17.apply(left._17, right._17),
624564
"_18" -> d18.apply(left._18, right._18)
625565
).toMap
626-
if (results.values.forall(_.isIdentical)) {
627-
IdenticalValue(left)
628-
} else {
629-
DiffResultObject("Tuple18", results)
630-
}
566+
DiffResultObject("Tuple18", results)
631567
}
632568
}
633569

@@ -679,11 +615,7 @@ trait TupleInstances {
679615
"_18" -> d18.apply(left._18, right._18),
680616
"_19" -> d19.apply(left._19, right._19)
681617
).toMap
682-
if (results.values.forall(_.isIdentical)) {
683-
IdenticalValue(left)
684-
} else {
685-
DiffResultObject("Tuple19", results)
686-
}
618+
DiffResultObject("Tuple19", results)
687619
}
688620
}
689621

@@ -738,11 +670,7 @@ trait TupleInstances {
738670
"_19" -> d19.apply(left._19, right._19),
739671
"_20" -> d20.apply(left._20, right._20)
740672
).toMap
741-
if (results.values.forall(_.isIdentical)) {
742-
IdenticalValue(left)
743-
} else {
744-
DiffResultObject("Tuple20", results)
745-
}
673+
DiffResultObject("Tuple20", results)
746674
}
747675
}
748676

@@ -799,11 +727,7 @@ trait TupleInstances {
799727
"_20" -> d20.apply(left._20, right._20),
800728
"_21" -> d21.apply(left._21, right._21)
801729
).toMap
802-
if (results.values.forall(_.isIdentical)) {
803-
IdenticalValue(left)
804-
} else {
805-
DiffResultObject("Tuple21", results)
806-
}
730+
DiffResultObject("Tuple21", results)
807731
}
808732
}
809733

@@ -887,11 +811,7 @@ trait TupleInstances {
887811
"_21" -> d21.apply(left._21, right._21),
888812
"_22" -> d22.apply(left._22, right._22)
889813
).toMap
890-
if (results.values.forall(_.isIdentical)) {
891-
IdenticalValue(left)
892-
} else {
893-
DiffResultObject("Tuple22", results)
894-
}
814+
DiffResultObject("Tuple22", results)
895815
}
896816
}
897817

core/src/test/scala/com/softwaremill/diffx/test/DiffModifyIntegrationTest.scala

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class DiffModifyIntegrationTest extends AnyFlatSpec with Matchers {
3333
implicit val d: Diff[Person] = Derived[Diff[Person]]
3434
.ignore(_.name)
3535
.ignore(_.age)
36-
compare(p1, p2) shouldBe IdenticalValue(p1)
36+
compare(p1, p2).isIdentical shouldBe true
3737
}
3838

3939
it should "compare lists using explicit object matcher comparator" in {
@@ -44,7 +44,7 @@ class DiffModifyIntegrationTest extends AnyFlatSpec with Matchers {
4444
.withListMatcher(
4545
ObjectMatcher.byValue[Int, Person](ObjectMatcher.by(_.name))
4646
)
47-
compare(o1, o2) shouldBe IdenticalValue(Organization(List(p1, p2)))
47+
compare(o1, o2).isIdentical shouldBe true
4848
}
4949

5050
it should "ignore only on right" in {
@@ -54,12 +54,12 @@ class DiffModifyIntegrationTest extends AnyFlatSpec with Matchers {
5454

5555
implicit val wrapperDiff: Diff[Wrapper] = Derived[Diff[Wrapper]].ignore(_.e.eachRight.name)
5656

57-
compare(e1, e2) shouldBe IdenticalValue(e1)
57+
compare(e1, e2).isIdentical shouldBe true
5858

5959
val e3 = Wrapper(Left(p1))
6060
val e4 = Wrapper(Left(p1.copy(name = p1.name + "_modified")))
6161

62-
compare(e3, e4) should not be an[IdenticalValue[_]]
62+
compare(e3, e4).isIdentical shouldBe false
6363
}
6464

6565
it should "ignore only on left" in {
@@ -69,11 +69,11 @@ class DiffModifyIntegrationTest extends AnyFlatSpec with Matchers {
6969

7070
implicit val wrapperDiff: Diff[Wrapper] = Derived[Diff[Wrapper]].ignore(_.e.eachLeft.name)
7171

72-
compare(e1, e2) should not be an[IdenticalValue[_]]
72+
compare(e1, e2).isIdentical shouldBe false
7373
val e3 = Wrapper(Left(p1))
7474
val e4 = Wrapper(Left(p1.copy(name = p1.name + "_modified")))
7575

76-
compare(e3, e4) shouldBe an[IdenticalValue[_]]
76+
compare(e3, e4).isIdentical shouldBe true
7777
}
7878

7979
it should "match map entries by values" in {
@@ -114,7 +114,14 @@ class DiffModifyIntegrationTest extends AnyFlatSpec with Matchers {
114114
Map(
115115
"workers" -> DiffResultSet(
116116
List(
117-
IdenticalValue(p1),
117+
DiffResultObject(
118+
"Person",
119+
Map(
120+
"name" -> IdenticalValue(p1.name),
121+
"age" -> IdenticalValue(p1.age),
122+
"in" -> IdenticalValue(p1.in)
123+
)
124+
),
118125
DiffResultObject(
119126
"Person",
120127
Map(

core/src/test/scala/com/softwaremill/diffx/test/DiffSemiautoTest.scala

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,19 @@ class DiffSemiautoTest extends AnyFreeSpec with Matchers {
4141
"should work for coproducts" in {
4242
implicit val dACoproduct: Derived[Diff[ACoproduct]] = Diff.derived[ACoproduct]
4343

44-
Diff.compare[ACoproduct](ProductA("1"), ProductA("1")) shouldBe IdenticalValue(
45-
ProductA("1")
46-
)
44+
Diff.compare[ACoproduct](ProductA("1"), ProductA("1")).isIdentical shouldBe true
4745
}
4846

4947
"should allow ignoring on derived diffs" in {
5048
implicit val dACoproduct: Derived[Diff[ProductA]] = Diff.derived[ProductA].ignore(_.id)
5149

52-
Diff.compare[ProductA](ProductA("1"), ProductA("2")) shouldBe IdenticalValue(
53-
ProductA("1")
54-
)
50+
Diff.compare[ProductA](ProductA("1"), ProductA("2")).isIdentical shouldBe true
5551
}
5652

5753
"should allow modifying derived diffs" in {
5854
implicit val dACoproduct: Derived[Diff[ProductA]] = Diff.derived[ProductA].modify(_.id).ignore()
5955

60-
Diff.compare[ProductA](ProductA("1"), ProductA("2")) shouldBe IdenticalValue(
61-
ProductA("1")
62-
)
56+
Diff.compare[ProductA](ProductA("1"), ProductA("2")).isIdentical shouldBe true
6357
}
6458
}
6559

core/src/test/scala/com/softwaremill/diffx/test/DiffTest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ class DiffTest extends AnyFreeSpec with Matchers {
761761
"tuples" - {
762762
"tuple2" - {
763763
"equal tuples should be identical" in {
764-
compare((1, 2), (1, 2)) shouldBe IdenticalValue((1, 2))
764+
compare((1, 2), (1, 2)).isIdentical shouldBe true
765765
}
766766
"different first element should make them different" in {
767767
compare((1, 2), (3, 2)) shouldBe DiffResultObject(
@@ -778,7 +778,7 @@ class DiffTest extends AnyFreeSpec with Matchers {
778778
}
779779
"tuple3" - {
780780
"equal tuples should be identical" in {
781-
compare((1, 2, 3), (1, 2, 3)) shouldBe IdenticalValue((1, 2, 3))
781+
compare((1, 2, 3), (1, 2, 3)).isIdentical shouldBe true
782782
}
783783
"different first element should make them different" in {
784784
compare((1, 2, 3), (4, 2, 3)) shouldBe DiffResultObject(

0 commit comments

Comments
 (0)