-
Notifications
You must be signed in to change notification settings - Fork 4
/
timeago_test.go
79 lines (69 loc) · 1.51 KB
/
timeago_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
package timeago
import (
"time"
)
import "testing"
func check(t *testing.T, d time.Duration, result string) {
start := time.Now()
end := time.Now().Add(d)
got, error := TimeAgoWithTime(start, end)
if error == nil {
if got != result {
t.Errorf("Wrong result: %s", got)
}
}
}
func TestThreeHoursAgo(t *testing.T) {
d, error := time.ParseDuration("-3h")
if error == nil {
check(t, d, "3 hours ago")
}
}
func TestAnHourAgo(t *testing.T) {
d, error := time.ParseDuration("-1.5h")
if error == nil {
check(t, d, "An hour ago")
}
}
func TestThreeMinutesAgo(t *testing.T) {
d, error := time.ParseDuration("-3m")
if error == nil {
check(t, d, "3 minutes ago")
}
}
func TestAMinuteAgo(t *testing.T) {
d, error := time.ParseDuration("-1.2m")
if error == nil {
check(t, d, "A minute ago")
}
}
func TestJustNow(t *testing.T) {
d, error := time.ParseDuration("-1.2s")
if error == nil {
check(t, d, "Just now")
}
}
func TestFromNow(t *testing.T) {
d, error := time.ParseDuration("-1.2m")
if error == nil {
end := time.Now().Add(d)
got, err := TimeAgoFromNowWithTime(end)
if err == nil {
if got != "A minute ago" {
t.Errorf("Wrong result: %s", got)
}
}
}
}
func TestFromNowWithString(t *testing.T) {
d, error := time.ParseDuration("-1.2m")
if error == nil {
end := time.Now().Add(d)
got, err := TimeAgoFromNowWithString(time.RFC3339, end.Format(time.RFC3339))
if err == nil {
if got != "A minute ago" {
t.Errorf("Wrong result: %s", got)
}
}
}
}