-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedtf_test.go
183 lines (146 loc) · 3.02 KB
/
edtf_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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package edtf
import (
"encoding/json"
_ "fmt"
"testing"
)
func TestUnmarshalJSON(t *testing.T) {
edtf_json := `{
"start": {
"edtf": "-1990",
"lower": {
"datetime": "-1990-01-01T00:00:00Z",
"timestamp": -124965504000,
"ymd": {
"year": -1990,
"month": 1,
"day": 1
},
"precision": 64
},
"upper": {
"datetime": "-1990-12-31T23:59:59Z",
"timestamp": -124933968001,
"ymd": {
"year": -1990,
"month": 12,
"day": 31
},
"precision": 64
}
},
"end": {
"edtf": "0400",
"lower": {
"datetime": "0400-01-01T00:00:00Z",
"timestamp": -49544438400,
"ymd": {
"year": 400,
"month": 1,
"day": 1
},
"precision": 64
},
"upper": {
"datetime": "0400-12-31T23:59:59Z",
"timestamp": -49512816001,
"ymd": {
"year": 400,
"month": 12,
"day": 31
},
"precision": 64
}
},
"edtf": "-1990/0400",
"level": 0,
"feature": "Time Interval"
}`
var d *EDTFDate
err := json.Unmarshal([]byte(edtf_json), &d)
if err != nil {
t.Logf("Failed to unmarshal JSON, %v", err)
t.Fail()
return
}
lower, err := d.Lower()
if err != nil {
t.Logf("Expected lower time.Time but got none, %v", err)
t.Fail()
return
}
upper, err := d.Upper()
if err != nil {
t.Logf("Expected upper time.Time but got none, %v", err)
t.Fail()
return
}
if lower.Unix() != -124965504000 {
t.Logf("Unexpected lower time.Time Unix timestamp")
t.Fail()
return
}
if upper.Unix() != -49512816001 {
t.Logf("Unexpected lower time.Time Unix timestamp")
t.Fail()
return
}
}
func TestIsOpen(t *testing.T) {
is_open := []string{
OPEN,
OPEN_2012,
}
not_open := []string{
"",
"2021-09-28",
}
for _, s := range is_open {
if !IsOpen(s) {
t.Fatalf("String '%s' is considered open but reported as not open", s)
}
}
for _, s := range not_open {
if IsOpen(s) {
t.Fatalf("String '%s' is not open but reported as being open", s)
}
}
}
func TestIsUnspecified(t *testing.T) {
is_unspecified := []string{
UNSPECIFIED,
UNSPECIFIED_2012,
}
not_unspecified := []string{
"2021-09-28",
}
for _, s := range is_unspecified {
if !IsUnspecified(s) {
t.Fatalf("String '%s' is considered unspecified but reported as not unspecified", s)
}
}
for _, s := range not_unspecified {
if IsUnspecified(s) {
t.Fatalf("String '%s' is not unspecified but reported as being unspecified", s)
}
}
}
func TestIsUnknown(t *testing.T) {
is_unknown := []string{
UNKNOWN,
UNKNOWN_2012,
}
not_unknown := []string{
"2021-09-28",
}
for _, s := range is_unknown {
if !IsUnknown(s) {
t.Fatalf("String '%s' is considered unknown but reported as not unknown", s)
}
}
for _, s := range not_unknown {
if IsUnknown(s) {
t.Fatalf("String '%s' is not unknown but reported as being unknown", s)
}
}
}