-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathequal_test.go
104 lines (89 loc) · 2.76 KB
/
equal_test.go
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
package gedcom_test
import (
"testing"
"github.com/elliotchance/gedcom/v39"
"github.com/elliotchance/tf"
)
func TestDeepEqual(t *testing.T) {
DeepEqual := tf.Function(t, gedcom.DeepEqual)
// These two are the same.
n1 := gedcom.NewResidenceNode("",
gedcom.NewDateNode("3 SEP 1987"),
)
n2 := gedcom.NewResidenceNode("",
gedcom.NewDateNode("3 SEP 1987"),
)
// Different variations.
n3 := gedcom.NewResidenceNode("",
gedcom.NewDateNode("5 SEP 1987"),
)
n4 := gedcom.NewResidenceNode("",
gedcom.NewDateNode("5 SEP 1987"),
gedcom.NewDateNode("3 SEP 1987"),
)
n5 := gedcom.NewResidenceNode("",
gedcom.NewDateNode("3 SEP 1987"),
gedcom.NewDateNode("5 SEP 1987"),
)
// More complex examples.
n6 := gedcom.NewDocument().AddIndividual("P1",
gedcom.NewNameNode("Elliot /Chance/"),
gedcom.NewResidenceNode("",
gedcom.NewDateNode("3 SEP 1987"),
gedcom.NewPlaceNode("England"),
),
)
n7 := gedcom.NewDocument().AddIndividual("P1",
gedcom.NewNameNode("Elliot /Chance/"),
gedcom.NewResidenceNode("",
gedcom.NewDateNode("3 SEP 1987"),
gedcom.NewPlaceNode("England"),
),
)
n8 := gedcom.NewDocument().AddIndividual("P1",
gedcom.NewNameNode("Elliot /Chance/"),
gedcom.NewResidenceNode("",
gedcom.NewDateNode("3 SEP 1987"),
gedcom.NewPlaceNode("London, England"),
),
)
// Nils.
DeepEqual((*gedcom.SimpleNode)(nil), (*gedcom.SimpleNode)(nil)).Returns(false)
DeepEqual((*gedcom.SimpleNode)(nil), n1).Returns(false)
DeepEqual(n1, (*gedcom.SimpleNode)(nil)).Returns(false)
// Equal.
DeepEqual(n1, n1).Returns(true) // #4
DeepEqual(n1, n2).Returns(true)
DeepEqual(n2, n1).Returns(true)
DeepEqual(n1, n3).Returns(false)
DeepEqual(n1, n3).Returns(false)
// Different amount of children.
DeepEqual(n3, n4).Returns(false) // #9
// Deep equal.
DeepEqual(n4, n5).Returns(true) // #10
DeepEqual(n5, n4).Returns(true)
DeepEqual(n6, n7).Returns(true)
DeepEqual(n7, n6).Returns(true)
DeepEqual(n7, n8).Returns(false)
}
func TestDeepEqualNodes(t *testing.T) {
DeepEqualNodes := tf.Function(t, gedcom.DeepEqualNodes)
// These two are the same.
n1 := gedcom.NewResidenceNode("",
gedcom.NewDateNode("3 SEP 1987"),
)
n2 := gedcom.NewResidenceNode("",
gedcom.NewDateNode("3 SEP 1987"),
)
n3 := gedcom.NewResidenceNode("",
gedcom.NewDateNode("5 SEP 1987"),
)
// There aren't too many tests here because the fiddly stuff is handled in
// the tests for DeepEqual.
DeepEqualNodes(nil, nil).Returns(true)
DeepEqualNodes(gedcom.Nodes{n1}, gedcom.Nodes{n1}).Returns(true)
DeepEqualNodes(gedcom.Nodes{n1}, gedcom.Nodes{n2}).Returns(true)
DeepEqualNodes(gedcom.Nodes{n1, n2}, gedcom.Nodes{n1, n2}).Returns(true)
DeepEqualNodes(gedcom.Nodes{n1, n2}, gedcom.Nodes{n1}).Returns(false)
DeepEqualNodes(gedcom.Nodes{n1}, gedcom.Nodes{n3}).Returns(false)
}