-
Notifications
You must be signed in to change notification settings - Fork 13
/
cmd_dates_test.go
58 lines (51 loc) · 967 Bytes
/
cmd_dates_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
//
// Copyright (c) 2017 Dean Jackson <[email protected]>
//
// MIT Licence. See http://opensource.org/licenses/MIT
//
// Created on 2017-11-25
//
package main
import "testing"
var validFormats = []string{
"2017-11-25", // date strings
"20171125",
"7", // no units
"-7",
"1d", // days
"+1d",
"-1d",
"2w", // weeks
"+2w",
"-2w",
}
var invalidFormats = []string{
"1m",
"2q",
"l1d",
"*2d",
}
func TestParseDate(t *testing.T) {
tm, ok := parseDate("0")
if !tm.Equal(today) || !ok {
t.Errorf("zero format failed. tm=%v", tm)
}
for _, s := range validFormats {
tm, ok := parseDate(s)
if !ok {
t.Errorf("error parsing valid format %q", s)
}
if tm.IsZero() {
t.Errorf("zero time for valid format %q", s)
}
}
for _, s := range invalidFormats {
tm, ok := parseDate(s)
if ok {
t.Errorf("no error parsing invalid format %q", s)
}
if !tm.IsZero() {
t.Errorf("non-zero time for invalid format %q: %v", s, tm)
}
}
}