aboutsummaryrefslogtreecommitdiffstats
path: root/worker/lib/daterange_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'worker/lib/daterange_test.go')
-rw-r--r--worker/lib/daterange_test.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/worker/lib/daterange_test.go b/worker/lib/daterange_test.go
new file mode 100644
index 00000000..983f99a0
--- /dev/null
+++ b/worker/lib/daterange_test.go
@@ -0,0 +1,55 @@
+package lib_test
+
+import (
+ "testing"
+ "time"
+
+ "git.sr.ht/~rjarry/aerc/worker/lib"
+)
+
+func TestParseDateRange(t *testing.T) {
+ dateFmt := "2006-01-02"
+ parse := 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: parse("2022-11-01"),
+ end: parse("2022-11-02"),
+ },
+ {
+ s: "2022-11-01..",
+ start: parse("2022-11-01"),
+ },
+ {
+ s: "..2022-11-05",
+ end: parse("2022-11-05"),
+ },
+ {
+ s: "2022-11-01..2022-11-05",
+ start: parse("2022-11-01"),
+ end: parse("2022-11-05"),
+ },
+ }
+
+ for _, test := range tests {
+ start, end, err := lib.ParseDateRange(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)
+ }
+ }
+}