-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_test.go
110 lines (93 loc) · 2.33 KB
/
print_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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
package main
import (
"fmt"
"testing"
"time"
)
func TestGetNotesHeader(t *testing.T) {
t.Parallel()
tempDir := t.TempDir()
err := createTestNoteFiles(tempDir, nil)
if err != nil {
t.Fatal(err.Error())
}
header, err := getNotesHeader(tempDir)
if err != nil {
t.Fatal(err.Error())
}
today := time.Now()
weekday := string([]byte(today.Weekday().String())[:3])
kitchen := today.Format("03:04 PM")
zone, _ := today.Zone()
taskList, err := getLastTaskList(tempDir)
if err != nil {
t.Fatal(err.Error())
}
// this is pretty dumb because it's just
// re-implementing the code its testing, but
// oh well fuck it coverage or death
testHeader := fmt.Sprintf(`# %s %02d, %04d
Today is a beautiful day.%s
## %04d-%02d-%02d %s %s %s (admin)
`,
today.Month(),
today.Day(),
today.Year(),
taskList,
today.Year(),
today.Month(),
today.Day(),
weekday,
kitchen,
zone)
if string(header) != testHeader {
t.Error("summary should match expected summary")
}
}
func TestGetNotesHeaderError(t *testing.T) {
t.Parallel()
if _, err := getNotesHeader("does/not/exist"); err == nil {
t.Error("calculate should have errored")
}
}
func TestGetSummary(t *testing.T) {
t.Parallel()
testSummary := `
This week you have worked: 3h 20m
Today you have worked: 0h 24m
➔ cat2: 0h 20m (83.3%, 30.0%, 31.8%)
➔ cat9: 0h 0m (0.0%, 12.0%, 21.8%)
➔ cat0: 0h 0m (0.0%, 6.0%, 10.9%)
➔ cat3: 0h 0m (0.0%, 24.0%, 10.9%)
➔ cat1: 0h 4m (16.7%, 8.0%, 10.0%)
➔ cat4: 0h 0m (0.0%, 16.0%, 7.3%)
➔ cat8: 0h 0m (0.0%, 4.0%, 7.3%)
You are currently working on: something fun
`
totals := newTestTotals()
summary := getSummary(&totals)
if string(summary) != testSummary {
t.Error("summary should match expected summary")
}
}
func TestGetSummaryNoCurrent(t *testing.T) {
t.Parallel()
testSummary := `
This week you have worked: 3h 20m
Today you have worked: 0h 24m
➔ cat2: 0h 20m (83.3%, 30.0%, 31.8%)
➔ cat9: 0h 0m (0.0%, 12.0%, 21.8%)
➔ cat0: 0h 0m (0.0%, 6.0%, 10.9%)
➔ cat3: 0h 0m (0.0%, 24.0%, 10.9%)
➔ cat1: 0h 4m (16.7%, 8.0%, 10.0%)
➔ cat4: 0h 0m (0.0%, 16.0%, 7.3%)
➔ cat8: 0h 0m (0.0%, 4.0%, 7.3%)
You are not currently tracking any work.
`
totals := newTestTotals()
totals.current = ""
summary := getSummary(&totals)
if string(summary) != testSummary {
t.Error("summary should match expected summary")
}
}