forked from go-shadow/moment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
moment_parser_test.go
143 lines (123 loc) · 5.18 KB
/
moment_parser_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
package moment
import (
. "github.com/smartystreets/goconvey/convey"
"testing"
)
func TestMomentParser(t *testing.T) {
parser := new(MomentParser)
Convey("Given moment month formats", t, func() {
Convey("It should generate the correct golang formats for months", func() {
So(parser.Convert("M"), ShouldEqual, "1")
So(parser.Convert("Mo"), ShouldEqual, "1<stdOrdinal>")
So(parser.Convert("MM"), ShouldEqual, "01")
So(parser.Convert("MMM"), ShouldEqual, "Jan")
So(parser.Convert("MMMM"), ShouldEqual, "January")
})
})
Convey("Given moment day of month formats", t, func() {
Convey("It should generate the correct golang formats for days", func() {
So(parser.Convert("D"), ShouldEqual, "2")
So(parser.Convert("Do"), ShouldEqual, "2<stdOrdinal>")
So(parser.Convert("DD"), ShouldEqual, "02")
})
})
Convey("Given moment day of year formats", t, func() {
Convey("It should generate the correct golang formats for days", func() {
So(parser.Convert("DDD"), ShouldEqual, "<stdDayOfYear>")
So(parser.Convert("DDDo"), ShouldEqual, "<stdDayOfYear><stdOrdinal>")
So(parser.Convert("DDDD"), ShouldEqual, "<stdDayOfYearZero>")
})
})
Convey("Given moment day of week formats", t, func() {
Convey("It should generate the correct golang formats for days", func() {
So(parser.Convert("d"), ShouldEqual, "<stdDayOfWeek>")
So(parser.Convert("do"), ShouldEqual, "<stdDayOfWeek><stdOrdinal>")
// So(parser.Convert("dd"), ShouldEqual, "Mo")
So(parser.Convert("ddd"), ShouldEqual, "Mon")
So(parser.Convert("dddd"), ShouldEqual, "Monday")
// Day of week locale
So(parser.Convert("e"), ShouldEqual, "<stdDayOfWeek>")
So(parser.Convert("E"), ShouldEqual, "<stdDayOfWeekISO>")
})
})
Convey("Given moment week of year formats", t, func() {
Convey("It should generate the correct golang formats for week of year", func() {
So(parser.Convert("w"), ShouldEqual, "<stdWeekOfYear>")
So(parser.Convert("wo"), ShouldEqual, "<stdWeekOfYear><stdOrdinal>")
// So(parser.Convert("ww"), ShouldEqual, "@todo")
So(parser.Convert("W"), ShouldEqual, "<stdWeekOfYear>")
So(parser.Convert("Wo"), ShouldEqual, "<stdWeekOfYear><stdOrdinal>")
// So(parser.Convert("WW"), ShouldEqual, "@todo")
})
})
Convey("Given moment year formats", t, func() {
Convey("It should generate the correct golang formats for years", func() {
So(parser.Convert("YY"), ShouldEqual, "06")
So(parser.Convert("YYYY"), ShouldEqual, "2006")
})
})
Convey("Given moment week year formats", t, func() {
Convey("It should generate the correct golang formats for week years", func() {
// So(parser.Convert("gg"), ShouldEqual, "@todo")
// So(parser.Convert("gggg"), ShouldEqual, "@todo")
// ISO
// So(parser.Convert("GG"), ShouldEqual, "@todo")
// So(parser.Convert("GGGG"), ShouldEqual, "@todo")
})
})
Convey("Given moment hour formats", t, func() {
Convey("It should generate the correct golang formats for hours", func() {
So(parser.Convert("H"), ShouldEqual, "<stdHourNoZero>")
So(parser.Convert("HH"), ShouldEqual, "15")
So(parser.Convert("h"), ShouldEqual, "3")
So(parser.Convert("hh"), ShouldEqual, "03")
})
})
Convey("Given moment minute formats", t, func() {
Convey("It should generate the correct golang formats for minutes", func() {
So(parser.Convert("m"), ShouldEqual, "4")
So(parser.Convert("mm"), ShouldEqual, "04")
})
})
Convey("Given moment second formats", t, func() {
Convey("It should generate the correct golang formats for seconds", func() {
So(parser.Convert("s"), ShouldEqual, "5")
So(parser.Convert("ss"), ShouldEqual, "05")
})
})
Convey("Given moment localized formats", t, func() {
Convey("It should generate the correct golang formats", func() {
So(parser.Convert("LT"), ShouldEqual, "3:04 PM")
So(parser.Convert("L"), ShouldEqual, "01/02/2006")
So(parser.Convert("l"), ShouldEqual, "1/2/2006")
So(parser.Convert("LL"), ShouldEqual, "January 2<stdOrdinal> 2006")
So(parser.Convert("ll"), ShouldEqual, "Jan 2 2006")
So(parser.Convert("LLL"), ShouldEqual, "January 2<stdOrdinal> 2006 3:04 PM")
So(parser.Convert("lll"), ShouldEqual, "Jan 2 2006 3:04 PM")
So(parser.Convert("LLLL"), ShouldEqual, "Monday, January 2<stdOrdinal> 2006 3:04 PM")
So(parser.Convert("llll"), ShouldEqual, "Mon, Jan 2 2006 3:04 PM")
})
})
Convey("Given moment timezone formats", t, func() {
Convey("It should generate the correct golang timezone formats", func() {
So(parser.Convert("z"), ShouldEqual, "MST")
So(parser.Convert("zz"), ShouldEqual, "MST")
So(parser.Convert("Z"), ShouldEqual, "Z07:00")
So(parser.Convert("ZZ"), ShouldEqual, "-0700")
})
})
Convey("Given moment misc formats", t, func() {
Convey("It should generate the correct golang formats", func() {
So(parser.Convert("Q"), ShouldEqual, "<stdQuarter>")
So(parser.Convert("A"), ShouldEqual, "PM")
So(parser.Convert("a"), ShouldEqual, "pm")
So(parser.Convert("X"), ShouldEqual, "<stdUnix>")
})
})
Convey("Given a moment format", t, func() {
Convey("It should generate the correct golang time format", func() {
So(parser.Convert("YYYY-MM-DD"), ShouldEqual, "2006-01-02")
So(parser.Convert("YYYY/MM/DD"), ShouldEqual, "2006/01/02")
})
})
}