forked from f-person/timeow-mac
-
Notifications
You must be signed in to change notification settings - Fork 2
/
period_test.go
39 lines (36 loc) · 887 Bytes
/
period_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
package main
import (
"fmt"
"testing"
"time"
)
func TestString(t *testing.T) {
now := time.Now()
loc := now.Location()
tests := []struct {
start time.Time
end time.Time
want string
}{
{
time.Date(2020, time.December, now.Day(), 15, 2, 0, 0, loc),
time.Date(2020, time.December, now.Day(), 15, 8, 0, 0, loc),
"15:02 - 15:08 (6 minutes)",
},
{
time.Date(2020, time.December, now.Day()-1, 23, 2, 0, 0, loc),
time.Date(2020, time.December, now.Day(), 3, 8, 0, 0, loc),
fmt.Sprintf("%v Dec 23:02 - %v Dec 03:08 (4 hours 6 minutes)", now.Day()-1, now.Day()),
},
}
for _, tt := range tests {
testname := fmt.Sprintf("%v, %v", tt.start, tt.end)
t.Run(testname, func(t *testing.T) {
entry := period{tt.start, tt.end, false}
answer := entry.string()
if answer != tt.want {
t.Fatalf("got %v, want %v", answer, tt.want)
}
})
}
}