-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathassert_test.go
49 lines (39 loc) · 1.43 KB
/
assert_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
package gedcom_test
import (
"testing"
"github.com/elliotchance/gedcom/v39"
"github.com/stretchr/testify/assert"
)
func assertAge(t *testing.T, age gedcom.Age, years float64, isEstimate bool, constraint gedcom.AgeConstraint) {
assert.True(t, age.IsKnown, "is known")
assert.Equal(t, isEstimate, age.IsEstimate, "is estimate")
assert.Equal(t, constraint.String(), age.Constraint.String(), "constraint")
expected := float64(age.Age) / 3.15576e16
assert.InDelta(t, years, expected, 0.1)
}
func assertNodeEqual(t *testing.T, expected, actual gedcom.Node, msgAndArgs ...interface{}) {
if gedcom.IsNil(expected) || gedcom.IsNil(actual) {
assert.True(t, gedcom.IsNil(expected))
assert.True(t, gedcom.IsNil(actual))
} else {
assert.True(t, expected.Equals(actual), msgAndArgs...)
}
}
func assertDocumentEqual(t *testing.T, expected, actual *gedcom.Document, msgAndArgs ...interface{}) {
assert.Equal(t, expected.String(), actual.String(), msgAndArgs...)
if !assert.Equal(t, len(expected.Nodes()), len(actual.Nodes()), msgAndArgs...) {
return
}
for i, n := range expected.Nodes() {
assertNodeEqual(t, n, actual.Nodes()[i])
}
assert.Equal(t, expected.MaxLivingAge, actual.MaxLivingAge, msgAndArgs...)
assert.Equal(t, expected.HasBOM, actual.HasBOM, msgAndArgs...)
}
func assertError(t *testing.T, expected, actual error) {
if expected == nil {
assert.NoError(t, actual)
} else {
assert.EqualError(t, expected, actual.Error())
}
}