forked from SlyMarbo/rss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
time_test.go
53 lines (46 loc) · 1.49 KB
/
time_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
package rss
import (
"testing"
"time"
)
const customLayout = "2006-01-02T15:04Z07:00"
var (
timeVal = time.Date(2015, 7, 1, 9, 27, 0, 0, time.UTC)
originalLayouts = TimeLayouts
)
func TestParseTimeUsingOnlyDefaultLayouts(t *testing.T) {
// Positive cases
for _, layout := range originalLayouts {
s := timeVal.Format(layout)
if tv, err := parseTime(s); err != nil || !tv.Equal(timeVal) {
t.Error("expected no err and times to equal, got err %v and time value %v", err, tv)
}
}
// Negative cases
if _, err := parseTime(""); err == nil {
t.Error("expected err, got none")
}
if _, err := parseTime("abc"); err == nil {
t.Error("expected err, got none")
}
custom := timeVal.Format(customLayout)
if _, err := parseTime(custom); err == nil {
t.Error("expected err, got none")
}
}
func TestParseTimeUsingCustomLayoutsPrepended(t *testing.T) {
TimeLayouts = append([]string{customLayout}, originalLayouts...)
custom := timeVal.Format(customLayout)
if tv, err := parseTime(custom); err != nil || !tv.Equal(timeVal) {
t.Error("expected no err and times to equal, got err %v and time value %v", err, tv)
}
TimeLayouts = originalLayouts
}
func TestParseTimeUsingCustomLayoutsAppended(t *testing.T) {
TimeLayouts = append(originalLayouts, customLayout)
custom := timeVal.Format(customLayout)
if tv, err := parseTime(custom); err != nil || !tv.Equal(timeVal) {
t.Error("expected no err and times to equal, got err %v and time value %v", err, tv)
}
TimeLayouts = originalLayouts
}