-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathpomodoro_test.go
94 lines (66 loc) · 2.2 KB
/
pomodoro_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
package main
import (
"os"
"strings"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
var aTime, _ = time.Parse(time.Kitchen, "10:00AM")
var emptyState = State{
endTime: noTime,
now: aTime,
}
func Test_parseCommand_start(t *testing.T) {
newState, output := parseCommand(emptyState, "start")
expected, _ := time.Parse(time.Kitchen, "10:25AM")
assert.Equal(t, expected, newState.endTime)
assert.Equal(t, "Timer started, 25 minutes remaining", output.text)
}
func Test_parseCommand_status(t *testing.T) {
endTime, _ := time.Parse(time.Kitchen, "10:25AM")
now, _ := time.Parse(time.Kitchen, "10:05AM")
state := State{endTime: endTime, now: now}
newState, output := parseCommand(state, "status")
assert.Equal(t, state, newState)
assert.Equal(t, "20 🍅 ", output.text)
}
func Test_parseCommand_status_empty(t *testing.T) {
newState, output := parseCommand(emptyState, "status")
assert.Equal(t, emptyState, newState)
assert.Equal(t, "", output.text)
}
func Test_parseCommand_done(t *testing.T) {
endTime, _ := time.Parse(time.Kitchen, "10:25AM")
now, _ := time.Parse(time.Kitchen, "10:25AM")
state := State{endTime: endTime, now: now}
newState, output := parseCommand(state, "status")
assert.Equal(t, state, newState)
assert.Equal(t, "0 🍅 ", output.text)
}
func Test_parseCommand_past(t *testing.T) {
endTime, _ := time.Parse(time.Kitchen, "10:25AM")
now, _ := time.Parse(time.Kitchen, "10:35AM")
state := State{endTime: endTime, now: now}
newState, output := parseCommand(state, "status")
assert.Equal(t, state, newState)
assert.Equal(t, "❗️ 🍅 ", output.text)
}
func Test_parseCommand_bad(t *testing.T) {
newState, output := parseCommand(emptyState, "foobar")
assert.Equal(t, emptyState, newState)
assert.Equal(t, "", output.text)
assert.Equal(t, 1, output.returnCode)
}
func Test_parseCommand_clear(t *testing.T) {
newState, output := parseCommand(emptyState, "clear")
assert.Equal(t, noTime, newState.endTime)
assert.Equal(t, "Pomodoro cleared!", output.text)
}
func Test_readExistingTime(t *testing.T) {
_ = os.Setenv("HOME", os.TempDir())
readExistingTime()
}
func Test_filePath(t *testing.T) {
assert.Equal(t, true, strings.HasSuffix(filePath(), "/.pomodoro"))
}