-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathDiffableSpec.scala
110 lines (96 loc) · 3.23 KB
/
DiffableSpec.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import reactivemongo.api.bson.{ BSONArray, BSONDocument, BSONString }
import reactivemongo.api.bson.specs2._
import org.specs2.matcher.describe.{ PrimitiveDifference, PrimitiveIdentical }
final class DiffableSpec extends org.specs2.mutable.Specification {
"Diffable".title
"Array comparision result" should {
"indicate everything is null" in {
diffableArray.diff(null, null) must_=== PrimitiveIdentical(null)
}
"indicate primitive difference if actual is null" in {
diffableArray.diff(null, BSONArray.empty) must_=== PrimitiveDifference(
actual = null,
expected = BSONArray.empty
)
}
"indicate primitive difference if expected is null (and actual not)" in {
diffableArray.diff(BSONArray.empty, null) must_=== PrimitiveDifference(
actual = BSONArray.empty,
expected = null
)
}
"indicate an unordered difference" in {
diffableArray
.diff(
actual = BSONArray("added", "same"),
expected = BSONArray("same", "removed")
)
.render must_=== """BSONArray('same',
added: 'added',
removed: 'removed')"""
}
}
"Document comparision result" should {
"indicate everything is null" in {
diffableDocument.diff(null, null) must_=== PrimitiveIdentical(null)
}
"indicate primitive difference if actual is null" in {
diffableDocument.diff(
null,
BSONDocument.empty
) must_=== PrimitiveDifference(
actual = null,
expected = BSONDocument.empty
)
}
"indicate primitive difference if expected is null (and actual not)" in {
diffableDocument.diff(
BSONDocument.empty,
null
) must_=== PrimitiveDifference(
actual = BSONDocument.empty,
expected = null
)
}
"indicate an unordered difference" in {
diffableDocument
.diff(
actual = BSONDocument(
"added" -> 1,
"changedPrimitive" -> "value",
"changedArr" -> BSONArray("_1"),
"changedDoc" -> BSONDocument("foo" -> 1)
),
expected = BSONDocument(
"changedArr" -> BSONArray.empty,
"changedPrimitive" -> 1.23D,
"removed" -> 2,
"changedDoc" -> BSONDocument("bar" -> 2)
)
)
.render must_=== """BSONDocument('changedPrimitive': BSONString(value) != BSONDouble(1.23),
'changedArr': BSONArray(added: '_1'),
'changedDoc': BSONDocument(added: 'foo': 1,
removed: 'bar': 2),
added: 'added': 1,
removed: 'removed': 2)"""
}
}
"Value comparision result" should {
"indicate everything is null" in {
diffableValue.diff(null, null) must_=== PrimitiveIdentical(null)
}
"indicate primitive difference if actual is null" in {
diffableValue.diff(null, BSONDocument.empty) must_=== PrimitiveDifference(
actual = null,
expected = BSONDocument.empty
)
}
"indicate primitive difference if expected is null (and actual not)" in {
diffableValue.diff(BSONString("str"), null) must_=== PrimitiveDifference(
actual = BSONString("str"),
expected = null
)
}
}
}