-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhhmmss_test.go
59 lines (54 loc) · 1.15 KB
/
hhmmss_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
package hhmmss
import (
"testing"
"time"
)
func TestInputs(t *testing.T) {
type Test struct {
arg string
expected time.Duration
}
tt := []Test{
Test{ // should be parsed in seconds if no ':' set
arg: "1200",
expected: time.Second * time.Duration(1200),
},
Test{
arg: "01:00:00", // HH:MM:SS
expected: time.Hour * 1,
},
Test{ // anything after hours defined should be ignored
arg: "10:01:00:00", // HH:MM:SS
expected: time.Hour * 1,
},
Test{
arg: "1:00:00",
expected: time.Hour * 1,
},
Test{
arg: "03:30:26",
expected: (time.Hour * 3) + (time.Minute * 30) + (time.Second * 26),
},
Test{
arg: "30:26", // MM:SS
expected: (time.Minute * 30) + (time.Second * 26),
},
Test{
arg: "3:26", // MM:SS
expected: (time.Minute * 3) + (time.Second * 26),
},
Test{
arg: "3:64", // MM:SS (time should roll over)
expected: (time.Minute * 4) + (time.Second * 4),
},
}
for i, test := range tt {
dur, err := Parse(test.arg)
if err != nil {
t.Fatal(err)
}
if dur != test.expected {
t.Errorf("#%v did not receive expected duration", i)
}
}
}