-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathformat_test.go
111 lines (105 loc) · 3.46 KB
/
format_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
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package date
import (
"testing"
)
func TestDate_String(t *testing.T) {
cases := []struct {
value string
}{
{value: "-0001-01-01"},
{value: "0000-01-01"},
{value: "0001-01-01"},
{value: "1000-01-01"},
{value: "1970-01-01"},
{value: "2000-11-22"},
{value: "+10000-01-01"},
}
for _, c := range cases {
d := MustParseISO(c.value)
value := d.String()
if value != c.value {
t.Errorf("String() == %v, want %v", value, c.value)
}
}
}
func TestDate_FormatOrdinal(t *testing.T) {
cases := []struct {
value, expected string
}{
{value: "-5000-001", expected: "-5000-001"},
{value: "-05000-001", expected: "-5000-001"},
{value: "-005000-001", expected: "-5000-001"},
{value: "0001-001", expected: "0001-001"},
{value: "00000-001", expected: "0000-001"},
{value: "1000-001", expected: "1000-001"},
{value: "01000-001", expected: "1000-001"},
{value: "1970-001", expected: "1970-001"},
{value: "001999-365", expected: "1999-365"},
{value: "999999-365", expected: "999999-365"},
}
for i, c := range cases {
d := MustParseISO(c.value)
value := d.FormatOrdinal()
if value != c.expected {
t.Errorf("%d: FormatOrdinal(%v) == %v, want %v", i, c, value, c.value)
}
}
}
func TestDate_FormatISO(t *testing.T) {
cases := []struct {
value string
n int
}{
{value: "-5000-02-03", n: 4},
{value: "-05000-02-03", n: 5},
{value: "-005000-02-03", n: 6},
{value: "+0000-01-01", n: 4},
{value: "+00000-01-01", n: 5},
{value: "+1000-01-01", n: 4},
{value: "+01000-01-01", n: 5},
{value: "+1970-01-01", n: 4},
{value: "+001999-12-31", n: 6},
{value: "+999999-12-31", n: 6},
}
for _, c := range cases {
d := MustParseISO(c.value)
value := d.FormatISO(c.n)
if value != c.value {
t.Errorf("FormatISO(%v) == %v, want %v", c, value, c.value)
}
}
}
func TestDate_Format(t *testing.T) {
cases := []struct {
value string
format string
expected string
}{
{value: "1970-01-01", format: "2 Jan 2006", expected: "1 Jan 1970"},
{value: "1970-01-01", format: "Jan 02 2006", expected: "Jan 01 1970"},
{value: "1970-01-01", format: "Jan 2nd 2006", expected: "Jan 1st 1970"},
{value: "2016-01-01", format: "2nd Jan 2006", expected: "1st Jan 2016"},
{value: "2016-02-02", format: "Jan 2nd 2006", expected: "Feb 2nd 2016"},
{value: "2016-03-03", format: "Jan 2nd 2006", expected: "Mar 3rd 2016"},
{value: "2016-04-04", format: "2nd Jan 2006", expected: "4th Apr 2016"},
{value: "2016-05-20", format: "Jan 2nd 2006", expected: "May 20th 2016"},
{value: "2016-06-21", format: "Jan 2nd 2006", expected: "Jun 21st 2016"},
{value: "2016-07-22", format: "Jan 2nd 2006", expected: "Jul 22nd 2016"},
{value: "2016-08-23", format: "Jan 2nd 2006", expected: "Aug 23rd 2016"},
{value: "2016-09-30", format: "Jan 2nd 2006", expected: "Sep 30th 2016"},
{value: "2016-10-31", format: "Jan 2nd 2006", expected: "Oct 31st 2016"},
{value: "2016-01-07", format: "Monday January 2nd 2006", expected: "Thursday January 7th 2016"},
{value: "2016-01-07", format: "Monday 2nd Monday 2nd", expected: "Thursday 7th Thursday 7th"},
{value: "2016-11-01", format: "2nd 2nd 2nd", expected: "1st 1st 1st"},
}
for _, c := range cases {
d := MustParseISO(c.value)
actual := d.Format(c.format)
if actual != c.expected {
t.Errorf("Format(%v) == %v, want %v", c, actual, c.expected)
}
}
}