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
|
package parse_test
import (
"reflect"
"testing"
"time"
"git.sr.ht/~rjarry/aerc/lib/parse"
)
func TestParseDateRange(t *testing.T) {
dateFmt := "2006-01-02"
date := func(s string) time.Time { d, _ := time.Parse(dateFmt, s); return d }
tests := []struct {
s string
start time.Time
end time.Time
}{
{
s: "2022-11-01",
start: date("2022-11-01"),
end: date("2022-11-02"),
},
{
s: "2022-11-01..",
start: date("2022-11-01"),
},
{
s: "..2022-11-05",
end: date("2022-11-05"),
},
{
s: "2022-11-01..2022-11-05",
start: date("2022-11-01"),
end: date("2022-11-05"),
},
}
for _, test := range tests {
start, end, err := parse.DateRange(test.s)
if err != nil {
t.Errorf("ParseDateRange return error for %s: %v",
test.s, err)
}
if !start.Equal(test.start) {
t.Errorf("wrong start date; expected %v, got %v",
test.start, start)
}
if !end.Equal(test.end) {
t.Errorf("wrong end date; expected %v, got %v",
test.end, end)
}
}
}
func TestParseRelativeDate(t *testing.T) {
tests := []struct {
s string
want parse.RelDate
}{
{
s: "5 weeks 1 day",
want: parse.RelDate{Year: 0, Month: 0, Day: 5*7 + 1},
},
{
s: "5_weeks 1_day",
want: parse.RelDate{Year: 0, Month: 0, Day: 5*7 + 1},
},
{
s: "5weeks1day",
want: parse.RelDate{Year: 0, Month: 0, Day: 5*7 + 1},
},
{
s: "5w1d",
want: parse.RelDate{Year: 0, Month: 0, Day: 5*7 + 1},
},
{
s: "5y4m3w1d",
want: parse.RelDate{Year: 5, Month: 4, Day: 3*7 + 1},
},
}
for _, test := range tests {
da, err := parse.RelativeDate(test.s)
if err != nil {
t.Errorf("ParseRelativeDate return error for %s: %v",
test.s, err)
}
if !reflect.DeepEqual(da, test.want) {
t.Errorf("results don't match. expected %v, got %v",
test.want, da)
}
}
}
|